2 * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
4 * This software may be freely used, copied, modified, and distributed
5 * provided that the above copyright notice is preserved in all copies of the
17 * Title: Definitions required for the rx and tx engines
25 * we need a definition for bool, which is "system" dependent
35 /* return status codes for the rx engine */
36 typedef enum re_status {
43 /* return status codes for the tx engine */
44 typedef enum te_status {
52 * required serial definitions, they should all be <32, refer to the
53 * re_config struct comments for more details
55 #define serial_STX (0x1c) /* data packet start */
56 #define serial_ETX (0x1d) /* packet end */
57 #define serial_ESC (0x1b) /* standard escape character */
58 #define serial_XON (0x11) /* software flow control - enable transmission */
59 #define serial_XOFF (0x13) /* software flow control - disable transmission */
62 * All other characters are transmitted clean. If any of the above
63 * characters need to be transmitted as part of the serial data stream
64 * then the character will be preceded by the "serial_ESC" character,
65 * and then the required character transmitted (OR-ed with the
66 * "serial_ESCAPE" value, to ensure that the serial stream never has
67 * any of the exceptional characters generated by data transfers).
70 #define serial_ESCAPE (0x40) /* OR-ed with escaped characters */
72 /* bad packet error codes */
73 typedef enum re_error {
83 /* a decoded packet */
85 unsigned short buf_len; /* should be set by caller */
86 DevChanID type; /* valid when status is RS_GOOD_PKT */
87 unsigned short len; /* --"-- */
88 unsigned int crc; /* crc for the unescaped pkt */
89 unsigned char *data; /* should be set by caller */
93 * Purpose: typedef for flow control function
96 * Input: fc_char the flow control character in question
97 * In/Out: cb_data callback data as set in the fc_data
98 * field of re_config, typically device id
100 * This callback would tpyically respond to received XON and XOFF
101 * characters by controlling the transmit side of the device.
103 typedef void (*fc_cb_func)(char fc_char, void *cb_data);
107 * Purpose: typedef for the function to alloc the data buffer
110 * In/Out: packet the data packet: len and type will be set on
111 * entry, and buf_len and data should
112 * be set by this routine if successful.
113 * cb_data callback data as set in the ba_data
114 * field of re_config, typically device id
116 * Returns: TRUE buffer allocated okay
117 * FALSE couldn't allocate buffer of required size
120 * This callback should attempt to acquire a buffer for the data portion
121 * of the packet which is currently being received, based on the len and
122 * type fields supplied in packet.
124 * angel_DD_RxEng_BufferAlloc() is supplied for use as this callback,
125 * and will be sufficient for most devices.
127 typedef bool (*BufferAlloc_CB_Fn)(struct data_packet *packet, void *cb_data);
131 * The static info needed by the engine, may vary per device.
133 * fc_set and esc_set are bitmaps, e.g. bit 3 == charcode 3 == ASCII ETX.
134 * Thus any of the first 32 charcodes can be set for flow control or to
137 * Note that esc_set should include all of fc_set, and should have bits
138 * set for stx, etx and esc, as a minimum.
140 * If character codes > 31 need to be used then fc_set and esc_set
141 * and their handling can be extended to use arrays and bit manipulation
142 * macros, potentially up to the full 256 possible chars.
144 * Note too that this could/should be shared with the tx engine.
148 unsigned char stx; /* the STX char for this device */
149 unsigned char etx; /* the ETX --"-- */
150 unsigned char esc; /* the ESC --"-- */
151 unsigned int fc_set; /* bitmap of flow control chars */
152 unsigned int esc_set; /* bitmap of special chars */
153 fc_cb_func fc_callback; /* flow control callback func */
154 void *fc_data; /* data to pass to fc_callback */
155 BufferAlloc_CB_Fn ba_callback; /* buffer alloc callback */
156 void *ba_data; /* data to pass to ba_calback */
159 /* the dynamic info needed by the rx engine */
161 unsigned char rx_state; /* 3 bits pkt state, 1 prepro state */
162 unsigned short field_c; /* chars left in current field */
163 unsigned short index; /* index into buffer */
164 unsigned int crc; /* crc accumulator */
165 re_error error; /* valid only if status is RS_BAD_PKT */
166 const struct re_config *config; /* pointer to static config */
169 /* dynamic state info needed by the tx engine */
171 unsigned short field_c; /* position in current field */
172 unsigned char tx_state; /* encodes n,e, and f (2+1+2=5 bits) */
173 unsigned char encoded; /* escape-encoded char for transmission */
174 const struct re_config *config; /* pointer to static config */
175 unsigned int crc; /* space for CRC (before escaping) */
179 * Function: Angel_RxEngineInit
180 * Purpose: Initialise state (during device init) for engine.
183 * Input: config static config info
184 * In/Out: state internal state
187 void Angel_RxEngineInit(const struct re_config *config,
188 struct re_state *state);
191 * Function: Angel_RxEngine
192 * Purpose: Rx Engine for character-based devices
195 * Input: new_ch the latest character
197 * In/Out: packet details of packet
198 * packet.buf_len and packet.data must
200 * state internal state, intially set by
201 * angel_RxEngineInit()
203 * Returns: re_status (see above)
207 re_status Angel_RxEngine(unsigned char new_ch, struct data_packet *packet,
208 struct re_state *state);
211 * This can be used as the buffer allocation callback for the rx engine,
212 * and will make use of angel_DD_GetBuffer() [in devdrv.h].
214 * Saves duplicating this callback function in every device driver that
215 * uses the rx engine.
217 * Note that this REQUIRES that the device id is installed as ba_data
218 * in the rx engine config structure for the driver.
220 bool angel_DD_RxEng_BufferAlloc( struct data_packet *packet, void *cb_data );
223 * Function: Angel_TxEngineInit
224 * Purpose: Set up tx engine at start of new packet, calculate CRC etc.
225 * (This should perform the actions described under
226 * "Initialisation" above)
229 * Input: config static config info
230 * packet the packet to transmit
231 * In/Out: state internal state
234 void Angel_TxEngineInit(const struct re_config *config,
235 const struct data_packet *packet,
236 struct te_state *state);
239 * Function: Angel_TxEngine
240 * Purpose: Tx Engine for character-based devices
243 * Input: packet details of packet
244 * packet.len, packet.data and
247 * In/Out: state internal state, intially set by
248 * angel_TxEngineStart()
249 * Output: tx_ch the character to be transmitted
250 * (NOT SET if return code is TS_IDLE)
252 * Returns: te_status (see above)
255 te_status Angel_TxEngine(const struct data_packet *packet,
256 struct te_state *state,
257 unsigned char *tx_ch);
261 #endif /* !defined(angel_rxtx_h) */