]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_IGLOO2_Creative_SoftConsole/Microsemi_Code/drivers/Core16550/core_16550.h
98b1f16eaa576f69fd33c75c250c6236bcd3339a
[freertos] / FreeRTOS / Demo / RISC-V_IGLOO2_Creative_SoftConsole / Microsemi_Code / drivers / Core16550 / core_16550.h
1 /*******************************************************************************\r
2  * (c) Copyright 2007-2015 Microsemi SoC Products Group. All rights reserved.\r
3  *\r
4  * This file contains the application programming interface for the Core16550\r
5  * bare metal driver.\r
6  *\r
7  * SVN $Revision: 7963 $\r
8  * SVN $Date: 2015-10-09 17:58:21 +0530 (Fri, 09 Oct 2015) $\r
9  */\r
10 /*=========================================================================*//**\r
11   @mainpage Core16550 Bare Metal Driver.\r
12 \r
13   @section intro_sec Introduction\r
14   The Core16550 is an implementation of the Universal Asynchronous\r
15   Receiver/Transmitter aimed at complete compliance to standard 16550 UART.\r
16   The Core16550 bare metal software driver is designed for use in systems\r
17   with no operating system.\r
18 \r
19   The Core16550 driver provides functions for polled and interrupt driven\r
20   transmitting and receiving. It also provides functions for reading the\r
21   values from different status registers, enabling and disabling interrupts\r
22   at Core16550 level. The Core16550 driver is provided as C source code.\r
23 \r
24   @section driver_configuration Driver Configuration\r
25   Your application software should configure the Core16550 driver through\r
26   calls to the UART_16550_init() function for each Core16550 instance in\r
27   the hardware design. The configuration parameters include the Core16550\r
28   hardware instance base address and other runtime parameters, such as baud\r
29   value, bit width, and parity.\r
30 \r
31   No Core16550 hardware configuration parameters are needed by the driver,\r
32   apart from the Core16550 hardware instance base address. Hence, no\r
33   additional configuration files are required to use the driver.\r
34 \r
35   @section theory_op Theory of Operation\r
36   The Core16550 software driver is designed to allow the control of multiple\r
37   instances of Core16550. Each instance of Core16550 in the hardware design\r
38   is associated with a single instance of the uart_16550_instance_t structure\r
39   in the software. You need to allocate memory for one unique\r
40   uart_16550_instance_t structure instance for each Core16550 hardware instance.\r
41   The contents of these data structures are initialized during calls to\r
42   function UART_16550_init(). A pointer to the structure is passed to\r
43   subsequent driver functions in order to identify the Core16550 hardware\r
44   instance you wish to perform the requested operation on.\r
45 \r
46   Note:     Do not attempt to directly manipulate the content of\r
47   uart_16550_instance_t structures. This structure is only intended to be\r
48   modified by the driver function.\r
49 \r
50   Initialization\r
51   The Core16550 driver is initialized through a call to the UART_16550_init()\r
52   function. This function takes the UART\92s configuration as parameters.\r
53   The UART_16550_init() function must be called before any other Core16550\r
54   driver functions can be called.\r
55 \r
56   Polled Transmission and Reception\r
57   The driver can be used to transmit and receive data once initialized. Polled\r
58   operations where the driver constantly polls the state of the UART registers\r
59   in order to control data transmit or data receive are performed using these\r
60   functions:\r
61          \95  UART_16550_polled_tx()\r
62          \95  UART_16550_polled_tx_string\r
63          \95  UART_16550_fill_tx_fifo()\r
64          \95  UART_16550_get_rx()\r
65 \r
66   Data is transmitted using the UART_16550_polled_tx() function. This function\r
67   is blocking, meaning that it will only return once the data passed to the\r
68   function has been sent to the Core16550 hardware. Data received by the\r
69   Core16550 hardware can be read by the UART_16550_get_rx() function.\r
70 \r
71   The UART_16550_polled_tx_string() function is provided to transmit a NULL (\91\0\92)\r
72   terminated string in polled mode. This function is blocking, meaning that it\r
73   will only return once the data passed to the function has been sent to the\r
74   Core16550 hardware.\r
75 \r
76   The UART_16550_fill_tx_fifo() function fills the Core16550 hardware transmit\r
77   FIFO with data from a buffer passed as a parameter and returns the number of\r
78   bytes transferred to the FIFO. If the transmit FIFO is not empty when the\r
79   UART_16550_fill_tx_fifo() function is called it returns immediately without\r
80   transferring any data to the FIFO.\r
81 \r
82   Interrupt Driven Operations\r
83   The driver can also transmit or receive data under interrupt control, freeing\r
84   your application to perform other tasks until an interrupt occurs indicating\r
85   that the driver\92s attention is required. Interrupt controlled UART operations\r
86   are performed using these functions:\r
87         \95   UART_16550_isr()\r
88         \95   UART_16550_irq_tx()\r
89         \95   UART_16550_tx_complete()\r
90         \95   UART_16550_set_tx_handler()\r
91         \95   UART_16550_set_rx_handler()\r
92         \95   UART_16550_set_rxstatus_handler()\r
93         \95   UART_16550_set_modemstatus_handler()\r
94         \95   UART_16550_enable_irq()\r
95         \95   UART_16550_disable_irq()\r
96 \r
97   Interrupt Handlers\r
98   The UART_16550_isr() function is the top level interrupt handler function for\r
99   the Core16550 driver. You must call it from the system level\r
100   (CoreInterrupt and NVIC level) interrupt service routine (ISR) assigned to the\r
101   interrupt triggered by the Core16550 INTR signal. The UART_16550_isr() function\r
102   identifies the source of the Core16550 interrupt and calls the corresponding\r
103   handler function previously registered with the driver through calls to the\r
104   UART_16550_set_rx_handler(), UART_16550_set_tx_handler(),\r
105   UART_16550_set_rxstatus_handler(), and UART_16550_set_modemstatus_handler()\r
106   functions. You are responsible for creating these lower level interrupt handlers\r
107   as part of your application program and registering them with the driver.\r
108   The UART_16550_enable_irq() and UART_16550_disable_irq() functions are used to\r
109   enable or disable the received line status, received data available/character\r
110   timeout, transmit holding register empty and modem status interrupts at the\r
111   Core16550 level.\r
112 \r
113   Transmitting Data\r
114   Interrupt-driven transmit is initiated by a call to UART_16550_irq_tx(),\r
115   specifying the block of data to transmit. Your application is then free to\r
116   perform other tasks and inquire later whether transmit has completed by calling\r
117   the UART_16550_tx_complete() function. The UART_16550_irq_tx() function enables\r
118   the UART\92s transmit holding register empty (THRE) interrupt and then, when the\r
119   interrupt goes active, the driver\92s default THRE interrupt handler transfers\r
120   the data block to the UART until the entire block is transmitted.\r
121 \r
122   Note:     You can use the UART_16550_set_tx_handler() function to assign an\r
123   alternative handler to the THRE interrupt. In this case, you must not use the\r
124   UART_16550_irq_tx() function to initiate the transmit, as this will re-assign\r
125   the driver\92s default THRE interrupt handler to the THRE interrupt. Instead,\r
126   your alternative THRE interrupt handler must include a call to the\r
127   UART_16550_fill_tx_fifo() function to transfer the data to the UART.\r
128 \r
129   Receiving Data\r
130   Interrupt-driven receive is performed by first calling UART_16550_set_rx_handler()\r
131   to register a receive handler function that will be called by the driver whenever\r
132   receive data is available. You must provide this receive handler function which\r
133   must include a call to the UART_16550_get_rx() function to actually read the\r
134   received data.\r
135 \r
136   UART Status\r
137   The function UART_16550_get_rx_status() is used to read the receiver error status.\r
138   This function returns the overrun, parity, framing, break, and FIFO error status\r
139   of the receiver.\r
140   The function UART_16550_get_tx_status() is used to read the transmitter status.\r
141   This function returns the transmit empty (TEMT) and transmit holding register\r
142   empty (THRE) status of the transmitter.\r
143   The function UART_16550_get_modem_status() is used to read the modem status flags.\r
144   This function returns the current value of the modem status register.\r
145 \r
146   Loopback\r
147   The function UART_16550_set_loopback() is used to enable or disable loopback\r
148   between Tx and Rx lines internal to Core16550.\r
149 *//*=========================================================================*/\r
150 #ifndef __CORE_16550_H\r
151 #define __CORE_16550_H 1\r
152 \r
153 #include "cpu_types.h"\r
154 \r
155 #ifdef __cplusplus\r
156 extern "C" {\r
157 #endif\r
158 \r
159 /***************************************************************************//**\r
160  * Receiver Error Status\r
161  * The following defines are used to determine the UART receiver error type.\r
162  * These bit mask constants are used with the return value of the\r
163  * UART_16550_get_rx_status() function to find out if any errors occurred\r
164  * while receiving data.\r
165  */\r
166 #define UART_16550_NO_ERROR         ( (uint8_t) 0x00 )\r
167 #define UART_16550_OVERRUN_ERROR    ( (uint8_t) 0x02 )\r
168 #define UART_16550_PARITY_ERROR     ( (uint8_t) 0x04 )\r
169 #define UART_16550_FRAMING_ERROR    ( (uint8_t) 0x08 )\r
170 #define UART_16550_BREAK_ERROR      ( (uint8_t) 0x10 )\r
171 #define UART_16550_FIFO_ERROR       ( (uint8_t) 0x80 )\r
172 #define UART_16550_INVALID_PARAM    ( (uint8_t) 0xFF )\r
173 \r
174 /***************************************************************************//**\r
175  * Modem Status\r
176  * The following defines are used to determine the modem status. These bit\r
177  * mask constants are used with the return value of the\r
178  * UART_16550_get_modem_status() function to find out the modem status of\r
179  * the UART.\r
180  */\r
181 #define UART_16550_DCTS             ( (uint8_t) 0x01 )\r
182 #define UART_16550_DDSR             ( (uint8_t) 0x02 )\r
183 #define UART_16550_TERI             ( (uint8_t) 0x04 )\r
184 #define UART_16550_DDCD             ( (uint8_t) 0x08 )\r
185 #define UART_16550_CTS              ( (uint8_t) 0x10 )\r
186 #define UART_16550_DSR              ( (uint8_t) 0x20 )\r
187 #define UART_16550_RI               ( (uint8_t) 0x40 )\r
188 #define UART_16550_DCD              ( (uint8_t) 0x80 )\r
189 \r
190 /***************************************************************************//**\r
191  * Transmitter Status\r
192  * The following definitions are used to determine the UART transmitter status.\r
193  * These bit mask constants are used with the return value of the\r
194  * UART_16550_get_tx_status() function to find out the status of the\r
195  * transmitter.\r
196  */\r
197 #define UART_16550_TX_BUSY          ( (uint8_t) 0x00 )\r
198 #define UART_16550_THRE             ( (uint8_t) 0x20 )\r
199 #define UART_16550_TEMT             ( (uint8_t) 0x40 )\r
200 \r
201 /***************************************************************************//**\r
202  * Core16550 Interrupts\r
203  * The following defines are used to enable and disable Core16550 interrupts.\r
204  * They are used to build the value of the irq_mask parameter for the\r
205  * UART_16550_enable_irq() and UART_16550_disable_irq() functions. A bitwise\r
206  * OR of these constants is used to enable or disable multiple interrupts.\r
207  */\r
208 #define UART_16550_RBF_IRQ          ( (uint8_t) 0x01 )\r
209 #define UART_16550_TBE_IRQ          ( (uint8_t) 0x02 )\r
210 #define UART_16550_LS_IRQ           ( (uint8_t) 0x04 )\r
211 #define UART_16550_MS_IRQ           ( (uint8_t) 0x08 )\r
212 \r
213 /***************************************************************************//**\r
214  * Data Width\r
215  * The following defines are used to build the value of the UART_16550_init()\r
216  * function line_config parameter.\r
217  */\r
218 #define UART_16550_DATA_5_BITS      ( (uint8_t) 0x00 )\r
219 #define UART_16550_DATA_6_BITS      ( (uint8_t) 0x01 )\r
220 #define UART_16550_DATA_7_BITS      ( (uint8_t) 0x02 )\r
221 #define UART_16550_DATA_8_BITS      ( (uint8_t) 0x03 )\r
222 \r
223 /***************************************************************************//**\r
224  * Parity Control\r
225  * The following defines are used to build the value of the UART_16550_init()\r
226  * function line_config parameter.\r
227  */\r
228 #define UART_16550_NO_PARITY            ( (uint8_t) 0x00 )\r
229 #define UART_16550_ODD_PARITY           ( (uint8_t) 0x08 )\r
230 #define UART_16550_EVEN_PARITY          ( (uint8_t) 0x18 )\r
231 #define UART_16550_STICK_PARITY_1       ( (uint8_t) 0x28 )\r
232 #define UART_16550_STICK_PARITY_0       ( (uint8_t) 0x38 )\r
233 \r
234 /***************************************************************************//**\r
235  * Number of Stop Bits\r
236  * The following defines are used to build the value of the UART_16550_init()\r
237  * function line_config parameter.\r
238  */\r
239 #define UART_16550_ONE_STOP_BIT     ( (uint8_t) 0x00 )\r
240 /*only when data bits is 5*/\r
241 #define UART_16550_ONEHALF_STOP_BIT ( (uint8_t) 0x04 )\r
242 /*only when data bits is not 5*/\r
243 #define UART_16550_TWO_STOP_BITS    ( (uint8_t) 0x04 )\r
244 \r
245 /***************************************************************************//**\r
246   This enumeration specifies the receiver FIFO trigger level. This is the number\r
247   of bytes that must be received before the UART generates a receive data\r
248   available interrupt. It provides the allowed values for the\r
249   UART_16550_set_rx_handler() function\92s trigger_level parameter.\r
250  */\r
251 typedef enum {\r
252     UART_16550_FIFO_SINGLE_BYTE    = 0,\r
253     UART_16550_FIFO_FOUR_BYTES     = 1,\r
254     UART_16550_FIFO_EIGHT_BYTES    = 2,\r
255     UART_16550_FIFO_FOURTEEN_BYTES = 3,\r
256     UART_16550_FIFO_INVALID_TRIG_LEVEL\r
257 } uart_16550_rx_trig_level_t;\r
258 \r
259 /***************************************************************************//**\r
260   This enumeration specifies the Loopback configuration of the UART. It provides\r
261   the allowed values for the UART_16550_set_loopback() function\92s loopback\r
262   parameter.\r
263  */\r
264 typedef enum {\r
265     UART_16550_LOOPBACK_OFF   = 0,\r
266     UART_16550_LOOPBACK_ON    = 1,\r
267     UART_16550_INVALID_LOOPBACK\r
268 } uart_16550_loopback_t;\r
269 \r
270 /***************************************************************************//**\r
271   This is type definition for Core16550 instance. You need to create and\r
272   maintain a record of this type. This holds all data regarding the Core16550\r
273   instance.\r
274  */\r
275 typedef struct uart_16550_instance uart_16550_instance_t;\r
276 \r
277 /***************************************************************************//**\r
278   This typedef specifies the function prototype for Core16550 interrupt handlers.\r
279   All interrupt handlers registered with the Core16550 driver must be of this\r
280   type. The interrupt handlers are registered with the driver through the\r
281   UART_16550_set_rx_handler(), UART_16550_set_tx_handler(),\r
282   UART_16550_set_rxstatus_handler(), and UART_16550_set_modemstatus_handler()\r
283   functions.\r
284 \r
285   The this_uart parameter is a pointer to a uart_16550_instance_t structure that\r
286   holds all data regarding this instance of the Core16550.\r
287  */\r
288 typedef void (*uart_16550_irq_handler_t)(uart_16550_instance_t * this_uart);\r
289 \r
290 /***************************************************************************//**\r
291   uart_16550_instance.\r
292   This structure is used to identify the various Core16550 hardware instances\r
293   in your system. Your application software should declare one instance of this\r
294   structure for each instance of Core16550 in your system. The function\r
295   UART_16550_init() initializes this structure. A pointer to an initialized\r
296   instance of the structure should be passed as the first parameter to the\r
297   Core16550 driver functions, to identify which Core16550 hardware instance\r
298   should perform the requested operation.\r
299  */\r
300 struct uart_16550_instance{\r
301     /* Core16550 instance base address: */\r
302     addr_t      base_address;\r
303     /* Accumulated status: */\r
304     uint8_t     status;\r
305 \r
306     /* transmit related info: */\r
307     const uint8_t*  tx_buffer;\r
308     uint32_t        tx_buff_size;\r
309     uint32_t        tx_idx;\r
310 \r
311     /* line status (OE, PE, FE & BI) interrupt handler:*/\r
312     uart_16550_irq_handler_t linests_handler;\r
313     /* receive interrupt handler:*/\r
314     uart_16550_irq_handler_t rx_handler;\r
315     /* transmitter holding register interrupt handler:*/\r
316     uart_16550_irq_handler_t tx_handler;\r
317     /* modem status interrupt handler:*/\r
318     uart_16550_irq_handler_t modemsts_handler;\r
319 };\r
320 \r
321 /***************************************************************************//**\r
322  * The UART_16550_init() function initializes the driver\92s data structures and\r
323  * the Core16550 hardware with the configuration passed as parameters.. The\r
324  * configuration parameters are the baud_value used to generate the baud rate,\r
325  * and the line_config used to specify the line configuration (bit length,\r
326  * stop bits and parity).\r
327  *\r
328  * @param this_uart     The this_uart parameter is a pointer to a\r
329  *                      uart_16550_instance_t structure that holds all data\r
330  *                      regarding this instance of the Core16550. This pointer\r
331  *                      is used to identify the target Core16550 hardware\r
332  *                      instance in subsequent calls to the Core16550 driver\r
333  *                      functions.\r
334  * @param base_addr     The base_address parameter is the base address in the\r
335  *                      processor's memory map for the registers of the\r
336  *                      Core16550 instance being initialized.\r
337  * @param baud_value    The baud_value parameter is used to select the baud rate\r
338  *                      for the UART. The baud value is calculated from the\r
339  *                      frequency of the system clock in Hertz and the desired\r
340  *                      baud rate using the following equation:\r
341  *\r
342  *                      baud_value = (clock /(baud_rate * 16))\r
343  *\r
344  *                      The baud_value parameter must be a value in the range 0\r
345  *                      to 65535 (or 0x0000 to 0xFFFF).\r
346  * @param line_config   This parameter is the line configuration specifying the\r
347  *                      bit length, number of stop bits and parity settings. This\r
348  *                      is a bitwise OR of one value from each of the following\r
349  *                      groups of allowed values:\r
350  *                      \95   Data lengths:\r
351  *                          UART_16550_DATA_5_BITS\r
352  *                          UART_16550_DATA_6_BITS\r
353  *                          UART_16550_DATA_7_BITS\r
354  *                          UART_16550_DATA_8_BITS\r
355  *                      \95   Parity types:\r
356  *                          UART_16550_NO_PARITY\r
357  *                          UART_16550_EVEN_PARITY\r
358  *                          UART_16550_ODD_PARITY\r
359  *                          UART_16550_STICK_PARITY_0\r
360  *                          UART_16550_STICK_PARITY_1\r
361  *                      \95   Number of stop bits:\r
362  *                          UART_16550_ONE_STOP_BIT\r
363  *                          UART_16550_ONEHALF_STOP_BIT\r
364  *                          UART_16550_TWO_STOP_BITS\r
365  * @return              This function does not return a value.\r
366  *\r
367  * Example:\r
368  * @code\r
369  * #define UART_16550_BASE_ADDR   0x2A000000\r
370  * #define BAUD_VALUE_57600    26\r
371  *\r
372  * uart_16550_instance_t g_uart;\r
373  *\r
374  * UART_16550_init( &g_uart, UART_16550_BASE_ADDR, BAUD_VALUE_57600,\r
375  *                  (UART_16550_DATA_8_BITS |\r
376  *                   UART_16550_EVEN_PARITY |\r
377  *                   UART_16550_ONE_STOP_BIT) );\r
378  * @endcode\r
379  */\r
380 void\r
381 UART_16550_init\r
382 (\r
383     uart_16550_instance_t* this_uart,\r
384     addr_t base_addr,\r
385     uint16_t baud_value,\r
386     uint8_t line_config\r
387 );\r
388 \r
389 /***************************************************************************//**\r
390  * The UART_16550_polled_tx() function is used to transmit data. It transfers\r
391  * the contents of the transmitter data buffer, passed as a function parameter,\r
392  * into the UART's hardware transmitter FIFO. It returns when the full content\r
393  * of the transmitter data buffer has been transferred to the UART's transmitter\r
394  * FIFO. It is safe to release or reuse the memory used as the transmitter data\r
395  * buffer once this function returns.\r
396  *\r
397  * Note:    This function reads the UART\92s line status register (LSR) to poll\r
398  * for the active state of the transmitter holding register empty (THRE) bit\r
399  * before transferring data from the data buffer to the transmitter FIFO. It\r
400  * transfers data to the transmitter FIFO in blocks of 16 bytes or less and\r
401  * allows the FIFO to empty before transferring the next block of data.\r
402  *\r
403  * Note:    The actual transmission over the serial connection will still be in\r
404  * progress when this function returns. Use the UART_16550_get_tx_status()\r
405  * function if you need to know when the transmitter is empty.\r
406  *\r
407  * @param this_uart     The this_uart parameter is a pointer to a\r
408  *                      uart_16550_instance_t structure that holds all\r
409  *                      data regarding this instance of the Core16550.\r
410  * @param pbuff         The pbuff parameter is a pointer to a buffer containing\r
411  *                      the data to be transmitted.\r
412  * @param tx_size       The tx_size parameter is the size, in bytes, of the\r
413  *                      data to be transmitted.\r
414  * @return              This function does not return a value.\r
415  *\r
416  * Example:\r
417  * @code\r
418  *   uint8_t testmsg1[] = {"\n\r\n\r\n\rUART_16550_polled_tx() test message 1"};\r
419  *   UART_16550_polled_tx(&g_uart,(const uint8_t *)testmsg1,sizeof(testmsg1));\r
420  * @endcode\r
421  */\r
422 void\r
423 UART_16550_polled_tx\r
424 (\r
425     uart_16550_instance_t * this_uart,\r
426     const uint8_t * pbuff,\r
427     uint32_t tx_size\r
428 );\r
429 /***************************************************************************//**\r
430  * The UART_16550_polled_tx_string() function is used to transmit a NULL ('\0')\r
431  * terminated string. It transfers the text string, from the buffer starting at\r
432  * the address pointed to by p_sz_string, into the UART\92s hardware transmitter\r
433  * FIFO. It returns when the complete string has been transferred to the UART's\r
434  * transmit FIFO. It is safe to release or reuse the memory used as the string\r
435  * buffer once this function returns.\r
436  *\r
437  * Note:    This function reads the UART\92s line status register (LSR) to poll\r
438  * for the active state of the transmitter holding register empty (THRE) bit\r
439  * before transferring data from the data buffer to the transmitter FIFO. It\r
440  * transfers data to the transmitter FIFO in blocks of 16 bytes or less and\r
441  * allows the FIFO to empty before transferring the next block of data.\r
442  *\r
443  * Note:    The actual transmission over the serial connection will still be\r
444  * in progress when this function returns. Use the UART_16550_get_tx_status()\r
445  * function if you need to know when the transmitter is empty.\r
446  *\r
447  * @param this_uart     The this_uart parameter is a pointer to a\r
448  *                      uart_16550_instance_t structure that holds all data\r
449  *                      regarding this instance of the Core16550.\r
450  * @param p_sz_string   The p_sz_string parameter is a pointer to a buffer\r
451  *                      containing the NULL ('\0') terminated string to be\r
452  *                      transmitted.\r
453  * @return              This function does not return a value.\r
454  *\r
455  * Example:\r
456  * @code\r
457  *   uint8_t testmsg1[] = {"\r\n\r\nUART_16550_polled_tx_string() test message 1\0"};\r
458  *   UART_16550_polled_tx_string(&g_uart,(const uint8_t *)testmsg1);\r
459  * @endcode\r
460  */\r
461 void\r
462 UART_16550_polled_tx_string\r
463 (\r
464     uart_16550_instance_t * this_uart,\r
465     const uint8_t * p_sz_string\r
466 );\r
467 \r
468 /***************************************************************************//**\r
469  * The UART_16550_irq_tx() function is used to initiate an interrupt driven\r
470  * transmit. It returns immediately after making a note of the transmit buffer\r
471  * location and enabling the transmitter holding register empty (THRE) interrupt\r
472  * at the Core16550 level. This function takes a pointer via the pbuff parameter\r
473  * to a memory buffer containing the data to transmit. The memory buffer\r
474  * specified through this pointer must remain allocated and contain the data to\r
475  * transmit until the transmit completion has been detected through calls to\r
476  * function UART_16550_tx_complete().The actual transmission over the serial\r
477  * connection is still in progress until calls to the UART_16550_tx_complete()\r
478  * function indicate transmit completion.\r
479  *\r
480  * Note:    It is your responsibility to call UART_16550_isr(), the driver\92s\r
481  * top level interrupt handler function, from the system level (CoreInterrupt\r
482  * and NVIC level) interrupt handler assigned to the interrupt triggered by the\r
483  * Core16550 INTR signal. You must do this before using the UART_16550_irq_tx()\r
484  * function.\r
485  *\r
486  * Note:    It is also your responsibility to enable the system level\r
487  * (CoreInterrupt and NVIC level) interrupt connected to the Core16550 INTR\r
488  * interrupt signal.\r
489  *\r
490  * Note:    The UART_16550_irq_tx() function assigns an internal default transmit\r
491  * interrupt handler function to the UART\92s THRE interrupt. This interrupt handler\r
492  * overrides any custom interrupt handler that you may have previously registered\r
493  * using the UART_16550_set_tx_handler() function.\r
494  *\r
495  * Note:    The UART_16550_irq_tx() function\92s default transmit interrupt handler\r
496  * disables the UART\92s THRE interrupt when all of the data has been transferred\r
497  * to the UART's transmit FIFO.\r
498  *\r
499  * @param this_uart     The this_uart parameter is a pointer to a\r
500  *                      uart_16550_instance_t structure that holds all data\r
501  *                      regarding this instance of the Core16550.\r
502  * @param pbuff         The pbuff parameter is a pointer to a buffer containing\r
503  *                      the data to be transmitted.\r
504  * @param tx_size       The tx_size parameter specifies the size, in bytes, of\r
505  *                      the data to be transmitted.\r
506  * @return              This function does not return a value.\r
507  *\r
508  * Example:\r
509  * @code\r
510  * uint8_t tx_buff[10] = "abcdefghi";\r
511  *\r
512  * UART_16550_irq_tx( &g_uart, tx_buff, sizeof(tx_buff));\r
513  * while ( 0 == UART_16550_tx_complete( &g_uart ) )\r
514  * { ; }\r
515  * @endcode\r
516  */\r
517 void\r
518 UART_16550_irq_tx\r
519 (\r
520     uart_16550_instance_t * this_uart,\r
521     const uint8_t * pbuff,\r
522     uint32_t tx_size\r
523 );\r
524 \r
525 /***************************************************************************//**\r
526  * The UART_16550_tx_complete() function is used to find out if the interrupt\r
527  * driven transmit previously initiated through a call to UART_16550_irq_tx()\r
528  * is complete. This function is typically used to find out when it is safe\r
529  * to reuse or release the memory buffer holding the transmit data.\r
530  *\r
531  * Note:    The transfer of all of the data from the memory buffer to the UART\92s\r
532  * transmit FIFO and the actual transmission over the serial connection are both\r
533  * complete when a call to the UART_16550_tx_complete() function indicate\r
534  * transmit completion.\r
535  *\r
536  * @param this_uart     The this_uart parameter is a pointer to a\r
537  *                      uart_16550_instance_t structure that holds all data\r
538  *                      regarding this instance of the Core16550.\r
539  * @return              This function returns a non-zero value if transmit has\r
540  *                      completed, otherwise it returns zero.\r
541  *  Example:\r
542  *   See the UART_16550_irq_tx() function for an example that uses the\r
543  *   UART_16550_tx_complete() function.\r
544  */\r
545 int8_t\r
546 UART_16550_tx_complete\r
547 (\r
548    uart_16550_instance_t * this_uart\r
549 );\r
550 \r
551 /***************************************************************************//**\r
552  * The UART_16550_get_rx() function reads the content of the Core16550\r
553  * receiver\92s FIFO and stores it in the receive buffer that is passed via the\r
554  * rx_buff function parameter. It copies either the full contents of the FIFO\r
555  * into the receive buffer, or just enough data from the FIFO to fill the receive\r
556  * buffer, dependent upon the size of the receive buffer passed by the buff_size\r
557  * parameter. The UART_16550_get_rx() function returns the number of bytes copied\r
558  * into the receive buffer .This function is non-blocking and will return 0\r
559  * immediately if no data has been received.\r
560  *\r
561  * Note:    The UART_16550_get_rx() function reads and accumulates the receiver\r
562  * status of the Core16550 instance before reading each byte from the receiver's\r
563  * data register/FIFO. This allows the driver to maintain a sticky record of any\r
564  * receiver errors that occur as the UART receives each data byte; receiver errors\r
565  * would otherwise be lost after each read from the receiver's data register. A call\r
566  * to the UART_16550_get_rx_status() function returns any receiver errors accumulated\r
567  * during the execution of the UART_16550_get_rx() function.\r
568  *\r
569  * Note:    If you need to read the error status for each byte received, set the\r
570  * buff_size to 1 and read the receive line error status for each byte using the\r
571  * UART_16550_get_rx_status() function.\r
572  * The UART_16550_get_rx() function can be used in polled mode, where it is called\r
573  * at regular intervals to find out if any data has been received, or in interrupt\r
574  * driven-mode, where it is called as part of a receive handler that is called by\r
575  * the driver as a result of data being received.\r
576  *\r
577  * Note:    In interrupt driven mode you should call the UART_16550_get_rx()\r
578  * function as part of the receive handler function that you register with the\r
579  * Core16550 driver through a call to UART_16550_set_rx_handler().\r
580  *\r
581  * @param this_uart     The this_uart parameter is a pointer to a\r
582  *                      uart_16550_instance_t structure that holds all data\r
583  *                      regarding this instance of the Core16550.\r
584  * @param rx_buff       The rx_buff parameter is a pointer to a memory buffer\r
585  *                      where the received data is copied.\r
586  * @param buff_size     The buff_size parameter is the size of the receive\r
587  *                      buffer in bytes.\r
588  * @return              This function returns the number of bytes copied into\r
589  *                      the receive buffer.\r
590  * Example:\r
591  * @code\r
592  *   #define MAX_RX_DATA_SIZE    256\r
593  *\r
594  *   uint8_t rx_data[MAX_RX_DATA_SIZE];\r
595  *   uint8_t rx_size = 0;\r
596  *\r
597  *   rx_size = UART_16550_get_rx( &g_uart, rx_data, sizeof(rx_data) );\r
598  * @endcode\r
599  */\r
600 size_t\r
601 UART_16550_get_rx\r
602 (\r
603    uart_16550_instance_t * this_uart,\r
604    uint8_t * rx_buff,\r
605    size_t buff_size\r
606 );\r
607 \r
608 /***************************************************************************//**\r
609  * The UART_16550_isr() function is the top level interrupt handler function for\r
610  * the Core16550 driver. You must call UART_16550_isr() from the system level\r
611  * (CoreInterrupt and NVIC level) interrupt handler assigned to the interrupt\r
612  * triggered by the Core16550 INTR signal. Your system level interrupt handler\r
613  * must also clear the system level interrupt triggered by the Core16550 INTR\r
614  * signal before returning, to prevent a re-assertion of the same interrupt.\r
615  *\r
616  * Note:    This function supports all types of interrupt triggered by Core16550.\r
617  * It is not a complete interrupt handler by itself; rather, it is a top level\r
618  * wrapper that abstracts Core16550 interrupt handling by calling lower level\r
619  * handler functions specific to each type of Core16550 interrupt. You must\r
620  * create the lower level handler functions to suit your application and\r
621  * register them with the driver through calls to the UART_16550_set_rx_handler(),\r
622  * UART_16550_set_tx_handler(), UART_16550_set_rxstatus_handler() and\r
623  * UART_16550_set_modemstatus_handler() functions.\r
624  *\r
625  * @param this_uart     The this_uart parameter is a pointer to a\r
626  *                      uart_16550_instance_t structure that holds all data\r
627  *                      regarding this instance of the Core16550.\r
628  *\r
629  * @return              This function does not return a value.\r
630  *\r
631  * Example:\r
632  * @code\r
633  *   void CIC_irq1_handler(void)\r
634  *   {\r
635  *      UART_16550_isr( &g_uart );\r
636  *   }\r
637  * @endcode\r
638  */\r
639 void\r
640 UART_16550_isr\r
641 (\r
642    uart_16550_instance_t * this_uart\r
643 );\r
644 \r
645 /***************************************************************************//**\r
646  * The UART_16550_set_rx_handler() function is used to register a receive handler\r
647  * function that is called by the driver when a UART receive data available (RDA)\r
648  * interrupt occurs. The UART_16550_set_rx_handler() function also enables the\r
649  * RDA interrupt at the Core16550 level. You must create and register the receive\r
650  * handler function to suit your application and it must include a call to the\r
651  * UART_16550_get_rx() function to actually read the received data.\r
652  *\r
653  * Note:    The driver\92s top level interrupt handler function UART_16550_isr()\r
654  * will call your receive handler function in response to an RDA interrupt from\r
655  * the Core16550.\r
656  *\r
657  * Note:    You can disable the RDA interrupt once the data is received by calling\r
658  * the UART_16550_disable_irq() function. This is your choice and is dependent\r
659  * upon your application.\r
660  *\r
661  * @param this_uart     The this_uart parameter is a pointer to a\r
662  *                      uart_16550_instance_t structure that holds all data\r
663  *                      regarding this instance of the Core16550.\r
664  * @param handler       The handler parameter is a pointer to a receive interrupt\r
665  *                      handler function provided by your application that will be\r
666  *                      called as a result of a UART RDA interrupt. This handler\r
667  *                      function must be of type uart_16550_irq_handler_t.\r
668  * @param trigger_level The trigger_level parameter is the receive FIFO\r
669  *                      trigger level. This specifies the number of bytes that\r
670  *                      must be received before the UART triggers an RDA\r
671  *                      interrupt.\r
672  * @return              This function does not return a value.\r
673  *\r
674  * Example:\r
675  * @code\r
676  * #include "core_16550.h"\r
677  *\r
678  * #define RX_BUFF_SIZE    64\r
679  * #define UART_57600_BAUD 26\r
680  *\r
681  * uint8_t g_rx_buff[RX_BUFF_SIZE];\r
682  * uart_16550_instance_t g_uart;\r
683  * void uart_rx_handler( uart_16550_instance_t * this_uart )\r
684  * {\r
685  *     UART_16550_get_rx( this_uart, g_rx_buff, RX_BUFF_SIZE );\r
686  * }\r
687  *\r
688  * int main(void)\r
689  * {\r
690  *     UART_16550_init( &g_uart, UART_57600_BAUD,\r
691  *                       ( UART_16550_DATA_8_BITS | UART_16550_NO_PARITY ) );\r
692  *     UART_16550_set_rx_handler( &g_uart, uart_rx_handler,\r
693  *                                UART_16550_FIFO_SINGLE_BYTE);\r
694  *     while ( 1 )\r
695  *     {\r
696  *         ;\r
697  *     }\r
698  *     return(0);\r
699  * }\r
700  * @endcode\r
701  */\r
702 void\r
703 UART_16550_set_rx_handler\r
704 (\r
705     uart_16550_instance_t * this_uart,\r
706     uart_16550_irq_handler_t handler,\r
707     uart_16550_rx_trig_level_t trigger_level\r
708 );\r
709 \r
710 /***************************************************************************//**\r
711  * The UART_16550_set_loopback() function is used to locally loopback the Tx\r
712  * and Rx lines of a Core16550 UART.\r
713  *\r
714  * @param this_uart     The this_uart parameter is a pointer to a\r
715  *                      uart_16550_instance_t structure that holds all data\r
716  *                      regarding this instance of the Core16550.\r
717  * @param loopback      The loopback parameter indicates whether or not the\r
718  *                      UART's transmit and receive lines should be looped back.\r
719  *                      Allowed values are as follows:\r
720  *                      \95   UART_16550_LOOPBACK_ON\r
721  *                      \95   UART_16550_LOOPBACK_OFF\r
722  * @return              This function does not return a value.\r
723  *\r
724  * Example:\r
725  * @code\r
726  * #include "core_16550.h"\r
727  *\r
728  * #define UART_57600_BAUD 26\r
729  * #define DATA_SIZE 4\r
730  *\r
731  * uart_16550_instance_t g_uart;\r
732  *\r
733  * int main(void)\r
734  * {\r
735  *      uint8_t txbuf[DATA_SIZE] = "abc";\r
736  *      uint8_t rxbuf[DATA_SIZE];\r
737  *      UART_16550_init( &g_uart, UART_57600_BAUD,\r
738  *                        ( UART_16550_DATA_8_BITS | UART_16550_NO_PARITY |\r
739  *                                               UART_16550_ONE_STOP_BIT) );\r
740  *      UART_16550_set_loopback( &g_uart, UART_16550_LOOPBACK_ON );\r
741  *\r
742  *      while(1)\r
743  *      {\r
744  *          UART_16550_polled_tx( &g_uart, txbuf, DATA_SIZE);\r
745  *          delay(100);\r
746  *          UART_16550_get_rx( &g_uart, rxbuf, DATA_SIZE);\r
747  *      }\r
748  * }\r
749  * @endcode\r
750  */\r
751 void\r
752 UART_16550_set_loopback\r
753 (\r
754     uart_16550_instance_t * this_uart,\r
755     uart_16550_loopback_t loopback\r
756 );\r
757 \r
758 /***************************************************************************//**\r
759  * The UART_16550_get_rx_status() function returns the receiver error status of\r
760  * the Core16550 instance. It reads both the current error status of the receiver\r
761  * from the UART\92s line status register (LSR) and the accumulated error status\r
762  * from preceding calls to the UART_16550_get_rx() function, and it combines\r
763  * them using a bitwise OR. It returns the cumulative overrun, parity, framing,\r
764  * break and FIFO error status of the receiver, since the previous call to\r
765  * UART_16550_get_rx_status(), as an 8-bit encoded value.\r
766  *\r
767  * Note:    The UART_16550_get_rx() function reads and accumulates the receiver\r
768  * status of the Core16550 instance before reading each byte from the receiver\92s\r
769  * data register/FIFO. The driver maintains a sticky record of the cumulative\r
770  * receiver error status, which persists after the UART_16550_get_rx() function\r
771  * returns. The UART_16550_get_rx_status() function clears the driver\92s sticky\r
772  * receiver error record before returning.\r
773  *\r
774  * Note:    The driver\92s transmit functions also read the line status register\r
775  * (LSR) as part of their implementation. When the driver reads the LSR, the\r
776  * UART clears any active receiver error bits in the LSR. This could result in\r
777  * the driver losing receiver errors. To avoid any loss of receiver errors, the\r
778  * transmit functions also update the driver\92s sticky record of the cumulative\r
779  * receiver error status whenever they read the LSR.\r
780  *\r
781  * @param this_uart     The this_uart parameter is a pointer to a\r
782  *                      uart_16550_instance_t structure that holds all data\r
783  *                      regarding this instance of the Core16550.\r
784  * @return              This function returns the UART\92s receiver error status\r
785  *                      as an 8-bit unsigned integer. The returned value is 0\r
786  *                      if no receiver errors occurred. The driver provides a\r
787  *                      set of bit mask constants that should be compared with\r
788  *                      and/or used to mask the returned value to determine the\r
789  *                      receiver error status.\r
790  *                      When the return value is compared to the following bit\r
791  *                      masks, a non-zero result indicates that the\r
792  *                      corresponding error occurred:\r
793  *                      \95   UART_16550_OVERRUN_ERROR    (bit mask = 0x02)\r
794  *                      \95   UART_16550_PARITY_ERROR     (bit mask = 0x04)\r
795  *                      \95   UART_16550_FRAMING_ERROR    (bit mask = 0x08)\r
796  *                      \95   UART_16550_BREAK_ERROR      (bit mask = 0x10)\r
797  *                      \95   UART_16550_FIFO_ERROR       (bit mask = 0x80)\r
798  *                      When the return value is compared to the following bit\r
799  *                      mask, a non-zero result indicates that no error occurred:\r
800  *                      \95   UART_16550_NO_ERROR         (bit mask = 0x00)\r
801  *                      Upon unsuccessful execution, this function returns:\r
802  *                      \95   UART_16550_INVALID_PARAM    (bit mask = 0xFF)\r
803  *\r
804  * Example:\r
805  * @code\r
806  *   uart_16550_instance_t g_uart;\r
807  *   uint8_t rx_data[MAX_RX_DATA_SIZE];\r
808  *   uint8_t err_status;\r
809  *\r
810  *   err_status = UART_16550_get_rx_status(&g_uart);\r
811  *   if(UART_16550_NO_ERROR == err_status )\r
812  *   {\r
813  *        rx_size = UART_16550_get_rx( &g_uart, rx_data, MAX_RX_DATA_SIZE );\r
814  *   }\r
815  * @endcode\r
816  */\r
817 uint8_t\r
818 UART_16550_get_rx_status\r
819 (\r
820     uart_16550_instance_t * this_uart\r
821 );\r
822 /***************************************************************************//**\r
823  * The UART_16550_enable_irq() function enables the Core16550 interrupts\r
824  * specified by the irq_mask parameter. The irq_mask parameter identifies the\r
825  * Core16550 interrupts by bit position, as defined in the interrupt enable\r
826  * register (IER) of Core16550. The Core16550 interrupts and their identifying\r
827  * irq_mask bit positions are as follows:\r
828  *      \95   Receive data available interrupt (RDA)      (irq_mask bit 0)\r
829  *      \95   Transmit holding register empty interrupt (THRE)    (irq_mask bit 1)\r
830  *      \95   Receiver line status interrupt (LS)         (irq_mask bit 2)\r
831  *      \95   Modem status interrupt (MS)         (irq_mask bit 3)\r
832  * When an irq_mask bit position is set to 1, this function enables the\r
833  * corresponding Core16550 interrupt in the IER register. When an irq_mask\r
834  * bit position is set to 0, the corresponding interrupt\92s state remains\r
835  * unchanged in the IER register.\r
836  *\r
837  * @param this_uart     The this_uart parameter is a pointer to a\r
838  *                      uart_16550_instance_t structure that holds all data\r
839  *                      regarding this instance of the Core16550.\r
840  * @param irq_mask      The irq_mask parameter is used to select which of the\r
841  *                      Core16550\92s interrupts you want to enable. The allowed\r
842  *                      value for the irq_mask parameter is one of the\r
843  *                      following constants or a bitwise OR of more than one:\r
844  *                      \95   UART_16550_RBF_IRQ      (bit mask = 0x01)\r
845  *                      \95   UART_16550_TBE_IRQ      (bit mask = 0x02)\r
846  *                      \95   UART_16550_LS_IRQ       (bit mask = 0x04)\r
847  *                      \95   UART_16550_MS_IRQ       (bit mask = 0x08)\r
848  * @return              This function does not return a value.\r
849  *\r
850  * Example:\r
851  * @code\r
852  *   UART_16550_enable_irq( &g_uart,( UART_16550_RBF_IRQ | UART_16550_TBE_IRQ ) );\r
853  * @endcode\r
854  */\r
855 void\r
856 UART_16550_enable_irq\r
857 (\r
858     uart_16550_instance_t * this_uart,\r
859     uint8_t irq_mask\r
860 );\r
861 \r
862 /***************************************************************************//**\r
863  * The UART_16550_disable_irq() function disables the Core16550 interrupts\r
864  * specified by the irq_mask parameter. The irq_mask parameter identifies the\r
865  * Core16550 interrupts by bit position, as defined in the interrupt enable\r
866  * register (IER) of Core16550. The Core16550 interrupts and their identifying\r
867  * bit positions are as follows:\r
868  *      \95   Receive data available interrupt (RDA)              (irq_mask bit 0)\r
869  *      \95   Transmit holding register empty interrupt (THRE)    (irq_mask bit 1)\r
870  *      \95   Receiver line status interrupt (LS)                 (irq_mask bit 2)\r
871  *      \95   Modem status interrupt (MS)                         (irq_mask bit 3)\r
872  * When an irq_mask bit position is set to 1, this function disables the\r
873  * corresponding Core16550 interrupt in the IER register. When an irq_mask bit\r
874  * position is set to 0, the corresponding interrupt\92s state remains unchanged\r
875  * in the IER register.\r
876  *\r
877  * @param this_uart     The this_uart parameter is a pointer to a\r
878  *                      uart_16550_instance_t structure that holds all data\r
879  *                      regarding this instance of the Core16550.\r
880  * @param irq_mask      The irq_mask parameter is used to select which of the\r
881  *                      Core16550\92s interrupts you want to disable. The allowed\r
882  *                      value for the irq_mask parameter is one of the\r
883  *                      following constants or a bitwise OR of more than one:\r
884  *                      \95   UART_16550_RBF_IRQ      (bit mask = 0x01)\r
885  *                      \95   UART_16550_TBE_IRQ      (bit mask = 0x02)\r
886  *                      \95   UART_16550_LS_IRQ       (bit mask = 0x04)\r
887  *                      \95   UART_16550_MS_IRQ       (bit mask = 0x08)\r
888  * @return              This function does not return a value.\r
889  *\r
890  * Example:\r
891  * @code\r
892  *   UART_16550_disable_irq( &g_uart, ( UART_16550_RBF_IRQ | UART_16550_TBE_IRQ ) );\r
893  * @endcode\r
894  */\r
895 void\r
896 UART_16550_disable_irq\r
897 (\r
898     uart_16550_instance_t * this_uart,\r
899     uint8_t irq_mask\r
900 );\r
901 \r
902 /***************************************************************************//**\r
903  * The UART_16550_get_modem_status() function returns the modem status of the\r
904  * Core16550 instance. It reads the modem status register (MSR) and returns the\r
905  * 8 bit value. The bit encoding of the returned value is exactly the same as\r
906  * the definition of the bits in the MSR.\r
907  *\r
908  * @param this_uart     The this_uart parameter is a pointer to a\r
909  *                      uart_16550_instance_t structure that holds all data\r
910  *                      regarding this instance of the Core16550.\r
911  * @return              This function returns current state of the UART's MSR\r
912  *                      as an 8 bit unsigned integer. The driver provides the\r
913  *                      following set of bit mask constants that should be\r
914  *                      compared with and/or used to mask the returned value\r
915  *                      to determine the modem status:\r
916  *                      \95   UART_16550_DCTS (bit mask = 0x01)\r
917  *                      \95   UART_16550_DDSR (bit mask = 0x02)\r
918  *                      \95   UART_16550_TERI (bit mask = 0x04)\r
919  *                      \95   UART_16550_DDCD (bit mask = 0x08)\r
920  *                      \95   UART_16550_CTS  (bit mask = 0x10)\r
921  *                      \95   UART_16550_DSR  (bit mask = 0x20)\r
922  *                      \95   UART_16550_RI   (bit mask = 0x40)\r
923  *                      \95   UART_16550_DCD  (bit mask = 0x80)\r
924  * Example:\r
925  * @code\r
926  *   void uart_modem_status_isr(uart_16550_instance_t * this_uart)\r
927  *   {\r
928  *      uint8_t status;\r
929  *      status = UART_16550_get_modem_status( this_uart );\r
930  *      if( status & UART_16550_DCTS )\r
931  *      {\r
932  *          uart_dcts_handler();\r
933  *      }\r
934  *      if( status & UART_16550_CTS )\r
935  *      {\r
936  *          uart_cts_handler();\r
937  *      }\r
938  *   }\r
939  * @endcode\r
940  */\r
941 uint8_t\r
942 UART_16550_get_modem_status\r
943 (\r
944     uart_16550_instance_t * this_uart\r
945 );\r
946 \r
947 /***************************************************************************//**\r
948  * The UART_16550_set_rxstatus_handler() function is used to register a receiver\r
949  * status handler function that is called by the driver when a UART receiver\r
950  * line status (RLS) interrupt occurs. The UART_16550_set_rxstatus_handler()\r
951  * function also enables the RLS interrupt at the Core16550 level. You must\r
952  * create and register the receiver status handler function to suit your\r
953  * application.\r
954  *\r
955  * Note:    The driver\92s top level interrupt handler function UART_16550_isr()\r
956  * will call your receive status handler function in response to an RLS\r
957  * interrupt from the Core16550.\r
958  *\r
959  * Note:    You can disable the RLS interrupt when required by calling the\r
960  * UART_16550_disable_irq() function. This is your choice and is dependent\r
961  * upon your application.\r
962  *\r
963  * @param this_uart     The this_uart parameter is a pointer to a\r
964  *                      uart_16550_instance_t structure that holds all data\r
965  *                      regarding this instance of the Core16550.\r
966  * @param handler       The handler parameter is a pointer to a receiver line\r
967  *                      status interrupt handler function provided by your\r
968  *                      application that will be called as a result of a\r
969  *                      UART RLS interrupt. This handler function must be\r
970  *                      of type uart_16550_irq_handler_t.\r
971  * Example:\r
972  * @code\r
973  * #include "core_16550.h"\r
974  *\r
975  * #define UART_57600_BAUD 26\r
976  *\r
977  * uart_16550_instance_t g_uart;\r
978  *\r
979  * void uart_rxsts_handler( uart_16550_instance_t * this_uart )\r
980  * {\r
981  *      uint8_t status;\r
982  *      status = UART_16550_get_rx_status( this_uart );\r
983  *      if( status & UART_16550_OVERUN_ERROR )\r
984  *      {\r
985  *          discard_rx_data();\r
986  *      }\r
987  * }\r
988  *\r
989  * int main(void)\r
990  * {\r
991  *     UART_16550_init( &g_uart, UART_57600_BAUD,\r
992  *                      UART_16550_DATA_8_BITS | UART_16550_NO_PARITY |\r
993  *                                             UART_16550_ONE_STOP_BIT );\r
994  *     UART_16550_set_rxstatus_handler( &g_uart, uart_rxsts_handler );\r
995  *\r
996  *     while ( 1 )\r
997  *     {\r
998  *         ;\r
999  *     }\r
1000  *     return(0);\r
1001  * }\r
1002  * @endcode\r
1003  */\r
1004 void\r
1005 UART_16550_set_rxstatus_handler\r
1006 (\r
1007     uart_16550_instance_t * this_uart,\r
1008     uart_16550_irq_handler_t handler\r
1009 );\r
1010 \r
1011 /***************************************************************************//**\r
1012  * The UART_16550_set_tx_handler() function is used to register a transmit\r
1013  * handler function that is called by the driver when a UART transmit holding\r
1014  * register empty (THRE) interrupt occurs. The UART_16550_set_tx_handler()\r
1015  * function also enables the THRE interrupt at the Core16550 level. You must\r
1016  * create and register the transmit handler function to suit your application.\r
1017  * You can use the UART_16550_fill_tx_fifo() function in your transmit handler\r
1018  * function to write data to the transmitter.\r
1019  *\r
1020  * Note:    The driver\92s top level interrupt handler function UART_16550_isr()\r
1021  * will call your transmit handler function in response to an THRE interrupt\r
1022  * from the Core16550.\r
1023  *\r
1024  * Note:    You can disable the THRE interrupt when required by calling the\r
1025  * UART_16550_disable_irq() function. This is your choice and is dependent\r
1026  * upon your application.\r
1027  *\r
1028  * Note:    The UART_16550_irq_tx() function does not use the transmit handler\r
1029  * function that you register with the UART_16550_set_tx_handler() function.\r
1030  * It uses its own internal THRE interrupt handler function that overrides any\r
1031  * custom interrupt handler that you register using the\r
1032  * UART_16550_set_tx_handler() function.\r
1033  *\r
1034  * @param this_uart     The this_uart parameter is a pointer to a\r
1035  *                      uart_16550_instance_t structure that holds all data\r
1036  *                      regarding this instance of the Core16550.\r
1037  * @param handler       The handler parameter is a pointer to a transmitter\r
1038  *                      interrupt handler function provided by your application,\r
1039  *                      which will be called as a result of a UART THRE interrupt.\r
1040  *                      This handler is of uart_16550_irq_handler_t type.\r
1041  * @return              This function does not return a value.\r
1042  *\r
1043  * Example:\r
1044  * @code\r
1045  * #include "core_16550.h"\r
1046  *\r
1047  * #define UART_57600_BAUD 26\r
1048  *\r
1049  * uart_16550_instance_t g_uart;\r
1050  *\r
1051  * uint8_t * g_tx_buffer;\r
1052  * size_t g_tx_size = 0;\r
1053  *\r
1054  * void uart_tx_handler( uart_16550_instance_t * this_uart )\r
1055  * {\r
1056  *      size_t size_in_fifo;\r
1057  *\r
1058  *      size_in_fifo = UART_16550_fill_tx_fifo( this_uart,\r
1059  *                                              (const uint8_t *)g_tx_buffer,\r
1060  *                                              g_tx_size );\r
1061  *\r
1062  *      if(size_in_fifo == g_tx_size)\r
1063  *      {\r
1064  *         g_tx_size = 0;\r
1065  *         UART_16550_disable_irq( this_uart, UART_16550_TBE_IRQ );\r
1066  *      }\r
1067  *      else\r
1068  *      {\r
1069  *         g_tx_buffer = &g_tx_buffer[size_in_fifo];\r
1070  *         g_tx_size = g_tx_size - size_in_fifo;\r
1071  *      }\r
1072  *  }\r
1073  *\r
1074  *  int main(void)\r
1075  *  {\r
1076  *      uint8_t message[12] = "Hello world";\r
1077  *\r
1078  *      UART_16550_init( &g_uart, UART_57600_BAUD,\r
1079  *                       UART_16550_DATA_8_BITS | UART_16550_NO_PARITY |\r
1080  *                                            UART_16550_ONE_STOP_BIT );\r
1081  *\r
1082  *      g_tx_buffer = message;\r
1083  *      g_tx_size = sizeof(message);\r
1084  *\r
1085  *      UART_16550_set_tx_handler( &g_uart, uart_tx_handler);\r
1086  *\r
1087  *      while ( 1 )\r
1088  *      {\r
1089  *          ;\r
1090  *      }\r
1091  *      return(0);\r
1092  *  }\r
1093  *\r
1094  * @endcode\r
1095  */\r
1096 void\r
1097 UART_16550_set_tx_handler\r
1098 (\r
1099     uart_16550_instance_t * this_uart,\r
1100     uart_16550_irq_handler_t handler\r
1101 );\r
1102 \r
1103 /***************************************************************************//**\r
1104  * The UART_16550_set_modemstatus_handler() function is used to register a\r
1105  * modem status handler function that is called by the driver when a UART modem\r
1106  * status (MS) interrupt occurs. The UART_16550_set_modemstatus_handler()\r
1107  * function also enables the MS interrupt at the Core16550 level. You must\r
1108  * create and register the modem status handler function to suit your\r
1109  * application.\r
1110  *\r
1111  * Note:    The driver\92s top level interrupt handler function UART_16550_isr()\r
1112  * will call your receive status handler function in response to an MS interrupt\r
1113  * from the Core16550.\r
1114  *\r
1115  * Note:    You can disable the MS interrupt when required by calling the\r
1116  * UART_16550_disable_irq() function. This is your choice and is dependent\r
1117  * upon your application.\r
1118  *\r
1119  * @param this_uart     The this_uart parameter is a pointer to a\r
1120  *                      uart_16550_instance_t structure that holds all data\r
1121  *                      regarding this instance of the Core16550.\r
1122  * @param handler       The handler parameter is a pointer to a modem status\r
1123  *                      interrupt handler function provided by your application\r
1124  *                      that will be called as a result of a UART MS interrupt.\r
1125  *                      This handler function must be of type\r
1126  *                      uart_16550_irq_handler_t.\r
1127  * @return              This function does not return a value.\r
1128  *\r
1129  * Example:\r
1130  * @code\r
1131  * #include "core_16550.h"\r
1132  *\r
1133  * #define UART_57600_BAUD 26\r
1134  *\r
1135  * uart_16550_instance_t g_uart;\r
1136  *\r
1137  * void uart_modem_handler( uart_16550_instance_t * this_uart )\r
1138  * {\r
1139  *      uint8_t status;\r
1140  *      status = UART_16550_get_modem_status( this_uart );\r
1141  *      if( status & UART_16550_CTS )\r
1142  *      {\r
1143  *          uart_cts_handler();\r
1144  *      }\r
1145  * }\r
1146  *\r
1147  * int main(void)\r
1148  * {\r
1149  *     UART_16550_init( &g_uart, UART_57600_BAUD,\r
1150  *                      UART_16550_DATA_8_BITS | UART_16550_NO_PARITY |\r
1151                                               UART_16550_ONE_STOP_BIT);\r
1152  *     UART_16550_set_modemstatus_handler( &g_uart, uart_modem_handler);\r
1153  *\r
1154  *     while ( 1 )\r
1155  *     {\r
1156  *         ;\r
1157  *     }\r
1158  *     return(0);\r
1159  * }\r
1160  * @endcode\r
1161  */\r
1162 void\r
1163 UART_16550_set_modemstatus_handler\r
1164 (\r
1165     uart_16550_instance_t * this_uart,\r
1166     uart_16550_irq_handler_t handler\r
1167 );\r
1168 \r
1169 /***************************************************************************//**\r
1170  * The UART_16550_fill_tx_fifo() function fills the UART's hardware transmitter\r
1171  * FIFO with the data found in the transmitter buffer that is passed via the\r
1172  * tx_buffer function parameter. If the transmitter FIFO is not empty when the\r
1173  * function is called, the function returns immediately without transferring\r
1174  * any data to the FIFO; otherwise, the function transfers data from the\r
1175  * transmitter buffer to the FIFO until it is full or until the complete\r
1176  * contents of the transmitter buffer have been copied into the FIFO. The\r
1177  * function returns the number of bytes copied into the UART's transmitter FIFO.\r
1178  *\r
1179  * Note:    This function reads the UART\92s line status register (LSR) to check\r
1180  * for the active state of the transmitter holding register empty (THRE) bit\r
1181  * before transferring data from the data buffer to the transmitter FIFO. If\r
1182  * THRE is 0, the function returns immediately, without transferring any data\r
1183  * to the FIFO. If THRE is 1, the function transfers up to 16 bytes of data to\r
1184  * the FIFO and then returns.\r
1185  *\r
1186  * Note:    The actual transmission over the serial connection will still be in\r
1187  * progress when this function returns. Use the UART_16550_get_tx_status()\r
1188  * function if you need to know when the transmitter is empty.\r
1189  *\r
1190  * @param this_uart     The this_uart parameter is a pointer to a\r
1191  *                      uart_16550_instance_t structure that holds all data\r
1192  *                      regarding this instance of the Core16550.\r
1193  * @param tx_buffer     The tx_buffer parameter is a pointer to a buffer\r
1194  *                      containing the data to be transmitted.\r
1195  * @param tx_size       The tx_size parameter is the size in bytes, of the data\r
1196  *                      to be transmitted.\r
1197  * @return              This function returns the number of bytes copied\r
1198  *                      into the UART's transmitter FIFO.\r
1199  *\r
1200  * Example:\r
1201  * @code\r
1202  *   void send_using_interrupt(uint8_t * pbuff, size_t tx_size)\r
1203  *   {\r
1204  *       size_t size_in_fifo;\r
1205  *       size_in_fifo = UART_16550_fill_tx_fifo( &g_uart, pbuff, tx_size );\r
1206  *   }\r
1207  * @endcode\r
1208  */\r
1209 size_t\r
1210 UART_16550_fill_tx_fifo\r
1211 (\r
1212     uart_16550_instance_t * this_uart,\r
1213     const uint8_t * tx_buffer,\r
1214     size_t tx_size\r
1215 );\r
1216 \r
1217 /***************************************************************************//**\r
1218  * The UART_16550_get_tx_status() function returns the transmitter status of\r
1219  * the Core16550 instance. It reads both the UART\92s line status register (LSR)\r
1220  * and returns the status of the transmit holding register empty (THRE) and\r
1221  * transmitter empty (TEMT) bits.\r
1222  *\r
1223  * @param this_uart     The this_uart parameter is a pointer to a\r
1224  *                      uart_16550_instance_t structure that holds all data\r
1225  *                      regarding this instance of the Core16550.\r
1226  * @return              This function returns the UART\92s transmitter status\r
1227  *                      as an 8-bit unsigned integer. The returned value is 0\r
1228  *                      if the transmitter status bits are not set or the\r
1229  *                      function execution failed. The driver provides a set\r
1230  *                      of bit mask constants that should be compared with\r
1231  *                      and/or used to mask the returned value to determine\r
1232  *                      the transmitter status.\r
1233  *                      When the return value is compared to the following\r
1234  *                      bitmasks, a non-zero result indicates that the\r
1235  *                      corresponding transmitter status bit is set:\r
1236  *                      \95   UART_16550_THRE     (bit mask = 0x20)\r
1237  *                      \95   UART_16550_TEMT     (bit mask = 0x40)\r
1238  *                      When the return value is compared to the following\r
1239  *                      bit mask, a non-zero result indicates that the\r
1240  *                      transmitter is busy or the function execution failed.\r
1241  *                      \95   UART_16550_TX_BUSY      (bit mask = 0x00)\r
1242  * Example:\r
1243  * @code\r
1244  *   uint8_t tx_buff[10] = "abcdefghi";\r
1245  *\r
1246  *   UART_16550_polled_tx( &g_uart, tx_buff, sizeof(tx_buff));\r
1247  *\r
1248  *   while ( ! (UART_16550_TEMT & UART_16550_get_tx_status( &g_uart ) )  )\r
1249  *   {\r
1250  *      ;\r
1251  *   }\r
1252  * @endcode\r
1253  */\r
1254 uint8_t\r
1255 UART_16550_get_tx_status\r
1256 (\r
1257     uart_16550_instance_t * this_uart\r
1258 );\r
1259 \r
1260 #ifdef __cplusplus\r
1261 }\r
1262 #endif\r
1263 \r
1264 #endif /* __CORE_16550_H */\r