Mercurial > ecos-v2_0-branch
comparison packages/io/serial/current/include/serial.h @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | 6512add4f5d6 |
| children | 518f42066aba |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 50 | 50 |
| 51 #include <cyg/infra/cyg_type.h> | 51 #include <cyg/infra/cyg_type.h> |
| 52 #include <cyg/io/io.h> | 52 #include <cyg/io/io.h> |
| 53 #include <cyg/io/serialio.h> | 53 #include <cyg/io/serialio.h> |
| 54 #include <cyg/hal/drv_api.h> | 54 #include <cyg/hal/drv_api.h> |
| 55 | |
| 56 #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT | |
| 57 #include <cyg/fileio/fileio.h> | |
| 58 #endif | |
| 55 | 59 |
| 56 typedef struct serial_channel serial_channel; | 60 typedef struct serial_channel serial_channel; |
| 57 typedef struct serial_funs serial_funs; | 61 typedef struct serial_funs serial_funs; |
| 58 | 62 |
| 59 // Pointers into upper-level driver which interrupt handlers need | 63 // Pointers into upper-level driver which interrupt handlers need |
| 62 void (*serial_init)(serial_channel *chan); | 66 void (*serial_init)(serial_channel *chan); |
| 63 // Cause an additional character to be output if one is available | 67 // Cause an additional character to be output if one is available |
| 64 void (*xmt_char)(serial_channel *chan); | 68 void (*xmt_char)(serial_channel *chan); |
| 65 // Consume an input character | 69 // Consume an input character |
| 66 void (*rcv_char)(serial_channel *chan, unsigned char c); | 70 void (*rcv_char)(serial_channel *chan, unsigned char c); |
| 67 | 71 #if CYGINT_IO_SERIAL_BLOCK_TRANSFER |
| 68 #ifdef CYGINT_IO_SERIAL_BLOCK_TRANSFER | |
| 69 // Request space for input characters | 72 // Request space for input characters |
| 70 bool (*data_rcv_req)(serial_channel *chan, int avail, | 73 bool (*data_rcv_req)(serial_channel *chan, int avail, |
| 71 int* space_avail, unsigned char** space); | 74 int* space_avail, unsigned char** space); |
| 72 // Receive operation completed | 75 // Receive operation completed |
| 73 void (*data_rcv_done)(serial_channel *chan); | 76 void (*data_rcv_done)(serial_channel *chan); |
| 74 // Request characters for transmission | 77 // Request characters for transmission |
| 75 bool (*data_xmt_req)(serial_channel *chan, int space, | 78 bool (*data_xmt_req)(serial_channel *chan, int space, |
| 76 int* chars_avail, unsigned char** chars); | 79 int* chars_avail, unsigned char** chars); |
| 77 // Transmit operation completed | 80 // Transmit operation completed |
| 78 void (*data_xmt_done)(serial_channel *chan); | 81 void (*data_xmt_done)(serial_channel *chan); |
| 79 #endif // CYGINT_IO_SERIAL_BLOCK_TRANSFER | 82 #endif |
| 83 #if defined(CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS) | |
| 84 void (*indicate_status)(serial_channel *chan, cyg_serial_line_status_t *s ); | |
| 85 #endif | |
| 80 } serial_callbacks_t; | 86 } serial_callbacks_t; |
| 81 | 87 |
| 82 #ifdef CYGINT_IO_SERIAL_BLOCK_TRANSFER | 88 #if CYGINT_IO_SERIAL_BLOCK_TRANSFER |
| 83 #define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char, _data_rcv_req, _data_rcv_done, _data_xmt_req, _data_xmt_done) \ | 89 # ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS |
| 90 # define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char, _data_rcv_req, _data_rcv_done, _data_xmt_req, _data_xmt_done, _indicate_status) \ | |
| 84 serial_callbacks_t _l = { \ | 91 serial_callbacks_t _l = { \ |
| 85 _init, \ | 92 _init, \ |
| 86 _xmt_char, \ | 93 _xmt_char, \ |
| 87 _rcv_char, \ | 94 _rcv_char, \ |
| 88 _data_rcv_req, \ | 95 _data_rcv_req, \ |
| 89 _data_rcv_done, \ | 96 _data_rcv_done, \ |
| 90 _data_xmt_req, \ | 97 _data_xmt_req, \ |
| 91 _data_xmt_done \ | 98 _data_xmt_done \ |
| 92 }; | 99 _indicate_status \ |
| 93 #else | 100 }; |
| 94 #define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char) \ | 101 # else |
| 102 # define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char, _data_rcv_req, _data_rcv_done, _data_xmt_req, _data_xmt_done) \ | |
| 103 serial_callbacks_t _l = { \ | |
| 104 _init, \ | |
| 105 _xmt_char, \ | |
| 106 _rcv_char, \ | |
| 107 _data_rcv_req, \ | |
| 108 _data_rcv_done, \ | |
| 109 _data_xmt_req, \ | |
| 110 _data_xmt_done \ | |
| 111 }; | |
| 112 # endif | |
| 113 #else | |
| 114 # ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS | |
| 115 # define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char,_indicate_status) \ | |
| 116 serial_callbacks_t _l = { \ | |
| 117 _init, \ | |
| 118 _xmt_char, \ | |
| 119 _rcv_char, \ | |
| 120 _indicate_status \ | |
| 121 }; | |
| 122 # else | |
| 123 # define SERIAL_CALLBACKS(_l,_init,_xmt_char,_rcv_char) \ | |
| 95 serial_callbacks_t _l = { \ | 124 serial_callbacks_t _l = { \ |
| 96 _init, \ | 125 _init, \ |
| 97 _xmt_char, \ | 126 _xmt_char, \ |
| 98 _rcv_char \ | 127 _rcv_char \ |
| 99 }; | 128 }; |
| 129 # endif | |
| 100 #endif | 130 #endif |
| 101 | 131 |
| 102 extern serial_callbacks_t cyg_io_serial_callbacks; | 132 extern serial_callbacks_t cyg_io_serial_callbacks; |
| 103 | 133 |
| 104 typedef struct { | 134 typedef struct { |
| 105 unsigned char *data; | 135 unsigned char *data; |
| 106 volatile int put; | 136 volatile int put; |
| 107 volatile int get; | 137 volatile int get; |
| 108 int len; | 138 int len; |
| 109 int low_water; // Min space in buffer before restart | 139 int nb; // count of bytes currently in buffer |
| 140 int low_water; // For tx: min space in buffer before restart | |
| 141 // For rx: max buffer used before flow unthrottled | |
| 142 #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL | |
| 143 int high_water; // For tx: unused | |
| 144 // For rx: min buffer used before throttle | |
| 145 #endif | |
| 110 cyg_drv_cond_t wait; | 146 cyg_drv_cond_t wait; |
| 111 cyg_drv_mutex_t lock; | 147 cyg_drv_mutex_t lock; |
| 112 bool waiting; | 148 bool waiting; |
| 113 #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING | 149 #ifdef CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING |
| 114 bool blocking; | 150 bool blocking; |
| 115 #endif | 151 #endif |
| 116 volatile bool abort; // Set by an outsider to kill processing | 152 volatile bool abort; // Set by an outsider to kill processing |
| 117 volatile cyg_int32 pending; // This many bytes waiting to be sent | 153 volatile cyg_int32 pending; // This many bytes waiting to be sent |
| 154 #ifdef CYGPKG_IO_SERIAL_SELECT_SUPPORT | |
| 155 struct CYG_SELINFO_TAG selinfo; // select info | |
| 156 #endif | |
| 118 } cbuf_t; | 157 } cbuf_t; |
| 119 | 158 |
| 120 #define CBUF_INIT(_data, _len) \ | 159 #define CBUF_INIT(_data, _len) \ |
| 121 {_data, 0, 0, _len} | 160 {_data, 0, 0, _len} |
| 161 | |
| 162 #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL | |
| 163 typedef struct { | |
| 164 cyg_uint32 flags; | |
| 165 #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE | |
| 166 cyg_uint8 xchar; | |
| 167 #endif | |
| 168 } flow_desc_t; | |
| 169 #endif | |
| 122 | 170 |
| 123 // Private data which describes this channel | 171 // Private data which describes this channel |
| 124 struct serial_channel { | 172 struct serial_channel { |
| 125 serial_funs *funs; | 173 serial_funs *funs; |
| 126 serial_callbacks_t *callbacks; | 174 serial_callbacks_t *callbacks; |
| 127 void *dev_priv; // Whatever is needed by actual device routines | 175 void *dev_priv; // Whatever is needed by actual device routines |
| 128 cyg_serial_info_t config; // Current configuration | 176 cyg_serial_info_t config; // Current configuration |
| 129 bool init; | 177 bool init; |
| 130 cbuf_t out_cbuf; | 178 cbuf_t out_cbuf; |
| 131 cbuf_t in_cbuf; | 179 cbuf_t in_cbuf; |
| 132 }; | 180 #ifdef CYGPKG_IO_SERIAL_FLOW_CONTROL |
| 181 flow_desc_t flow_desc; | |
| 182 #endif | |
| 183 #ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS | |
| 184 cyg_serial_line_status_callback_fn_t status_callback; | |
| 185 CYG_ADDRWORD status_callback_priv; | |
| 186 #endif | |
| 187 }; | |
| 188 | |
| 189 // Flow descriptor flag values | |
| 190 #define CYG_SERIAL_FLOW_OUT_THROTTLED (1<<0) | |
| 191 #define CYG_SERIAL_FLOW_IN_THROTTLED (1<<1) | |
| 133 | 192 |
| 134 // Initialization macro for serial channel | 193 // Initialization macro for serial channel |
| 135 #define SERIAL_CHANNEL(_l, \ | 194 #define SERIAL_CHANNEL(_l, \ |
| 136 _funs, \ | 195 _funs, \ |
| 137 _dev_priv, \ | 196 _dev_priv, \ |
| 164 // Send one character to the output device, return true if consumed | 223 // Send one character to the output device, return true if consumed |
| 165 bool (*putc)(serial_channel *priv, unsigned char c); | 224 bool (*putc)(serial_channel *priv, unsigned char c); |
| 166 // Fetch one character from the device | 225 // Fetch one character from the device |
| 167 unsigned char (*getc)(serial_channel *priv); | 226 unsigned char (*getc)(serial_channel *priv); |
| 168 // Change hardware configuration (baud rate, etc) | 227 // Change hardware configuration (baud rate, etc) |
| 169 bool (*set_config)(serial_channel *priv, cyg_serial_info_t *config); | 228 Cyg_ErrNo (*set_config)(serial_channel *priv, cyg_uint32 key, const void *xbuf, |
| 229 cyg_uint32 *len); | |
| 170 // Enable the transmit channel and turn on transmit interrupts | 230 // Enable the transmit channel and turn on transmit interrupts |
| 171 void (*start_xmit)(serial_channel *priv); | 231 void (*start_xmit)(serial_channel *priv); |
| 172 // Disable the transmit channel and turn transmit interrupts off | 232 // Disable the transmit channel and turn transmit interrupts off |
| 173 void (*stop_xmit)(serial_channel *priv); | 233 void (*stop_xmit)(serial_channel *priv); |
| 174 }; | 234 }; |
