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_004_H_
\r
33 #define __USART_004_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_USART_004 IP: USART register block and driver (004)
\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
77 __IO uint32_t OSR; /*!< Oversampling Register. Controls the degree of oversampling during each bit time. Only on some UARTS. */
\r
78 __IO uint32_t TER1; /*!< Transmit Enable Register. Turns off USART transmitter for use with software flow control. */
\r
79 uint32_t RESERVED0[3];
\r
80 __IO uint32_t HDEN; /*!< Half-duplex enable Register- only on some UARTs */
\r
81 __I uint32_t RESERVED1[1];
\r
82 __IO uint32_t SCICTRL; /*!< Smart card interface control register- only on some UARTs */
\r
84 __IO uint32_t RS485CTRL; /*!< RS-485/EIA-485 Control. Contains controls to configure various aspects of RS-485/EIA-485 modes. */
\r
85 __IO uint32_t RS485ADRMATCH; /*!< RS-485/EIA-485 address match. Contains the address match value for RS-485/EIA-485 mode. */
\r
86 __IO uint32_t RS485DLY; /*!< RS-485/EIA-485 direction control delay. */
\r
89 __IO uint32_t SYNCCTRL; /*!< Synchronous mode control register. Only on USARTs. */
\r
90 __I uint32_t FIFOLVL; /*!< FIFO Level register. Provides the current fill levels of the transmit and receive FIFOs. */
\r
93 __IO uint32_t TER2; /*!< Transmit Enable Register. Only on LPC177X_8X UART4 and LPC18XX/43XX USART0/2/3. */
\r
96 #define UART_RBR_MASKBIT (0xFF) /*!< UART Received Buffer mask bit (8 bits) */
\r
99 * @brief Basic UART initialization
\r
100 * @param pUART : Pointer to selected UART peripheral
\r
102 * @note This function performs very basic UART initialization
\r
104 void IP_UART_Init(IP_USART_001_T *pUART);
\r
107 * @brief UART de-initialization
\r
108 * @param pUART : Pointer to selected UART peripheral
\r
111 STATIC INLINE void IP_UART_DeInit(IP_USART_001_T *pUART) {}
\r
114 * @brief Transmit a single byte through the UART peripheral
\r
115 * @param pUART : Pointer to selected UART peripheral
\r
116 * @param data : Byte to transmit
\r
118 * @note This function attempts to place a byte into the UART transmit
\r
119 * FIFO or transmit hold register regard regardless of UART state.
\r
121 STATIC INLINE void IP_UART_SendByte(IP_USART_001_T *pUART, const uint8_t data)
\r
123 pUART->THR = (uint32_t) data;
\r
127 * @brief Get a single data from UART peripheral
\r
128 * @param pUART : Pointer to selected UART peripheral
\r
129 * @return A single byte of data read
\r
130 * @note This function reads a byte from the UART receive FIFO or
\r
131 * receive hold register regard regardless of UART state.
\r
133 STATIC INLINE uint8_t IP_UART_ReadByte(IP_USART_001_T *pUART)
\r
135 return (uint8_t) (pUART->RBR & UART_RBR_MASKBIT);
\r
139 * @brief Macro defines for UART interrupt enable register
\r
141 #define UART_IER_RBRINT (1 << 0) /*!< RBR Interrupt enable*/
\r
142 #define UART_IER_THREINT (1 << 1) /*!< THR Interrupt enable*/
\r
143 #define UART_IER_RLSINT (1 << 2) /*!< RX line status interrupt enable*/
\r
144 #define UART_IER_MSINT (1 << 3) /*!< Modem status interrupt enable */
\r
145 #define UART_IER_CTSINT (1 << 7) /*!< CTS1 signal transition interrupt enable */
\r
146 #define UART_IER_ABEOINT (1 << 8) /*!< Enables the end of auto-baud interrupt */
\r
147 #define UART_IER_ABTOINT (1 << 9) /*!< Enables the auto-baud time-out interrupt */
\r
148 #define UART_IER_BITMASK (0x307) /*!< UART interrupt enable register bit mask */
\r
149 #define UART1_IER_BITMASK (0x38F) /*!< UART1 interrupt enable register bit mask */
\r
152 * @brief Enable UART interrupts
\r
153 * @param pUART : Pointer to selected UART peripheral
\r
154 * @param intMask : Or'ed Interrupts to enable in the Interrupt Enable Register (IER)
\r
156 * @note Use an Or'ed value of UART_IER_* definitions with this call
\r
157 * to enable specific UART interrupts. The Divisor Latch Access Bit
\r
158 * (DLAB) in LCR must be cleared in order to access the IER register.
\r
159 * This function doesn't alter the DLAB state.
\r
161 STATIC INLINE void IP_UART_IntEnable(IP_USART_001_T *pUART, uint32_t intMask)
\r
163 pUART->IER |= intMask;
\r
167 * @brief Disable UART interrupts
\r
168 * @param pUART : Pointer to selected UART peripheral
\r
169 * @param intMask : Or'ed Interrupts to disable in the Interrupt Enable Register (IER)
\r
171 * @note Use an Or'ed value of UART_IER_* definitions with this call
\r
172 * to disable specific UART interrupts. The Divisor Latch Access Bit
\r
173 * (DLAB) in LCR must be cleared in order to access the IER register.
\r
174 * This function doesn't alter the DLAB state.
\r
176 STATIC INLINE void IP_UART_IntDisable(IP_USART_001_T *pUART, uint32_t intMask)
\r
178 pUART->IER &= ~intMask;
\r
182 * @brief Macro defines for UART interrupt identification register
\r
184 #define UART_IIR_INTSTAT_PEND (1 << 0) /*!<Interrupt Status - Active low */
\r
185 #define UART_IIR_INTID_RLS (3 << 1) /*!<Interrupt identification: Receive line status*/
\r
186 #define UART_IIR_INTID_RDA (2 << 1) /*!<Interrupt identification: Receive data available*/
\r
187 #define UART_IIR_INTID_CTI (6 << 1) /*!<Interrupt identification: Character time-out indicator*/
\r
188 #define UART_IIR_INTID_THRE (1 << 1) /*!<Interrupt identification: THRE interrupt*/
\r
189 #define UART_IIR_INTID_MODEM (0 << 1) /*!<Interrupt identification: Modem interrupt*/
\r
190 #define UART_IIR_INTID_MASK (7 << 1) /*!<Interrupt identification: Interrupt ID mask */
\r
191 #define UART_IIR_FIFO_EN (3 << 6) /*!<These bits are equivalent to UnFCR[0] */
\r
192 #define UART_IIR_ABEO_INT (1 << 8) /*!< End of auto-baud interrupt */
\r
193 #define UART_IIR_ABTO_INT (1 << 9) /*!< Auto-baud time-out interrupt */
\r
194 #define UART_IIR_BITMASK (0x3CF) /*!< UART interrupt identification register bit mask */
\r
197 * @brief Read the Interrupt Identification Register (IIR)
\r
198 * @param pUART : Pointer to selected UART peripheral
\r
199 * @return Current pending interrupt status per the IIR register
\r
201 STATIC INLINE uint32_t IP_UART_ReadIntIDReg(IP_USART_001_T *pUART)
\r
207 * @brief Macro defines for UART FIFO control register
\r
209 #define UART_FCR_FIFO_EN (1 << 0) /*!< UART FIFO enable */
\r
210 #define UART_FCR_RX_RS (1 << 1) /*!< UART FIFO RX reset */
\r
211 #define UART_FCR_TX_RS (1 << 2) /*!< UART FIFO TX reset */
\r
212 #define UART_FCR_DMAMODE_SEL (1 << 3) /*!< UART DMA mode selection */
\r
213 #define UART_FCR_TRG_LEV0 (0) /*!< UART FIFO trigger level 0: 1 character */
\r
214 #define UART_FCR_TRG_LEV1 (1 << 6) /*!< UART FIFO trigger level 1: 4 character */
\r
215 #define UART_FCR_TRG_LEV2 (2 << 6) /*!< UART FIFO trigger level 2: 8 character */
\r
216 #define UART_FCR_TRG_LEV3 (3 << 6) /*!< UART FIFO trigger level 3: 14 character */
\r
217 #define UART_FCR_BITMASK (0xCF) /*!< UART FIFO control bit mask */
\r
218 #define UART_TX_FIFO_SIZE (16)
\r
221 * @brief Setup the UART FIFOs
\r
222 * @param pUART : Pointer to selected UART peripheral
\r
223 * @param fcr : FIFO control register setup OR'ed flags
\r
225 * @note Use an Or'ed value of UART_FCR_* definitions with this call
\r
226 * to select specific options.
\r
228 STATIC INLINE void IP_UART_SetupFIFOS(IP_USART_001_T *pUART, uint32_t fcr)
\r
234 * @brief Macro defines for UART line control register
\r
236 #define UART_LCR_WLEN5 (0) /*!< UART 5 bit data mode */
\r
237 #define UART_LCR_WLEN6 (1 << 0) /*!< UART 6 bit data mode */
\r
238 #define UART_LCR_WLEN7 (2 << 0) /*!< UART 7 bit data mode */
\r
239 #define UART_LCR_WLEN8 (3 << 0) /*!< UART 8 bit data mode */
\r
240 #define UART_LCR_SBS_1BIT (0 << 2) /*!< UART One Stop Bit Select */
\r
241 #define UART_LCR_SBS_2BIT (1 << 2) /*!< UART Two Stop Bits Select */
\r
242 #define UART_LCR_PARITY_EN (1 << 3) /*!< UART Parity Enable */
\r
243 #define UART_LCR_PARITY_DIS (0 << 3) /*!< UART Parity Disable */
\r
244 #define UART_LCR_PARITY_ODD (0) /*!< UART Odd Parity Select */
\r
245 #define UART_LCR_PARITY_EVEN (1 << 4) /*!< UART Even Parity Select */
\r
246 #define UART_LCR_PARITY_F_1 (2 << 4) /*!< UART force 1 stick parity */
\r
247 #define UART_LCR_PARITY_F_0 (3 << 4) /*!< UART force 0 stick parity */
\r
248 #define UART_LCR_BREAK_EN (1 << 6) /*!< UART Transmission Break enable */
\r
249 #define UART_LCR_DLAB_EN (1 << 7) /*!< UART Divisor Latches Access bit enable */
\r
250 #define UART_LCR_BITMASK (0xFF) /*!< UART line control bit mask */
\r
253 * @brief Setup the UART operation mode in the Line Control Register (LCR)
\r
254 * @param pUART : Pointer to selected UART peripheral
\r
255 * @param lcr : OR'ed flags
\r
257 * @note Sets up the UART transmit mode (data bits, stop bits, parity,
\r
258 * and break). Use an Or'ed value of UART_LCR_* definitions with this
\r
259 * call to select specific options. Unless the UART_LCR_DLAB_EN
\r
260 * option is passed in lcd, DLAB will be cleared and divisor access
\r
261 * will be disabled.
\r
263 STATIC INLINE void IP_UART_SetMode(IP_USART_001_T *pUART, uint32_t lcr)
\r
269 * @brief Enable access to Divisor Latches
\r
270 * @param pUART : Pointer to selected UART peripheral
\r
273 STATIC INLINE void IP_UART_EnableDivisorAccess(IP_USART_001_T *pUART)
\r
275 pUART->LCR |= UART_LCR_DLAB_EN;
\r
279 * @brief Disable access to Divisor Latches
\r
280 * @param pUART : Pointer to selected UART peripheral
\r
283 STATIC INLINE void IP_UART_DisableDivisorAccess(IP_USART_001_T *pUART)
\r
285 pUART->LCR &= ~UART_LCR_DLAB_EN;
\r
288 #define UART_DLL_MASKBIT (0xFF) /*!< Divisor latch LSB (DLL) bit mask */
\r
289 #define UART_DLM_MASKBIT (0xFF) /*!< Divisor latch MSB (DLM) bit mask */
\r
292 * @brief Set LSB and MSB divisor latch registers
\r
293 * @param pUART : Pointer to selected UART peripheral
\r
294 * @param dll : Divisor Latch LSB value
\r
295 * @param dlm : Divisor Latch MSB value
\r
297 * @note The Divisor Latch Access Bit (DLAB) in LCR must be set in
\r
298 * order to access the USART Divisor Latches. This function
\r
299 * doesn't alter the DLAB state.
\r
301 STATIC INLINE void IP_UART_SetDivisorLatches(IP_USART_001_T *pUART, uint8_t dll, uint8_t dlm)
\r
303 pUART->DLL = (uint32_t) dll;
\r
304 pUART->DLM = (uint32_t) dlm;
\r
308 * @brief Macro defines for UART Modem control register
\r
310 #define UART_MCR_DTR_CTRL (1 << 0) /*!< Source for modem output pin DTR */
\r
311 #define UART_MCR_RTS_CTRL (1 << 1) /*!< Source for modem output pin RTS */
\r
312 #define UART_MCR_LOOPB_EN (1 << 4) /*!< Loop back mode select */
\r
313 #define UART_MCR_AUTO_RTS_EN (1 << 6) /*!< Enable Auto RTS flow-control */
\r
314 #define UART_MCR_AUTO_CTS_EN (1 << 7) /*!< Enable Auto CTS flow-control */
\r
315 #define UART_MCR_BITMASK (0x0F3) /*!< UART1 bit mask value */
\r
318 * @brief Return modem control register/status
\r
319 * @param pUART : Pointer to selected UART peripheral
\r
320 * @return Modem control register (status)
\r
321 * @note Mask bits of the returned status value with UART_MCR_*
\r
322 * definitions for specific statuses.
\r
324 STATIC INLINE uint32_t IP_UART_ReadModemControl(IP_USART_001_T *pUART)
\r
330 * @brief Set modem control register/status
\r
331 * @param pUART : Pointer to selected UART peripheral
\r
332 * @param mcr : Modem control register flags to set
\r
334 * @note Use an Or'ed value of UART_MCR_* definitions with this
\r
335 * call to set specific options.
\r
337 STATIC INLINE void IP_UART_SetModemControl(IP_USART_001_T *pUART, uint32_t mcr)
\r
343 * @brief Clear modem control register/status
\r
344 * @param pUART : Pointer to selected UART peripheral
\r
345 * @param mcr : Modem control register flags to clear
\r
347 * @note Use an Or'ed value of UART_MCR_* definitions with this
\r
348 * call to clear specific options.
\r
350 STATIC INLINE void IP_UART_ClearModemControl(IP_USART_001_T *pUART, uint32_t mcr)
\r
352 pUART->MCR &= ~mcr;
\r
356 * @brief Macro defines for UART line status register
\r
358 #define UART_LSR_RDR (1 << 0) /*!< Line status register: Receive data ready */
\r
359 #define UART_LSR_OE (1 << 1) /*!< Line status register: Overrun error */
\r
360 #define UART_LSR_PE (1 << 2) /*!< Line status register: Parity error */
\r
361 #define UART_LSR_FE (1 << 3) /*!< Line status register: Framing error */
\r
362 #define UART_LSR_BI (1 << 4) /*!< Line status register: Break interrupt */
\r
363 #define UART_LSR_THRE (1 << 5) /*!< Line status register: Transmit holding register empty */
\r
364 #define UART_LSR_TEMT (1 << 6) /*!< Line status register: Transmitter empty */
\r
365 #define UART_LSR_RXFE (1 << 7) /*!< Error in RX FIFO */
\r
366 #define UART_LSR_BITMASK (0xFF) /*!< UART Line status bit mask */
\r
369 * @brief Return Line Status register/status (LSR)
\r
370 * @param pUART : Pointer to selected UART peripheral
\r
371 * @return Line Status register (status)
\r
372 * @note Mask bits of the returned status value with UART_LSR_*
\r
373 * definitions for specific statuses.
\r
375 STATIC INLINE uint32_t IP_UART_ReadLineStatus(IP_USART_001_T *pUART)
\r
381 * @brief Macro defines for UART Modem status register
\r
383 #define UART_MSR_DELTA_CTS (1 << 0) /*!< Set upon state change of input CTS */
\r
384 #define UART_MSR_DELTA_DSR (1 << 1) /*!< Set upon state change of input DSR */
\r
385 #define UART_MSR_LO2HI_RI (1 << 2) /*!< Set upon low to high transition of input RI */
\r
386 #define UART_MSR_DELTA_DCD (1 << 3) /*!< Set upon state change of input DCD */
\r
387 #define UART_MSR_CTS (1 << 4) /*!< Clear To Send State */
\r
388 #define UART_MSR_DSR (1 << 5) /*!< Data Set Ready State */
\r
389 #define UART_MSR_RI (1 << 6) /*!< Ring Indicator State */
\r
390 #define UART_MSR_DCD (1 << 7) /*!< Data Carrier Detect State */
\r
391 #define UART_MSR_BITMASK (0xFF) /*!< MSR register bit-mask value */
\r
394 * @brief Return Modem Status register/status (MSR)
\r
395 * @param pUART : Pointer to selected UART peripheral
\r
396 * @return Modem Status register (status)
\r
397 * @note Mask bits of the returned status value with UART_MSR_*
\r
398 * definitions for specific statuses.
\r
400 STATIC INLINE uint32_t IP_UART_ReadModemStatus(IP_USART_001_T *pUART)
\r
406 * @brief Write a byte to the scratchpad register
\r
407 * @param pUART : Pointer to selected UART peripheral
\r
408 * @param data : Byte value to write
\r
411 STATIC INLINE void IP_UART_SetScratch(IP_USART_001_T *pUART, uint8_t data)
\r
413 pUART->SCR = (uint32_t) data;
\r
417 * @brief Returns current byte value in the scratchpad register
\r
418 * @param pUART : Pointer to selected UART peripheral
\r
419 * @return Byte value read from scratchpad register
\r
421 STATIC INLINE uint8_t IP_UART_ReadScratch(IP_USART_001_T *pUART)
\r
423 return (uint8_t) (pUART->SCR & 0xFF);
\r
427 * @brief Macro defines for UART Auto baudrate control register
\r
429 #define UART_ACR_START (1 << 0) /*!< UART Auto-baud start */
\r
430 #define UART_ACR_MODE (1 << 1) /*!< UART Auto baudrate Mode 1 */
\r
431 #define UART_ACR_AUTO_RESTART (1 << 2) /*!< UART Auto baudrate restart */
\r
432 #define UART_ACR_ABEOINT_CLR (1 << 8) /*!< UART End of auto-baud interrupt clear */
\r
433 #define UART_ACR_ABTOINT_CLR (1 << 9) /*!< UART Auto-baud time-out interrupt clear */
\r
434 #define UART_ACR_BITMASK (0x307) /*!< UART Auto Baudrate register bit mask */
\r
437 * @brief Set autobaud register options
\r
438 * @param pUART : Pointer to selected UART peripheral
\r
439 * @param acr : Or'ed values to set for ACR register
\r
441 * @note Use an Or'ed value of UART_ACR_* definitions with this
\r
442 * call to set specific options.
\r
444 STATIC INLINE void IP_UART_SetAutoBaudReg(IP_USART_001_T *pUART, uint32_t acr)
\r
450 * @brief Clear autobaud register options
\r
451 * @param pUART : Pointer to selected UART peripheral
\r
452 * @param acr : Or'ed values to clear for ACR register
\r
454 * @note Use an Or'ed value of UART_ACR_* definitions with this
\r
455 * call to clear specific options.
\r
457 STATIC INLINE void IP_UART_ClearAutoBaudReg(IP_USART_001_T *pUART, uint32_t acr)
\r
459 pUART->ACR &= ~acr;
\r
463 * @brief Enable transmission on UART TxD pin
\r
464 * @param pUART : Pointer to selected UART peripheral
\r
467 STATIC INLINE void IP_UART_TXEnable(IP_USART_001_T *pUART)
\r
469 pUART->TER1 = (1 << 7);
\r
473 * @brief Disable transmission on UART TxD pin
\r
474 * @param pUART : Pointer to selected UART peripheral
\r
477 STATIC INLINE void IP_UART_TXDisable(IP_USART_001_T *pUART)
\r
483 * @brief Macro defines for UART1 RS485 Control register
\r
485 #define UART_RS485CTRL_NMM_EN (1 << 0) /*!< RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */
\r
486 #define UART_RS485CTRL_RX_DIS (1 << 1) /*!< The receiver is disabled */
\r
487 #define UART_RS485CTRL_AADEN (1 << 2) /*!< Auto Address Detect (AAD) is enabled */
\r
488 #define UART_RS485CTRL_SEL_DTR (1 << 3) /*!< If direction control is enabled (bit DCTRL = 1), pin DTR is
\r
489 used for direction control */
\r
490 #define UART_RS485CTRL_DCTRL_EN (1 << 4) /*!< Enable Auto Direction Control */
\r
491 #define UART_RS485CTRL_OINV_1 (1 << 5) /*!< This bit reverses the polarity of the direction
\r
492 control signal on the RTS (or DTR) pin. The direction control pin
\r
493 will be driven to logic "1" when the transmitter has data to be sent */
\r
494 #define UART_RS485CTRL_BITMASK (0x3F) /*!< RS485 control bit-mask value */
\r
497 * @brief Set RS485 control register options
\r
498 * @param pUART : Pointer to selected UART peripheral
\r
499 * @param ctrl : Or'ed values to set for RS485 control register
\r
501 * @note Use an Or'ed value of UART_RS485CTRL_* definitions with this
\r
502 * call to set specific options.
\r
504 STATIC INLINE void IP_UART_SetRS485Flags(IP_USART_001_T *pUART, uint32_t ctrl)
\r
506 pUART->RS485CTRL |= ctrl;
\r
510 * @brief Clear RS485 control register options
\r
511 * @param pUART : Pointer to selected UART peripheral
\r
512 * @param ctrl : Or'ed values to clear for RS485 control register
\r
514 * @note Use an Or'ed value of UART_RS485CTRL_* definitions with this
\r
515 * call to clear specific options.
\r
517 STATIC INLINE void IP_UART_ClearRS485Flags(IP_USART_001_T *pUART, uint32_t ctrl)
\r
519 pUART->RS485CTRL &= ~ctrl;
\r
523 * @brief Set RS485 address match value
\r
524 * @param pUART : Pointer to selected UART peripheral
\r
525 * @param addr : Address match value for RS-485/EIA-485 mode
\r
528 STATIC INLINE void IP_UART_SetRS485Addr(IP_USART_001_T *pUART, uint8_t addr)
\r
530 pUART->RS485ADRMATCH = (uint32_t) addr;
\r
534 * @brief Read RS485 address match value
\r
535 * @param pUART : Pointer to selected UART peripheral
\r
536 * @return Address match value for RS-485/EIA-485 mode
\r
538 STATIC INLINE uint8_t IP_UART_GetRS485Addr(IP_USART_001_T *pUART)
\r
540 return (uint8_t) (pUART->RS485ADRMATCH & 0xFF);
\r
544 * @brief Set RS485 direction control (RTS or DTR) delay value
\r
545 * @param pUART : Pointer to selected UART peripheral
\r
546 * @param dly : direction control (RTS or DTR) delay value
\r
548 * @note This delay time is in periods of the baud clock. Any delay
\r
549 * time from 0 to 255 bit times may be programmed.
\r
551 STATIC INLINE void IP_UART_SetRS485Delay(IP_USART_001_T *pUART, uint8_t dly)
\r
553 pUART->RS485DLY = (uint32_t) dly;
\r
557 * @brief Read RS485 direction control (RTS or DTR) delay value
\r
558 * @param pUART : Pointer to selected UART peripheral
\r
559 * @return direction control (RTS or DTR) delay value
\r
560 * @note This delay time is in periods of the baud clock. Any delay
\r
561 * time from 0 to 255 bit times may be programmed.
\r
563 STATIC INLINE uint8_t IP_UART_GetRS485Delay(IP_USART_001_T *pUART)
\r
565 return (uint8_t) (pUART->RS485DLY & 0xFF);
\r
569 * @brief Determines and sets best dividers to get a target bit rate
\r
570 * @param pUART : Pointer to selected UART peripheral
\r
571 * @param baudrate : Target baud rate (baud rate = bit rate)
\r
572 * @param uClk : Clock rate into UART peripheral
\r
573 * @return The actual baud rate, or 0 if no rate can be found
\r
574 * @note Once you've computed your baud rate, you can remove this function
\r
575 * to make your image smaller.
\r
577 uint32_t IP_UART_SetBaud(IP_USART_001_T *pUART, uint32_t baudrate, uint32_t uClk);
\r
581 // FDR handled at chip layer
\r
584 // HDEN handled at chip layer
\r
585 // SCICTRL handled at chip layer
\r
586 // TER2 handled at chip layer
\r
589 * @brief Macro defines for UART IrDA control register
\r
591 #define UART_ICR_IRDAEN ((uint32_t) (1 << 0)) /*!< IrDA mode enable */
\r
592 #define UART_ICR_IRDAINV ((uint32_t) (1 << 1)) /*!< IrDA serial input inverted */
\r
593 #define UART_ICR_FIXPULSE_EN ((uint32_t) (1 << 2)) /*!< IrDA fixed pulse width mode */
\r
594 #define UART_ICR_PULSEDIV(n) ((uint32_t) ((n & 0x07) << 3)) /*!< PulseDiv - Configures the pulse when FixPulseEn = 1 */
\r
595 #define UART_ICR_BITMASK ((uint32_t) (0x3F)) /*!< UART IRDA bit mask */
\r
598 * @brief Macro defines for UART half duplex register
\r
600 #define UART_HDEN_HDEN ((uint32_t) (1 << 0)) /*!< enable half-duplex mode*/
\r
603 * @brief Macro defines for UART smart card interface control register
\r
605 #define UART_SCICTRL_SCIEN ((uint32_t) (1 << 0)) /*!< enable asynchronous half-duplex smart card interface*/
\r
606 #define UART_SCICTRL_NACKDIS ((uint32_t) (1 << 1)) /*!< NACK response is inhibited*/
\r
607 #define UART_SCICTRL_PROTSEL_T1 ((uint32_t) (1 << 2)) /*!< ISO7816-3 protocol T1 is selected*/
\r
608 #define UART_SCICTRL_TXRETRY(n) ((uint32_t) ((n & 0x07) << 5)) /*!< number of retransmission*/
\r
609 #define UART_SCICTRL_GUARDTIME(n) ((uint32_t) ((n & 0xFF) << 8)) /*!< Extra guard time*/
\r
612 * @brief Macro defines for UART Fractional divider register
\r
614 #define UART_FDR_DIVADDVAL(n) ((uint32_t) (n & 0x0F)) /*!< Baud-rate generation pre-scaler divisor */
\r
615 #define UART_FDR_MULVAL(n) ((uint32_t) ((n << 4) & 0xF0)) /*!< Baud-rate pre-scaler multiplier value */
\r
616 #define UART_FDR_BITMASK ((uint32_t) (0xFF)) /*!< UART Fractional Divider register bit mask */
\r
619 * @brief Macro defines for UART Tx Enable register
\r
621 #define UART_TER1_TXEN ((uint8_t) (1 << 7)) /*!< Transmit enable bit */
\r
622 #define UART_TER1_BITMASK ((uint8_t) (0x80)) /*!< UART Transmit Enable Register bit mask */
\r
623 #define UART_TER2_TXEN ((uint8_t) (1 << 0)) /*!< Transmit enable bit */
\r
624 #define UART_TER2_BITMASK ((uint8_t) (0x01)) /*!< UART Transmit Enable Register bit mask */
\r
627 * @brief Macro defines for UART synchronous control register
\r
629 #define UART_SYNCCTRL_SYNC ((uint32_t) (1 << 0)) /*!< enable synchronous mode*/
\r
630 #define UART_SYNCCTRL_CSRC_MASTER ((uint32_t) (1 << 1)) /*!< synchronous master mode*/
\r
631 #define UART_SYNCCTRL_FES ((uint32_t) (1 << 2)) /*!< sample on falling edge*/
\r
632 #define UART_SYNCCTRL_TSBYPASS ((uint32_t) (1 << 3)) /*!< to be defined*/
\r
633 #define UART_SYNCCTRL_CSCEN ((uint32_t) (1 << 4)) /*!< continuous running clock enable (master mode only)*/
\r
634 #define UART_SYNCCTRL_STARTSTOPDISABLE ((uint32_t) (1 << 5)) /*!< do not send start/stop bit*/
\r
635 #define UART_SYNCCTRL_CCCLR ((uint32_t) (1 << 6)) /*!< stop continuous clock*/
\r
647 #endif /* __USART_004_H_ */
\r