2 * @brief LPC18xx/43xx UART chip driver
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\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
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
32 #ifndef __UART_18XX_43XX_H_
\r
33 #define __UART_18XX_43XX_H_
\r
39 /** @defgroup 18XX_43XX CHIP: LPC18xx/43xx UART Driver
\r
40 * @ingroup CHIP_18XX_43XX_Drivers
\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
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
68 IP_UART_ConfigData(pUART, Databits, Parity, Stopbits);
\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
79 STATIC INLINE uint32_t Chip_UART_Send(LPC_USART_T *pUART, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_T flag)
\r
81 return IP_UART_Send(pUART, txbuf, buflen, flag);
\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
92 STATIC INLINE uint32_t Chip_UART_Receive(LPC_USART_T *pUART,
\r
95 TRANSFER_BLOCK_T flag)
\r
97 return IP_UART_Receive(pUART, rxbuf, buflen, flag);
\r
100 /* UART FIFO functions ----------------------------------------------------------*/
\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
107 STATIC INLINE void Chip_UART_FIFOConfig(LPC_USART_T *pUART, UART_FIFO_CFG_T *FIFOCfg)
\r
109 IP_UART_FIFOConfig(pUART, FIFOCfg);
\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
123 STATIC INLINE void Chip_UART_FIFOConfigStructInit(LPC_USART_T *pUART, UART_FIFO_CFG_T *UART_FIFOInitStruct)
\r
125 IP_UART_FIFOConfigStructInit(UART_FIFOInitStruct);
\r
128 /* UART operate functions -------------------------------------------------------*/
\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
143 STATIC INLINE void Chip_UART_IntConfig(LPC_USART_T *pUART, IP_UART_INT_T UARTIntCfg, FunctionalState NewState)
\r
145 IP_UART_IntConfig(pUART, UARTIntCfg, NewState);
\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
153 STATIC INLINE uint32_t Chip_UART_IntGetStatus(LPC_USART_T *pUART)
\r
155 return IP_UART_IntGetStatus(pUART);
\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
163 STATIC INLINE uint8_t Chip_UART_GetLineStatus(LPC_USART_T *pUART)
\r
165 return IP_UART_GetLineStatus(pUART);
\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
173 STATIC INLINE FlagStatus Chip_UART_CheckBusy(LPC_USART_T *pUART)
\r
175 return IP_UART_CheckBusy(pUART);
\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
183 STATIC INLINE void Chip_UART_ForceBreak(LPC_USART_T *pUART)
\r
185 IP_UART_ForceBreak(pUART);
\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
194 STATIC INLINE Status Chip_UART_SendByte(LPC_USART_T *pUART, uint8_t data)
\r
196 return IP_UART_SendByte(pUART, data);
\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
205 STATIC INLINE Status Chip_UART_ReceiveByte(LPC_USART_T *pUART, uint8_t *Data)
\r
207 return IP_UART_ReceiveByte(pUART, Data);
\r
211 * @brief Initializes the pUART peripheral.
\r
212 * @param pUART : Pointer to selected pUART peripheral
\r
215 void Chip_UART_Init(LPC_USART_T *pUART);
\r
218 * @brief De-initializes the pUART peripheral.
\r
219 * @param pUART : Pointer to selected pUART peripheral
\r
222 void Chip_UART_DeInit(LPC_USART_T *pUART);
\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
230 Status Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate);
\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
238 void Chip_UART_TxCmd(LPC_USART_T *pUART, FunctionalState NewState);
\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
248 IP_UART_INT_STATUS_T Chip_UART_GetIntStatus(LPC_USART_T *pUART);
\r
251 * @brief Uart interrupt service routine (chip layer)
\r
252 * @param pUART : Pointer to selected pUART peripheral
\r
255 void Chip_UART_Interrupt_Handler (LPC_USART_T *pUART);
\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
264 uint32_t Chip_UART_Interrupt_Transmit(LPC_USART_T *pUART, uint8_t *txbuf, uint8_t buflen);
\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
273 uint32_t Chip_UART_Interrupt_Receive(LPC_USART_T *pUART, uint8_t *rxbuf, uint8_t buflen);
\r
276 * @brief Reset Tx and Rx ring buffer (head and tail)
\r
277 * @param pUART : Pointer to selected UART peripheral
\r
280 void Chip_UART_InitRingBuffer(LPC_USART_T *pUART);
\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
289 * @note Auto-baudrate mode enable bit will be cleared once this mode completed.
\r
291 STATIC INLINE void Chip_UART_ABCmd(LPC_USART_T *pUART, UART_AB_CFG_T *ABConfigStruct, FunctionalState NewState)
\r
293 IP_UART_ABCmd(pUART, ABConfigStruct, NewState);
\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
304 STATIC INLINE void Chip_UART_ABClearIntPending(LPC_USART_T *pUART, IP_UART_INT_STATUS_T ABIntType)
\r
306 IP_UART_ABClearIntPending(pUART, ABIntType);
\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
319 #endif /* __UART_18XX_43XX_H_ */
\r