]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/ThirdParty/LPCOpen/lpc_core/lpc_chip/chip_18xx_43xx/uart_18xx_43xx.h
Update LPC18xx FreeRTOS+UDP demo to use LPCOpen USB and Ethernet drivers.
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / ThirdParty / LPCOpen / lpc_core / lpc_chip / chip_18xx_43xx / uart_18xx_43xx.h
1 /*\r
2  * @brief LPC18xx/43xx UART chip driver\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6  * All rights reserved.\r
7  *\r
8  * @par\r
9  * Software that is described herein is for illustrative purposes only\r
10  * which provides customers with programming information regarding the\r
11  * LPC products.  This software is supplied "AS IS" without any warranties of\r
12  * any kind, and NXP Semiconductors and its licensor disclaim any and\r
13  * all warranties, express or implied, including all implied warranties of\r
14  * merchantability, fitness for a particular purpose and non-infringement of\r
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility\r
16  * or liability for the use of the software, conveys no license or rights under any\r
17  * patent, copyright, mask work right, or any other intellectual property rights in\r
18  * or to any products. NXP Semiconductors reserves the right to make changes\r
19  * in the software without notification. NXP Semiconductors also makes no\r
20  * representation or warranty that such application will be suitable for the\r
21  * specified use without further testing or modification.\r
22  *\r
23  * @par\r
24  * Permission to use, copy, modify, and distribute this software and its\r
25  * documentation is hereby granted, under NXP Semiconductors' and its\r
26  * licensor's relevant copyrights in the software, without fee, provided that it\r
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This\r
28  * copyright, permission, and disclaimer notice must appear in all copies of\r
29  * this code.\r
30  */\r
31 \r
32 #ifndef __UART_18XX_43XX_H_\r
33 #define __UART_18XX_43XX_H_\r
34 \r
35 #ifdef __cplusplus\r
36 extern "C" {\r
37 #endif\r
38 \r
39 /** @defgroup 18XX_43XX CHIP: LPC18xx/43xx UART Driver\r
40  * @ingroup CHIP_18XX_43XX_Drivers\r
41  * @{\r
42  */\r
43 \r
44 /**\r
45  * @brief       Configure data width, parity mode and stop bits\r
46  * @param       pUART           : Pointer to selected pUART peripheral\r
47  * @param       Databits        : UART Data width, should be:\r
48  *                          UART_DATABIT_5: UART 5 bit data mode\r
49  *                          UART_DATABIT_6: UART 6 bit data mode\r
50  *                          UART_DATABIT_7: UART 7 bit data mode\r
51  *                          UART_DATABIT_8: UART 8 bit data mode\r
52  * @param       Parity          : UART Parity mode, should be:\r
53  *                          UART_PARITY_NONE: No parity\r
54  *                          UART_PARITY_ODD:  Odd parity\r
55  *                          UART_PARITY_EVEN: Even parity\r
56  *                          UART_PARITY_SP_1: Forced "1" stick parity\r
57  *                          UART_PARITY_SP_0: Forced "0" stick parity\r
58  * @param       Stopbits        : Number of stop bits, should be:\r
59  *                          UART_STOPBIT_1: One Stop Bit Select\r
60  *                          UART_STOPBIT_2: Two Stop Bits Select\r
61  * @return      Nothing\r
62  */\r
63 STATIC INLINE void Chip_UART_ConfigData(LPC_USART_T *pUART,\r
64                                                                                 IP_UART_DATABIT_T Databits,\r
65                                                                                 IP_UART_PARITY_T Parity,\r
66                                                                                 IP_UART_STOPBIT_T Stopbits)\r
67 {\r
68         IP_UART_ConfigData(pUART, Databits, Parity, Stopbits);\r
69 }\r
70 \r
71 /**\r
72  * @brief       Send a block of data via UART peripheral\r
73  * @param       pUART   : Pointer to selected pUART peripheral\r
74  * @param       txbuf   : Pointer to Transmit buffer\r
75  * @param       buflen  : Length of Transmit buffer\r
76  * @param       flag    : Flag used in  UART transfer, should be NONE_BLOCKING or BLOCKING\r
77  * @return      Number of bytes sent\r
78  */\r
79 STATIC INLINE uint32_t Chip_UART_Send(LPC_USART_T *pUART, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_T flag)\r
80 {\r
81         return IP_UART_Send(pUART, txbuf, buflen, flag);\r
82 }\r
83 \r
84 /**\r
85  * @brief       Receive a block of data via UART peripheral\r
86  * @param       pUART   : Pointer to selected pUART peripheral\r
87  * @param       rxbuf   : Pointer to Received buffer\r
88  * @param       buflen  : Length of Received buffer\r
89  * @param       flag    : Flag mode, should be NONE_BLOCKING or BLOCKING\r
90  * @return      Number of bytes received\r
91  */\r
92 STATIC INLINE uint32_t Chip_UART_Receive(LPC_USART_T *pUART,\r
93                                                                                  uint8_t *rxbuf,\r
94                                                                                  uint32_t buflen,\r
95                                                                                  TRANSFER_BLOCK_T flag)\r
96 {\r
97         return IP_UART_Receive(pUART, rxbuf, buflen, flag);\r
98 }\r
99 \r
100 /* UART FIFO functions ----------------------------------------------------------*/\r
101 /**\r
102  * @brief       Configure FIFO function on selected UART peripheral\r
103  * @param       pUART   : Pointer to selected pUART peripheral\r
104  * @param       FIFOCfg : Pointer to a UART_FIFO_CFG_T Structure that contains specified information about FIFO configuration\r
105  * @return      Nothing\r
106  */\r
107 STATIC INLINE void Chip_UART_FIFOConfig(LPC_USART_T *pUART, UART_FIFO_CFG_T *FIFOCfg)\r
108 {\r
109         IP_UART_FIFOConfig(pUART, FIFOCfg);\r
110 }\r
111 \r
112 /**\r
113  * @brief       Fills each UART_FIFOInitStruct member with its default value:\r
114  *                      - FIFO_DMAMode = DISABLE\r
115  *                      - FIFO_Level = UART_FIFO_TRGLEV0\r
116  *                      - FIFO_ResetRxBuf = ENABLE\r
117  *                      - FIFO_ResetTxBuf = ENABLE\r
118  *                      - FIFO_State = ENABLE\r
119  * @param       pUART   : Pointer to selected UART peripheral\r
120  * @param       UART_FIFOInitStruct     : Pointer to a UART_FIFO_CFG_T structure which will be initialized.\r
121  * @return      Nothing\r
122  */\r
123 STATIC INLINE void Chip_UART_FIFOConfigStructInit(LPC_USART_T *pUART, UART_FIFO_CFG_T *UART_FIFOInitStruct)\r
124 {\r
125         IP_UART_FIFOConfigStructInit(UART_FIFOInitStruct);\r
126 }\r
127 \r
128 /* UART operate functions -------------------------------------------------------*/\r
129 /**\r
130  * @brief       Enable or disable specified UART interrupt.\r
131  * @param       pUART           : Pointer to selected pUART peripheral\r
132  * @param       UARTIntCfg      : Specifies the interrupt flag, should be one of the following:\r
133  *                  - UART_INTCFG_RBR   : RBR Interrupt enable\r
134  *                  - UART_INTCFG_THRE  : THR Interrupt enable\r
135  *                  - UART_INTCFG_RLS   : RX line status interrupt enable\r
136  *                  - UART1_INTCFG_MS   : Modem status interrupt enable (UART1 only)\r
137  *                  - UART1_INTCFG_CTS  : CTS1 signal transition interrupt enable (UART1 only)\r
138  *                  - UART_INTCFG_ABEO  : Enables the end of auto-baud interrupt\r
139  *                  - UART_INTCFG_ABTO  : Enables the auto-baud time-out interrupt\r
140  * @param       NewState        : New state of specified UART interrupt type, should be ENALBE or DISALBE\r
141  * @return      Nothing\r
142  */\r
143 STATIC INLINE void Chip_UART_IntConfig(LPC_USART_T *pUART, IP_UART_INT_T UARTIntCfg, FunctionalState NewState)\r
144 {\r
145         IP_UART_IntConfig(pUART, UARTIntCfg, NewState);\r
146 }\r
147 \r
148 /**\r
149  * @brief       Get Source Interrupt\r
150  * @param       pUART   : Pointer to selected pUART peripheral\r
151  * @return      Return the value of IIR register\r
152  */\r
153 STATIC INLINE uint32_t Chip_UART_IntGetStatus(LPC_USART_T *pUART)\r
154 {\r
155         return IP_UART_IntGetStatus(pUART);\r
156 }\r
157 \r
158 /**\r
159  * @brief       Get current value of Line Status register in UART peripheral.\r
160  * @param       pUART   : Pointer to selected pUART peripheral\r
161  * @return      Current value of Line Status register in UART peripheral\r
162  */\r
163 STATIC INLINE uint8_t Chip_UART_GetLineStatus(LPC_USART_T *pUART)\r
164 {\r
165         return IP_UART_GetLineStatus(pUART);\r
166 }\r
167 \r
168 /**\r
169  * @brief       Check whether if UART is busy or not\r
170  * @param       pUART   : Pointer to selected pUART peripheral\r
171  * @return      RESET if UART is not busy, otherwise return SET.\r
172  */\r
173 STATIC INLINE FlagStatus Chip_UART_CheckBusy(LPC_USART_T *pUART)\r
174 {\r
175         return IP_UART_CheckBusy(pUART);\r
176 }\r
177 \r
178 /**\r
179  * @brief       Force BREAK character on UART line, output pin pUART TXD is forced to logic 0\r
180  * @param       pUART   : Pointer to selected pUART peripheral\r
181  * @return      Nothing\r
182  */\r
183 STATIC INLINE void Chip_UART_ForceBreak(LPC_USART_T *pUART)\r
184 {\r
185         IP_UART_ForceBreak(pUART);\r
186 }\r
187 \r
188 /**\r
189  * @brief       Transmit a single data through UART peripheral\r
190  * @param       pUART   : Pointer to selected pUART peripheral\r
191  * @param       data    : Data to transmit (must be 8-bit long)\r
192  * @return      Status, should be ERROR (THR is empty, ready to send) or SUCCESS (THR is not empty)\r
193  */\r
194 STATIC INLINE Status Chip_UART_SendByte(LPC_USART_T *pUART, uint8_t data)\r
195 {\r
196         return IP_UART_SendByte(pUART, data);\r
197 }\r
198 \r
199 /**\r
200  * @brief       Receive a single data from UART peripheral\r
201  * @param       pUART   : Pointer to selected pUART peripheral\r
202  * @param       *Data   : Pointer to Data to receive (must be 8-bit long)\r
203  * @return      Status, should be ERROR or (Receive data is ready) or SUCCESS (Receive data is not ready yet)\r
204  */\r
205 STATIC INLINE Status Chip_UART_ReceiveByte(LPC_USART_T *pUART, uint8_t *Data)\r
206 {\r
207         return IP_UART_ReceiveByte(pUART, Data);\r
208 }\r
209 \r
210 /**\r
211  * @brief       Initializes the pUART peripheral.\r
212  * @param       pUART   : Pointer to selected pUART peripheral\r
213  * @return      Nothing\r
214  */\r
215 void Chip_UART_Init(LPC_USART_T *pUART);\r
216 \r
217 /**\r
218  * @brief       De-initializes the pUART peripheral.\r
219  * @param       pUART   : Pointer to selected pUART peripheral\r
220  * @return      Nothing\r
221  */\r
222 void Chip_UART_DeInit(LPC_USART_T *pUART);\r
223 \r
224 /**\r
225  * @brief       Determines best dividers to get a target baud rate\r
226  * @param       pUART           : Pointer to selected pUART peripheral\r
227  * @param       baudrate        : Desired UART baud rate.\r
228  * @return      Error status, could be SUCCESS or ERROR\r
229  */\r
230 Status Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate);\r
231 \r
232 /**\r
233  * @brief       Enable/Disable transmission on UART TxD pin\r
234  * @param       pUART           : Pointer to selected pUART peripheral\r
235  * @param       NewState        : New State of Tx transmission function, should be ENABLE or DISABLE\r
236  * @return Nothing\r
237  */\r
238 void Chip_UART_TxCmd(LPC_USART_T *pUART, FunctionalState NewState);\r
239 \r
240 /**\r
241  * @brief       Get Interrupt Stream Status\r
242  * @param       pUART   : Pointer to selected pUART peripheral\r
243  * @return      Return the interrupt status, should be:\r
244  *              - UART_INTSTS_ERROR\r
245  *              - UART_INTSTS_RTR\r
246  *              - UART_INTSTS_RTS\r
247  */\r
248 IP_UART_INT_STATUS_T Chip_UART_GetIntStatus(LPC_USART_T *pUART);\r
249 \r
250 /**\r
251  * @brief       Uart interrupt service routine (chip layer)\r
252  * @param       pUART   : Pointer to selected pUART peripheral\r
253  * @return      Nothing\r
254  */\r
255 void Chip_UART_Interrupt_Handler (LPC_USART_T *pUART);\r
256 \r
257 /**\r
258  * @brief       UART transmit function for interrupt mode (using ring buffers)\r
259  * @param       pUART   : Selected UART peripheral used to send data, should be UART0\r
260  * @param       txbuf   : Pointer to Transmit buffer\r
261  * @param       buflen  : Length of Transmit buffer\r
262  * @return      Number of bytes actually sent to the ring buffer\r
263  */\r
264 uint32_t Chip_UART_Interrupt_Transmit(LPC_USART_T *pUART, uint8_t *txbuf, uint8_t buflen);\r
265 \r
266 /**\r
267  * @brief       UART read function for interrupt mode (using ring buffers)\r
268  * @param       pUART   : Selected UART peripheral used to send data, should be UART0\r
269  * @param       rxbuf   : Pointer to Received buffer\r
270  * @param       buflen  : Length of Received buffer\r
271  * @return      Number of bytes actually read from the ring buffer\r
272  */\r
273 uint32_t Chip_UART_Interrupt_Receive(LPC_USART_T *pUART, uint8_t *rxbuf, uint8_t buflen);\r
274 \r
275 /**\r
276  * @brief       Reset Tx and Rx ring buffer (head and tail)\r
277  * @param       pUART   : Pointer to selected UART peripheral\r
278  * @return      Nothing\r
279  */\r
280 void Chip_UART_InitRingBuffer(LPC_USART_T *pUART);\r
281 \r
282 /**\r
283  * @brief       Start/Stop Auto Baudrate activity\r
284  * @param       pUART                   : Pointer to selected pUART peripheral\r
285  * @param       ABConfigStruct  : A pointer to UART_AB_CFG_T structure that\r
286  *          contains specified information about UAR auto baud configuration\r
287  * @param       NewState                : New State of Auto baudrate activity, should be ENABLE or DISABLE\r
288  * @return      Nothing\r
289  * @note        Auto-baudrate mode enable bit will be cleared once this mode completed.\r
290  */\r
291 STATIC INLINE void Chip_UART_ABCmd(LPC_USART_T *pUART, UART_AB_CFG_T *ABConfigStruct, FunctionalState NewState)\r
292 {\r
293         IP_UART_ABCmd(pUART, ABConfigStruct, NewState);\r
294 }\r
295 \r
296 /**\r
297  * @brief       Clear Autobaud Interrupt\r
298  * @param       pUART           : Pointer to selected pUART peripheral\r
299  * @param       ABIntType       : type of auto-baud interrupt, should be:\r
300  *                              - UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt\r
301  *                              - UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt\r
302  * @return      Nothing\r
303  */\r
304 STATIC INLINE void Chip_UART_ABClearIntPending(LPC_USART_T *pUART, IP_UART_INT_STATUS_T ABIntType)\r
305 {\r
306         IP_UART_ABClearIntPending(pUART, ABIntType);\r
307 }\r
308 \r
309 // FIXME - this function is probably not interrupt related and needs a DoxyGen header\r
310 /* UART interrupt service routine */\r
311 FlagStatus Chip_UART_GetABEOStatus(LPC_USART_T *pUART);\r
312 \r
313 /**\r
314  * @}\r
315  */\r
316 #ifdef __cplusplus\r
317 }\r
318 #endif\r
319 #endif /* __UART_18XX_43XX_H_ */\r