2 * @brief UART/USART Registers and control functions
\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 __USART_001_H_
\r
33 #define __USART_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_USART_001 IP: USART register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief USART register block structure
\r
50 typedef struct { /*!< USARTn Structure */
\r
53 __IO uint32_t DLL; /*!< Divisor Latch LSB. Least significant byte of the baud rate divisor value. The full divisor is used to generate a baud rate from the fractional rate divider (DLAB = 1). */
\r
54 __O uint32_t THR; /*!< Transmit Holding Register. The next character to be transmitted is written here (DLAB = 0). */
\r
55 __I uint32_t RBR; /*!< Receiver Buffer Register. Contains the next received character to be read (DLAB = 0). */
\r
59 __IO uint32_t IER; /*!< Interrupt Enable Register. Contains individual interrupt enable bits for the 7 potential UART interrupts (DLAB = 0). */
\r
60 __IO uint32_t DLM; /*!< Divisor Latch MSB. Most significant byte of the baud rate divisor value. The full divisor is used to generate a baud rate from the fractional rate divider (DLAB = 1). */
\r
64 __O uint32_t FCR; /*!< FIFO Control Register. Controls UART FIFO usage and modes. */
\r
65 __I uint32_t IIR; /*!< Interrupt ID Register. Identifies which interrupt(s) are pending. */
\r
68 __IO uint32_t LCR; /*!< Line Control Register. Contains controls for frame formatting and break generation. */
\r
69 __IO uint32_t MCR; /*!< Modem Control Register. Only present on USART ports with full modem support. */
\r
70 __I uint32_t LSR; /*!< Line Status Register. Contains flags for transmit and receive status, including line errors. */
\r
71 __I uint32_t MSR; /*!< Modem Status Register. Only present on USART ports with full modem support. */
\r
72 __IO uint32_t SCR; /*!< Scratch Pad Register. Eight-bit temporary storage for software. */
\r
73 __IO uint32_t ACR; /*!< Auto-baud Control Register. Contains controls for the auto-baud feature. */
\r
74 __IO uint32_t ICR; /*!< IrDA control register (not all UARTS) */
\r
75 __IO uint32_t FDR; /*!< Fractional Divider Register. Generates a clock input for the baud rate divider. */
\r
76 __IO uint32_t OSR; /*!< Oversampling Register. Controls the degree of oversampling during each bit time. Only on some UARTS. */
\r
77 __IO uint32_t TER1; /*!< Transmit Enable Register. Turns off USART transmitter for use with software flow control. */
\r
78 uint32_t RESERVED0[3];
\r
79 __IO uint32_t HDEN; /*!< Half-duplex enable Register- only on some UARTs */
\r
80 __I uint32_t RESERVED1[1];
\r
81 __IO uint32_t SCICTRL; /*!< Smart card interface control register- only on some UARTs */
\r
82 __IO uint32_t RS485CTRL; /*!< RS-485/EIA-485 Control. Contains controls to configure various aspects of RS-485/EIA-485 modes. */
\r
83 __IO uint32_t RS485ADRMATCH; /*!< RS-485/EIA-485 address match. Contains the address match value for RS-485/EIA-485 mode. */
\r
84 __IO uint32_t RS485DLY; /*!< RS-485/EIA-485 direction control delay. */
\r
86 __IO uint32_t SYNCCTRL; /*!< Synchronous mode control register. Only on USARTs. */
\r
87 __I uint32_t FIFOLVL; /*!< FIFO Level register. Provides the current fill levels of the transmit and receive FIFOs. */
\r
90 #if !defined CHIP_LPC11XX
\r
91 __IO uint32_t TER2; /*!< Transmit Enable Register. Only on LPC177X_8X UART4 and LPC18XX/43XX USART0/2/3. */
\r
95 #define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL) /*!< UART time-out definitions in case of using Read/Write function with Blocking Flag mode */
\r
97 #define UART_ACCEPTED_BAUDRATE_ERROR (3) /*!< Acceptable UART baudrate error */
\r
99 /* --------------------- BIT DEFINITIONS -------------------------------------- */
\r
101 * @brief Macro defines for UARTn Receiver Buffer Register
\r
103 #define UART_RBR_MASKBIT ((uint8_t) 0xFF) /*!< UART Received Buffer mask bit (8 bits) */
\r
106 * @brief Macro defines for UARTn Transmit Holding Register
\r
108 #define UART_THR_MASKBIT ((uint8_t) 0xFF) /*!< UART Transmit Holding mask bit (8 bits) */
\r
111 * @brief Macro defines for UARTn Divisor Latch LSB register
\r
113 #define UART_LOAD_DLL(div) ((div) & 0xFF) /*!< Macro for loading least significant halfs of divisors */
\r
114 #define UART_DLL_MASKBIT ((uint8_t) 0xFF) /*!< Divisor latch LSB bit mask */
\r
117 * @brief Macro defines for UARTn Divisor Latch MSB register
\r
119 #define UART_DLM_MASKBIT ((uint8_t) 0xFF) /*!< Divisor latch MSB bit mask */
\r
120 #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF) /*!< Macro for loading most significant halfs of divisors */
\r
123 * @brief Macro defines for UART interrupt enable register
\r
125 #define UART_IER_RBRINT_EN ((uint32_t) (1 << 0)) /*!< RBR Interrupt enable*/
\r
126 #define UART_IER_THREINT_EN ((uint32_t) (1 << 1)) /*!< THR Interrupt enable*/
\r
127 #define UART_IER_RLSINT_EN ((uint32_t) (1 << 2)) /*!< RX line status interrupt enable*/
\r
128 #define UART_IER_MSINT_EN ((uint32_t) (1 << 3)) /*!< Modem status interrupt enable */
\r
129 #define UART_IER_CTSINT_EN ((uint32_t) (1 << 7)) /*!< CTS1 signal transition interrupt enable */
\r
130 #define UART_IER_ABEOINT_EN ((uint32_t) (1 << 8)) /*!< Enables the end of auto-baud interrupt */
\r
131 #define UART_IER_ABTOINT_EN ((uint32_t) (1 << 9)) /*!< Enables the auto-baud time-out interrupt */
\r
132 #define UART_IER_BITMASK ((uint32_t) (0x307)) /*!< UART interrupt enable register bit mask */
\r
133 #define UART1_IER_BITMASK ((uint32_t) (0x38F)) /*!< UART1 interrupt enable register bit mask */
\r
136 * @brief Macro defines for UART interrupt identification register
\r
138 #define UART_IIR_INTSTAT_PEND ((uint32_t) (1 << 0)) /*!<Interrupt Status - Active low */
\r
139 #define UART_IIR_INTID_RLS ((uint32_t) (3 << 1)) /*!<Interrupt identification: Receive line status*/
\r
140 #define UART_IIR_INTID_RDA ((uint32_t) (2 << 1)) /*!<Interrupt identification: Receive data available*/
\r
141 #define UART_IIR_INTID_CTI ((uint32_t) (6 << 1)) /*!<Interrupt identification: Character time-out indicator*/
\r
142 #define UART_IIR_INTID_THRE ((uint32_t) (1 << 1)) /*!<Interrupt identification: THRE interrupt*/
\r
143 #define UART_IIR_INTID_MODEM ((uint32_t) (0 << 1)) /*!<Interrupt identification: Modem interrupt*/
\r
144 #define UART_IIR_INTID_MASK ((uint32_t) (7 << 1)) /*!<Interrupt identification: Interrupt ID mask */
\r
145 #define UART_IIR_FIFO_EN ((uint32_t) (3 << 6)) /*!<These bits are equivalent to UnFCR[0] */
\r
146 #define UART_IIR_ABEO_INT ((uint32_t) (1 << 8)) /*!< End of auto-baud interrupt */
\r
147 #define UART_IIR_ABTO_INT ((uint32_t) (1 << 9)) /*!< Auto-baud time-out interrupt */
\r
148 #define UART_IIR_BITMASK ((uint32_t) (0x3CF)) /*!< UART interrupt identification register bit mask */
\r
151 * @brief Macro defines for UART FIFO control register
\r
153 #define UART_FCR_FIFO_EN ((uint8_t) (1 << 0)) /*!< UART FIFO enable */
\r
154 #define UART_FCR_RX_RS ((uint8_t) (1 << 1)) /*!< UART FIFO RX reset */
\r
155 #define UART_FCR_TX_RS ((uint8_t) (1 << 2)) /*!< UART FIFO TX reset */
\r
156 #define UART_FCR_DMAMODE_SEL ((uint8_t) (1 << 3)) /*!< UART DMA mode selection */
\r
157 #define UART_FCR_TRG_LEV0 ((uint8_t) (0)) /*!< UART FIFO trigger level 0: 1 character */
\r
158 #define UART_FCR_TRG_LEV1 ((uint8_t) (1 << 6)) /*!< UART FIFO trigger level 1: 4 character */
\r
159 #define UART_FCR_TRG_LEV2 ((uint8_t) (2 << 6)) /*!< UART FIFO trigger level 2: 8 character */
\r
160 #define UART_FCR_TRG_LEV3 ((uint8_t) (3 << 6)) /*!< UART FIFO trigger level 3: 14 character */
\r
161 #define UART_FCR_BITMASK ((uint8_t) (0xCF)) /*!< UART FIFO control bit mask */
\r
162 #define UART_TX_FIFO_SIZE (16)
\r
165 * @brief Macro defines for UART line control register
\r
167 #define UART_LCR_WLEN5 ((uint8_t) (0)) /*!< UART 5 bit data mode */
\r
168 #define UART_LCR_WLEN6 ((uint8_t) (1 << 0)) /*!< UART 6 bit data mode */
\r
169 #define UART_LCR_WLEN7 ((uint8_t) (2 << 0)) /*!< UART 7 bit data mode */
\r
170 #define UART_LCR_WLEN8 ((uint8_t) (3 << 0)) /*!< UART 8 bit data mode */
\r
171 #define UART_LCR_SBS_1BIT ((uint8_t) (0 << 2)) /*!< UART One Stop Bit Select */
\r
172 #define UART_LCR_SBS_2BIT ((uint8_t) (1 << 2)) /*!< UART Two Stop Bits Select */
\r
173 #define UART_LCR_PARITY_EN ((uint8_t) (1 << 3)) /*!< UART Parity Enable */
\r
174 #define UART_LCR_PARITY_DIS ((uint8_t) (0 << 3)) /*!< UART Parity Disable */
\r
175 #define UART_LCR_PARITY_ODD ((uint8_t) (0)) /*!< UART Odd Parity Select */
\r
176 #define UART_LCR_PARITY_EVEN ((uint8_t) (1 << 4)) /*!< UART Even Parity Select */
\r
177 #define UART_LCR_PARITY_F_1 ((uint8_t) (2 << 4)) /*!< UART force 1 stick parity */
\r
178 #define UART_LCR_PARITY_F_0 ((uint8_t) (3 << 4)) /*!< UART force 0 stick parity */
\r
179 #define UART_LCR_BREAK_EN ((uint8_t) (1 << 6)) /*!< UART Transmission Break enable */
\r
180 #define UART_LCR_DLAB_EN ((uint8_t) (1 << 7)) /*!< UART Divisor Latches Access bit enable */
\r
181 #define UART_LCR_BITMASK ((uint8_t) (0xFF)) /*!< UART line control bit mask */
\r
184 * @brief Macro defines for UART Modem control register
\r
186 #define UART_MCR_DTR_CTRL ((uint8_t) (1 << 0)) /*!< Source for modem output pin DTR */
\r
187 #define UART_MCR_RTS_CTRL ((uint8_t) (1 << 1)) /*!< Source for modem output pin RTS */
\r
188 #define UART_MCR_LOOPB_EN ((uint8_t) (1 << 4)) /*!< Loop back mode select */
\r
189 #define UART_MCR_AUTO_RTS_EN ((uint8_t) (1 << 6)) /*!< Enable Auto RTS flow-control */
\r
190 #define UART_MCR_AUTO_CTS_EN ((uint8_t) (1 << 7)) /*!< Enable Auto CTS flow-control */
\r
191 #define UART_MCR_BITMASK ((uint8_t) (0x0F3)) /*!< UART1 bit mask value */
\r
194 * @brief Macro defines for UART line status register
\r
196 #define UART_LSR_RDR ((uint8_t) (1 << 0)) /*!<Line status register: Receive data ready*/
\r
197 #define UART_LSR_OE ((uint8_t) (1 << 1)) /*!<Line status register: Overrun error*/
\r
198 #define UART_LSR_PE ((uint8_t) (1 << 2)) /*!<Line status register: Parity error*/
\r
199 #define UART_LSR_FE ((uint8_t) (1 << 3)) /*!<Line status register: Framing error*/
\r
200 #define UART_LSR_BI ((uint8_t) (1 << 4)) /*!<Line status register: Break interrupt*/
\r
201 #define UART_LSR_THRE ((uint8_t) (1 << 5)) /*!<Line status register: Transmit holding register empty*/
\r
202 #define UART_LSR_TEMT ((uint8_t) (1 << 6)) /*!<Line status register: Transmitter empty*/
\r
203 #define UART_LSR_RXFE ((uint8_t) (1 << 7)) /*!<Error in RX FIFO*/
\r
204 #define UART_LSR_BITMASK ((uint8_t) (0xFF)) /*!<UART Line status bit mask */
\r
207 * @brief Macro defines for UART Modem status register
\r
209 #define UART_MSR_DELTA_CTS ((uint8_t) (1 << 0)) /*!< Set upon state change of input CTS */
\r
210 #define UART_MSR_DELTA_DSR ((uint8_t) (1 << 1)) /*!< Set upon state change of input DSR */
\r
211 #define UART_MSR_LO2HI_RI ((uint8_t) (1 << 2)) /*!< Set upon low to high transition of input RI */
\r
212 #define UART_MSR_DELTA_DCD ((uint8_t) (1 << 3)) /*!< Set upon state change of input DCD */
\r
213 #define UART_MSR_CTS ((uint8_t) (1 << 4)) /*!< Clear To Send State */
\r
214 #define UART_MSR_DSR ((uint8_t) (1 << 5)) /*!< Data Set Ready State */
\r
215 #define UART_MSR_RI ((uint8_t) (1 << 6)) /*!< Ring Indicator State */
\r
216 #define UART_MSR_DCD ((uint8_t) (1 << 7)) /*!< Data Carrier Detect State */
\r
217 #define UART_MSR_BITMASK ((uint8_t) (0xFF)) /*!< MSR register bit-mask value */
\r
220 * @brief Macro defines for UART Scratch Pad register
\r
222 #define UART_SCR_BIMASK ((uint8_t) (0xFF)) /*!< UART Scratch Pad bit mask */
\r
225 * @brief Macro defines for UART Auto baudrate control register
\r
227 #define UART_ACR_START ((uint32_t) (1 << 0)) /*!< UART Auto-baud start */
\r
228 #define UART_ACR_MODE ((uint32_t) (1 << 1)) /*!< UART Auto baudrate Mode 1 */
\r
229 #define UART_ACR_AUTO_RESTART ((uint32_t) (1 << 2)) /*!< UART Auto baudrate restart */
\r
230 #define UART_ACR_ABEOINT_CLR ((uint32_t) (1 << 8)) /*!< UART End of auto-baud interrupt clear */
\r
231 #define UART_ACR_ABTOINT_CLR ((uint32_t) (1 << 9)) /*!< UART Auto-baud time-out interrupt clear */
\r
232 #define UART_ACR_BITMASK ((uint32_t) (0x307)) /*!< UART Auto Baudrate register bit mask */
\r
235 * @brief Macro defines for UART IrDA control register
\r
237 #define UART_ICR_IRDAEN ((uint32_t) (1 << 0)) /*!< IrDA mode enable */
\r
238 #define UART_ICR_IRDAINV ((uint32_t) (1 << 1)) /*!< IrDA serial input inverted */
\r
239 #define UART_ICR_FIXPULSE_EN ((uint32_t) (1 << 2)) /*!< IrDA fixed pulse width mode */
\r
240 #define UART_ICR_PULSEDIV(n) ((uint32_t) ((n & 0x07) << 3)) /*!< PulseDiv - Configures the pulse when FixPulseEn = 1 */
\r
241 #define UART_ICR_BITMASK ((uint32_t) (0x3F)) /*!< UART IRDA bit mask */
\r
244 * @brief Macro defines for UART half duplex register
\r
246 #define UART_HDEN_HDEN ((uint32_t) (1 << 0)) /*!< enable half-duplex mode*/
\r
249 * @brief Macro defines for UART smart card interface control register
\r
251 #define UART_SCICTRL_SCIEN ((uint32_t) (1 << 0)) /*!< enable asynchronous half-duplex smart card interface*/
\r
252 #define UART_SCICTRL_NACKDIS ((uint32_t) (1 << 1)) /*!< NACK response is inhibited*/
\r
253 #define UART_SCICTRL_PROTSEL_T1 ((uint32_t) (1 << 2)) /*!< ISO7816-3 protocol T1 is selected*/
\r
254 #define UART_SCICTRL_TXRETRY(n) ((uint32_t) ((n & 0x07) << 5)) /*!< number of retransmission*/
\r
255 #define UART_SCICTRL_GUARDTIME(n) ((uint32_t) ((n & 0xFF) << 8)) /*!< Extra guard time*/
\r
258 * @brief Macro defines for UART synchronous control register
\r
260 #define UART_SYNCCTRL_SYNC ((uint32_t) (1 << 0)) /*!< enable synchronous mode*/
\r
261 #define UART_SYNCCTRL_CSRC_MASTER ((uint32_t) (1 << 1)) /*!< synchronous master mode*/
\r
262 #define UART_SYNCCTRL_FES ((uint32_t) (1 << 2)) /*!< sample on falling edge*/
\r
263 #define UART_SYNCCTRL_TSBYPASS ((uint32_t) (1 << 3)) /*!< to be defined*/
\r
264 #define UART_SYNCCTRL_CSCEN ((uint32_t) (1 << 4)) /*!< continuous running clock enable (master mode only)*/
\r
265 #define UART_SYNCCTRL_STARTSTOPDISABLE ((uint32_t) (1 << 5)) /*!< do not send start/stop bit*/
\r
266 #define UART_SYNCCTRL_CCCLR ((uint32_t) (1 << 6)) /*!< stop continuous clock*/
\r
269 * @brief Macro defines for UART Fractional divider register
\r
271 #define UART_FDR_DIVADDVAL(n) ((uint32_t) (n & 0x0F)) /*!< Baud-rate generation pre-scaler divisor */
\r
272 #define UART_FDR_MULVAL(n) ((uint32_t) ((n << 4) & 0xF0)) /*!< Baud-rate pre-scaler multiplier value */
\r
273 #define UART_FDR_BITMASK ((uint32_t) (0xFF)) /*!< UART Fractional Divider register bit mask */
\r
276 * @brief Macro defines for UART Tx Enable register
\r
278 #define UART_TER1_TXEN ((uint8_t) (1 << 7)) /*!< Transmit enable bit */
\r
279 #define UART_TER1_BITMASK ((uint8_t) (0x80)) /*!< UART Transmit Enable Register bit mask */
\r
280 #define UART_TER2_TXEN ((uint8_t) (1 << 0)) /*!< Transmit enable bit */
\r
281 #define UART_TER2_BITMASK ((uint8_t) (0x01)) /*!< UART Transmit Enable Register bit mask */
\r
284 * @brief Macro defines for UART1 RS485 Control register
\r
286 #define UART_RS485CTRL_NMM_EN ((uint32_t) (1 << 0)) /*!< RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */
\r
287 #define UART_RS485CTRL_RX_DIS ((uint32_t) (1 << 1)) /*!< The receiver is disabled */
\r
288 #define UART_RS485CTRL_AADEN ((uint32_t) (1 << 2)) /*!< Auto Address Detect (AAD) is enabled */
\r
289 #define UART_RS485CTRL_SEL_DTR ((uint32_t) (1 << 3)) /*!< If direction control is enabled (bit DCTRL = 1), pin DTR is
\r
290 used for direction control */
\r
291 #define UART_RS485CTRL_DCTRL_EN ((uint32_t) (1 << 4)) /*!< Enable Auto Direction Control */
\r
292 #define UART_RS485CTRL_OINV_1 ((uint32_t) (1 << 5)) /*!< This bit reverses the polarity of the direction
\r
293 control signal on the RTS (or DTR) pin. The direction control pin
\r
294 will be driven to logic "1" when the transmitter has data to be sent */
\r
295 #define UART_RS485CTRL_BITMASK ((uint32_t) (0x3F)) /*!< RS485 control bit-mask value */
\r
298 * @brief Macro defines for UART1 RS-485 Address Match register
\r
300 #define UART_RS485ADRMATCH_BITMASK ((uint8_t) (0xFF)) /*!< Bit mask value */
\r
303 * @brief Macro defines for UART1 RS-485 Delay value register
\r
305 #define UART_RS485DLY_BITMASK ((uint8_t) (0xFF)) /*!< Bit mask value */
\r
308 * @brief Macro defines for UART FIFO Level register
\r
310 #define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t) (n & 0x0F)) /*!< Reflects the current level of the UART receiver FIFO */
\r
311 #define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t) ((n >> 8) & 0x0F)) /*!< Reflects the current level of the UART transmitter FIFO */
\r
312 #define UART_FIFOLVL_BITMASK ((uint32_t) (0x0F0F)) /*!< UART FIFO Level Register bit mask */
\r
315 * @brief Macro defines for Ring Buffer
\r
317 #define UART_RING_BUFSIZE 256 /*!< buffer size definition */
\r
318 #define __BUF_MASK (UART_RING_BUFSIZE - 1) /*!< Buf mask */
\r
319 #define __BUF_IS_FULL(head, tail) ((tail & __BUF_MASK) == ((head + 1) & __BUF_MASK)) /*!< Check buf is full or not */
\r
320 #define __BUF_WILL_FULL(head, tail) ((tail & __BUF_MASK) == ((head + 2) & __BUF_MASK)) /*!< Check buf will be full in next receiving or not */
\r
321 #define __BUF_IS_EMPTY(head, tail) ((head & __BUF_MASK) == (tail & __BUF_MASK)) /*!< Check buf is empty */
\r
322 #define __BUF_RESET(bufidx) (bufidx = 0) /*!< Reset buf */
\r
323 #define __BUF_INCR(bufidx) (bufidx = (bufidx + 1) & __BUF_MASK) /*!< Increase buf */
\r
326 * @brief UART Ring buffer structure
\r
329 __IO uint32_t tx_head; /*!< UART Tx ring buffer head index */
\r
330 __IO uint32_t tx_tail; /*!< UART Tx ring buffer tail index */
\r
331 __IO uint32_t rx_head; /*!< UART Rx ring buffer head index */
\r
332 __IO uint32_t rx_tail; /*!< UART Rx ring buffer tail index */
\r
333 __IO uint8_t tx[UART_RING_BUFSIZE]; /*!< UART Tx data ring buffer */
\r
334 __IO uint8_t rx[UART_RING_BUFSIZE]; /*!< UART Rx data ring buffer */
\r
335 } UART_RingBuffer_T;
\r
338 * @brief UART Line Status Type definition
\r
340 typedef enum IP_UART_LS {
\r
341 UART_LINESTAT_RDR = UART_LSR_RDR, /*!< Line status register: Receive data ready*/
\r
342 UART_LINESTAT_OE = UART_LSR_OE, /*!< Line status register: Overrun error*/
\r
343 UART_LINESTAT_PE = UART_LSR_PE, /*!< Line status register: Parity error*/
\r
344 UART_LINESTAT_FE = UART_LSR_FE, /*!< Line status register: Framing error*/
\r
345 UART_LINESTAT_BI = UART_LSR_BI, /*!< Line status register: Break interrupt*/
\r
346 UART_LINESTAT_THRE = UART_LSR_THRE, /*!< Line status register: Transmit holding register empty*/
\r
347 UART_LINESTAT_TEMT = UART_LSR_TEMT, /*!< Line status register: Transmitter empty*/
\r
348 UART_LINESTAT_RXFE = UART_LSR_RXFE /*!< Error in RX FIFO*/
\r
352 * @brief UART Full modem - Signal states definition
\r
354 typedef enum IP_UART_SIGNAL_STATE {
\r
355 INACTIVE = 0, /*!< In-active state */
\r
356 ACTIVE = !INACTIVE /*!< Active state */
\r
357 } IP_UART_SIGNAL_STATE_T;
\r
360 * @brief UART modem status type definition
\r
362 typedef enum IP_UART_MODEM_STAT {
\r
363 UART_MODEM_STAT_DELTA_CTS = UART_MSR_DELTA_CTS, /*!< Set upon state change of input CTS */
\r
364 UART_MODEM_STAT_DELTA_DSR = UART_MSR_DELTA_DSR, /*!< Set upon state change of input DSR */
\r
365 UART_MODEM_STAT_LO2HI_RI = UART_MSR_LO2HI_RI, /*!< Set upon low to high transition of input RI */
\r
366 UART_MODEM_STAT_DELTA_DCD = UART_MSR_DELTA_DCD, /*!< Set upon state change of input DCD */
\r
367 UART_MODEM_STAT_CTS = UART_MSR_CTS, /*!< Clear To Send State */
\r
368 UART_MODEM_STAT_DSR = UART_MSR_DSR, /*!< Data Set Ready State */
\r
369 UART_MODEM_STAT_RI = UART_MSR_RI, /*!< Ring Indicator State */
\r
370 UART_MODEM_STAT_DCD = UART_MSR_DCD /*!< Data Carrier Detect State */
\r
371 } IP_UART_MODEM_STAT_T;
\r
374 * @brief Modem output pin type definition
\r
376 typedef enum IP_UART_MODEM_PIN {
\r
377 UART_MODEM_PIN_DTR = 0, /*!< Source for modem output pin DTR */
\r
378 UART_MODEM_PIN_RTS /*!< Source for modem output pin RTS */
\r
379 } IP_UART_MODEM_PIN_T;
\r
382 * @brief UART Modem mode type definition
\r
384 typedef enum IP_UART_MODEM_MODE {
\r
385 UART_MODEM_MODE_LOOPBACK = 0, /*!< Loop back mode select */
\r
386 UART_MODEM_MODE_AUTO_RTS, /*!< Enable Auto RTS flow-control */
\r
387 UART_MODEM_MODE_AUTO_CTS /*!< Enable Auto CTS flow-control */
\r
388 } IP_UART_MODEM_MODE_T;
\r
391 * @brief UART Interrupt Type definitions
\r
393 typedef enum IP_UART_INT {
\r
394 UART_INTCFG_RBR = 0, /*!< RBR Interrupt enable*/
\r
395 UART_INTCFG_THRE, /*!< THR Interrupt enable*/
\r
396 UART_INTCFG_RLS, /*!< RX line status interrupt enable*/
\r
397 UART_INTCFG_MS, /*!< Modem status interrupt enable */
\r
398 UART_INTCFG_CTS, /*!< CTS1 signal transition interrupt enable */
\r
399 UART_INTCFG_ABEO, /*!< Enables the end of auto-baud interrupt */
\r
400 UART_INTCFG_ABTO /*!< Enables the auto-baud time-out interrupt */
\r
404 * @brief UART Parity type definitions
\r
406 typedef enum IP_UART_PARITY {
\r
407 UART_PARITY_NONE = 0, /*!< No parity */
\r
408 UART_PARITY_ODD = (4 << 3), /*!< Odd parity */
\r
409 UART_PARITY_EVEN = (5 << 3), /*!< Even parity */
\r
410 UART_PARITY_SP_1 = (6 << 3), /*!< Forced "1" stick parity */
\r
411 UART_PARITY_SP_0 = (7 << 3) /*!< Forced "0" stick parity */
\r
412 } IP_UART_PARITY_T;
\r
415 * @brief FIFO Level type definitions
\r
417 typedef enum IP_UART_FITO_LEVEL {
\r
418 UART_FIFO_TRGLEV0 = 0, /*!< UART FIFO trigger level 0: 1 character */
\r
419 UART_FIFO_TRGLEV1, /*!< UART FIFO trigger level 1: 4 character */
\r
420 UART_FIFO_TRGLEV2, /*!< UART FIFO trigger level 2: 8 character */
\r
421 UART_FIFO_TRGLEV3 /*!< UART FIFO trigger level 3: 14 character */
\r
422 } IP_UART_FITO_LEVEL_T;
\r
425 * @brief UART Stop bit type definitions
\r
427 typedef enum IP_UART_STOPBIT {
\r
428 UART_STOPBIT_1 = 0, /*!< UART One Stop Bit Select */
\r
429 UART_STOPBIT_2 = (1 << 2) /*!< UART Two Stop Bits Select */
\r
430 } IP_UART_STOPBIT_T;
\r
433 * @brief UART Databit type definitions
\r
435 typedef enum IP_UART_DATABIT {
\r
436 UART_DATABIT_5 = 0, /*!< UART 5 bit data mode */
\r
437 UART_DATABIT_6, /*!< UART 6 bit data mode */
\r
438 UART_DATABIT_7, /*!< UART 7 bit data mode */
\r
439 UART_DATABIT_8 /*!< UART 8 bit data mode */
\r
440 } IP_UART_DATABIT_T;
\r
445 typedef enum IP_UART_ID {
\r
454 * @brief UART Interrupt Status
\r
456 typedef enum IP_UART_INT_STATUS {
\r
457 UART_INTSTS_ERROR = 1 << 0, /*!< UART Interrupt Error*/
\r
458 UART_INTSTS_RTS = 1 << 1, /*!< UART Interrupt status: Ready to Send*/
\r
459 UART_INTSTS_RTR = 1 << 2, /*!< UART Interrupt status: Ready to Receive*/
\r
460 UART_INTSTS_ABEO = UART_IIR_ABEO_INT, /*!< UART End of auto-baud interrupt */
\r
461 UART_INTSTS_ABTO = UART_IIR_ABTO_INT /*!< UART Auto-baud time-out interrupt */
\r
462 } IP_UART_INT_STATUS_T;
\r
465 * @brief UART Auto-baudrate mode type definition
\r
467 typedef enum IP_UART_AB_MODE {
\r
468 UART_AUTOBAUD_MODE0 = 0, /*!< UART Auto baudrate Mode 0 */
\r
469 UART_AUTOBAUD_MODE1, /*!< UART Auto baudrate Mode 1 */
\r
470 } IP_UART_AB_MODE_T;
\r
473 * @brief Auto Baudrate mode configuration type definition
\r
476 IP_UART_AB_MODE_T ABMode; /*!< Autobaudrate mode */
\r
477 FunctionalState AutoRestart; /*!< Auto Restart state */
\r
481 * @brief UART FIFO Configuration Structure definition
\r
484 FunctionalState FIFO_ResetRxBuf; /*!< Reset Rx FIFO command state , should be:
\r
485 - ENABLE: Reset Rx FIFO in UART
\r
486 - DISABLE: Do not reset Rx FIFO in UART
\r
488 FunctionalState FIFO_ResetTxBuf; /*!< Reset Tx FIFO command state , should be:
\r
489 - ENABLE: Reset Tx FIFO in UART
\r
490 - DISABLE: Do not reset Tx FIFO in UART
\r
492 FunctionalState FIFO_DMAMode; /*!< DMA mode, should be:
\r
493 - ENABLE: Enable DMA mode in UART
\r
494 - DISABLE: Disable DMA mode in UART
\r
496 IP_UART_FITO_LEVEL_T FIFO_Level; /*!< Rx FIFO trigger level, should be:
\r
497 - UART_FIFO_TRGLEV0: UART FIFO trigger level 0: 1 character
\r
498 - UART_FIFO_TRGLEV1: UART FIFO trigger level 1: 4 character
\r
499 - UART_FIFO_TRGLEV2: UART FIFO trigger level 2: 8 character
\r
500 - UART_FIFO_TRGLEV3: UART FIFO trigger level 3: 14 character
\r
505 * @brief Initializes the UARTx peripheral according to the specified parameters in the UART_ConfigStruct.
\r
506 * @param pUART : Pointer to selected UARTx peripheral
\r
507 * @param UARTPort : UART ID type
\r
510 void IP_UART_Init(IP_USART_001_T *pUART, IP_UART_ID_T UARTPort);
\r
513 * @brief De-initializes the UARTx peripheral registers to their default reset values.
\r
514 * @param pUART : Pointer to selected UARTx peripheral
\r
515 * @param UARTPort : UART ID type
\r
518 void IP_UART_DeInit(IP_USART_001_T *pUART, IP_UART_ID_T UARTPort);
\r
521 * @brief Determines best dividers to get a target clock rate
\r
522 * @param pUART : Pointer to selected UARTx peripheral
\r
523 * @param baudrate : Desired UART baud rate.
\r
524 * @param uClk : Current Uart Block Clock.
\r
525 * @return Error status, could be SUCCESS or ERROR
\r
527 Status IP_UART_SetBaud(IP_USART_001_T *pUART, uint32_t baudrate, uint32_t uClk);
\r
530 * @brief Configure data width, parity mode and stop bits
\r
531 * @param pUART : Pointer to selected UARTx peripheral
\r
532 * @param Databits : UART Data width, should be:
\r
533 * UART_DATABIT_5: UART 5 bit data mode
\r
534 * UART_DATABIT_6: UART 6 bit data mode
\r
535 * UART_DATABIT_7: UART 7 bit data mode
\r
536 * UART_DATABIT_8: UART 8 bit data mode
\r
537 * @param Parity : UART Parity mode, should be:
\r
538 * UART_PARITY_NONE: No parity
\r
539 * UART_PARITY_ODD: Odd parity
\r
540 * UART_PARITY_EVEN: Even parity
\r
541 * UART_PARITY_SP_1: Forced "1" stick parity
\r
542 * UART_PARITY_SP_0: Forced "0" stick parity
\r
543 * @param Stopbits : Number of stop bits, should be:
\r
544 * UART_STOPBIT_1: One Stop Bit Select
\r
545 * UART_STOPBIT_2: Two Stop Bits Select
\r
548 void IP_UART_ConfigData(IP_USART_001_T *pUART,
\r
549 IP_UART_DATABIT_T Databits,
\r
550 IP_UART_PARITY_T Parity,
\r
551 IP_UART_STOPBIT_T Stopbits);
\r
553 /* UART Send/Receive functions -------------------------------------------------*/
\r
555 * @brief Transmit a single data through UART peripheral
\r
556 * @param pUART : Pointer to selected UARTx peripheral
\r
557 * @param data : Data to transmit (must be 8-bit long)
\r
558 * @return Status, should be ERROR (THR is empty, ready to send) or SUCCESS (THR is not empty)
\r
560 Status IP_UART_SendByte(IP_USART_001_T *pUART, uint8_t data);
\r
563 * @brief Receive a single data from UART peripheral
\r
564 * @param pUART : Pointer to selected UARTx peripheral
\r
565 * @param *Data : Pointer to Data to receive (must be 8-bit long)
\r
566 * @return Status, should be ERROR or (Receive data is ready) or SUCCESS (Receive data is not ready yet)
\r
568 Status IP_UART_ReceiveByte(IP_USART_001_T *pUART, uint8_t *Data);
\r
571 * @brief Send a block of data via UART peripheral
\r
572 * @param pUART : Pointer to selected UARTx peripheral
\r
573 * @param txbuf : Pointer to Transmit buffer
\r
574 * @param buflen : Length of Transmit buffer
\r
575 * @param flag : Flag used in UART transfer, should be NONE_BLOCKING or BLOCKING
\r
576 * @return Number of bytes sent
\r
578 * Note: when using UART in BLOCKING mode, a time-out condition is used
\r
579 * via defined symbol UART_BLOCKING_TIMEOUT.
\r
581 uint32_t IP_UART_Send(IP_USART_001_T *pUART, uint8_t *txbuf, uint32_t buflen, TRANSFER_BLOCK_T flag);
\r
584 * @brief Receive a block of data via UART peripheral
\r
585 * @param pUART : Pointer to selected UARTx peripheral
\r
586 * @param rxbuf : Pointer to Received buffer
\r
587 * @param buflen : Length of Received buffer
\r
588 * @param flag : Flag mode, should be NONE_BLOCKING or BLOCKING
\r
589 * @return Number of bytes received
\r
591 * Note: when using UART in BLOCKING mode, a time-out condition is used
\r
592 * via defined symbol UART_BLOCKING_TIMEOUT.
\r
594 uint32_t IP_UART_Receive(IP_USART_001_T *pUART, uint8_t *rxbuf, uint32_t buflen, TRANSFER_BLOCK_T flag);
\r
596 /* UART operate functions -------------------------------------------------------*/
\r
598 * @brief Enable or disable specified UART interrupt.
\r
599 * @param pUART : Pointer to selected UARTx peripheral
\r
600 * @param UARTIntCfg : Specifies the interrupt flag, should be one of the following:
\r
601 * - UART_INTCFG_RBR : RBR Interrupt enable
\r
602 * - UART_INTCFG_THRE : THR Interrupt enable
\r
603 * - UART_INTCFG_RLS : RX line status interrupt enable
\r
604 * - UART1_INTCFG_MS : Modem status interrupt enable (UART1 only)
\r
605 * - UART1_INTCFG_CTS : CTS1 signal transition interrupt enable (UART1 only)
\r
606 * - UART_INTCFG_ABEO : Enables the end of auto-baud interrupt
\r
607 * - UART_INTCFG_ABTO : Enables the auto-baud time-out interrupt
\r
608 * @param NewState : New state of specified UART interrupt type, should be:
\r
609 * - ENALBE : Enable this UART interrupt type
\r
610 * - DISALBE : Disable this UART interrupt type
\r
613 void IP_UART_IntConfig(IP_USART_001_T *pUART, IP_UART_INT_T UARTIntCfg, FunctionalState NewState);
\r
616 * @brief Get Source Interrupt
\r
617 * @param pUART : Pointer to selected UARTx peripheral
\r
618 * @return Return the value of IIR register
\r
620 uint32_t IP_UART_IntGetStatus(IP_USART_001_T *pUART);
\r
623 * @brief Force BREAK character on UART line, output pin UARTx TXD is forced to logic 0
\r
624 * @param pUART : Pointer to selected UARTx peripheral
\r
627 void IP_UART_ForceBreak(IP_USART_001_T *pUART);
\r
630 * @brief Get current value of Line Status register in UART peripheral.
\r
631 * @param pUART : Pointer to selected UARTx peripheral
\r
632 * @return Current value of Line Status register in UART peripheral
\r
634 * The return value of this function must be ANDed with each member in UART_LS_T
\r
635 * enumeration to determine current flag status corresponding to each Line status type. Because
\r
636 * some flags in Line Status register will be cleared after reading, the next reading Line
\r
637 * Status register could not be correct. So this function used to read Line status register
\r
638 * in one time only, then the return value used to check all flags.
\r
640 uint8_t IP_UART_GetLineStatus(IP_USART_001_T *pUART);
\r
643 * @brief Check whether if UART is busy or not
\r
644 * @param pUART : Pointer to selected UARTx peripheral
\r
645 * @return RESET if UART is not busy, otherwise return SET.
\r
647 FlagStatus IP_UART_CheckBusy(IP_USART_001_T *pUART);
\r
650 * @brief Enable/Disable transmission on UART TxD pin
\r
651 * @param pUART : Pointer to selected UARTx peripheral
\r
652 * @param UARTPort : UART ID type
\r
653 * @param NewState : New State of Tx transmission function, should be ENABLE or DISABLE
\r
656 void IP_UART_TxCmd(IP_USART_001_T *pUART, IP_UART_ID_T UARTPort, FunctionalState NewState);
\r
658 /* UART FIFO functions ----------------------------------------------------------*/
\r
660 * @brief Configure FIFO function on selected UART peripheral
\r
661 * @param pUART : Pointer to selected UARTx peripheral
\r
662 * @param FIFOCfg : Pointer to a UART_FIFO_CFG_T Structure that contains specified information about FIFO configuration
\r
665 void IP_UART_FIFOConfig(IP_USART_001_T *pUART, UART_FIFO_CFG_T *FIFOCfg);
\r
668 * @brief Fills each UART_FIFOInitStruct member with its default value:
\r
669 * - FIFO_DMAMode = DISABLE
\r
670 * - FIFO_Level = UART_FIFO_TRGLEV0
\r
671 * - FIFO_ResetRxBuf = ENABLE
\r
672 * - FIFO_ResetTxBuf = ENABLE
\r
673 * - FIFO_State = ENABLE
\r
674 * @param UART_FIFOInitStruct : Pointer to a UART_FIFO_CFG_T structure which will be initialized.
\r
677 void IP_UART_FIFOConfigStructInit(UART_FIFO_CFG_T *UART_FIFOInitStruct);
\r
680 * @brief Start/Stop Auto Baudrate activity
\r
681 * @param pUART : Pointer to selected UARTx peripheral
\r
682 * @param ABConfigStruct : A pointer to UART_AB_CFG_T structure that
\r
683 * contains specified information about UAR auto baud configuration
\r
684 * @param NewState : New State of Auto baudrate activity, should be ENABLE or DISABLE
\r
686 * @note Auto-baudrate mode enable bit will be cleared once this mode completed.
\r
688 void IP_UART_ABCmd(IP_USART_001_T *pUART, UART_AB_CFG_T *ABConfigStruct, FunctionalState NewState);
\r
691 * @brief Clear Autobaud Interrupt
\r
692 * @param pUART : Pointer to selected UARTx peripheral
\r
693 * @param ABIntType : type of auto-baud interrupt, should be:
\r
694 * - UART_AUTOBAUD_INTSTAT_ABEO: End of Auto-baud interrupt
\r
695 * - UART_AUTOBAUD_INTSTAT_ABTO: Auto-baud time out interrupt
\r
698 void IP_UART_ABClearIntPending(IP_USART_001_T *pUART, IP_UART_INT_STATUS_T ABIntType);
\r
708 #endif /* __USART_001_H_ */
\r