/********************************************************************** * $Id$ lpc_uart.h 2011-06-02 *//** * @file lpc_uart.h * @brief Contains all macro definitions and function prototypes * support for UART firmware library on LPC * @version 1.0 * @date 02. June. 2011 * @author NXP MCU SW Application Team * * Copyright(C) 2011, NXP Semiconductor * All rights reserved. * *********************************************************************** * Software that is described herein is for illustrative purposes only * which provides customers with programming information regarding the * products. This software is supplied "AS IS" without any warranties. * NXP Semiconductors assumes no responsibility or liability for the * use of the software, conveys no license or title under any patent, * copyright, or mask work right to the product. NXP Semiconductors * reserves the right to make changes in the software without * notification. NXP Semiconductors also make no representation or * warranty that such application will be suitable for the specified * use without further testing or modification. * Permission to use, copy, modify, and distribute this software and its * documentation is hereby granted, under NXP Semiconductors' * relevant copyright in the software, without fee, provided that it * is used in conjunction with NXP Semiconductors microcontrollers. This * copyright, permission, and disclaimer notice must appear in all copies of * this code. **********************************************************************/ /* Peripheral group ----------------------------------------------------------- */ /** @defgroup UART UART (Universal Asynchronous Receiver/Transmitter) * @ingroup LPC_CMSIS_FwLib_Drivers * @{ */ #ifndef __LPC_UART_H_ #define __LPC_UART_H_ /* Includes ------------------------------------------------------------------- */ #include "LPC407x_8x_177x_8x.h" #include "lpc_types.h" #ifdef __cplusplus extern "C" { #endif /* Public Macros -------------------------------------------------------------- */ /** @defgroup UART_Public_Macros UART Public Macros * @{ */ /** UART time-out definitions in case of using Read() and Write function * with Blocking Flag mode */ #define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL) /** * @} */ /* Private Macros ------------------------------------------------------------- */ /** @defgroup UART_Private_Macros UART Private Macros * @{ */ /* Accepted Error baud rate value (in percent unit) */ #define UART_ACCEPTED_BAUDRATE_ERROR (3) /*!< Acceptable UART baudrate error */ /* --------------------- BIT DEFINITIONS -------------------------------------- */ /*********************************************************************//** * Macro defines for Macro defines for UARTn Receiver Buffer Register **********************************************************************/ /** UART Received Buffer mask bit (8 bits) */ #define UART_RBR_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Transmit Holding Register **********************************************************************/ /** UART Transmit Holding mask bit (8 bits) */ #define UART_THR_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Divisor Latch LSB register **********************************************************************/ /** Macro for loading least significant halfs of divisors */ #define UART_LOAD_DLL(div) ((div) & 0xFF) /** Divisor latch LSB bit mask */ #define UART_DLL_MASKBIT ((uint8_t)0xFF) /*********************************************************************//** * Macro defines for Macro defines for UARTn Divisor Latch MSB register **********************************************************************/ /** Divisor latch MSB bit mask */ #define UART_DLM_MASKBIT ((uint8_t)0xFF) /** Macro for loading most significant halfs of divisors */ #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF) /*********************************************************************//** * Macro defines for Macro defines for UART interrupt enable register **********************************************************************/ /** RBR Interrupt enable*/ #define UART_IER_RBRINT_EN ((uint32_t)(1<<0)) /** THR Interrupt enable*/ #define UART_IER_THREINT_EN ((uint32_t)(1<<1)) /** RX line status interrupt enable*/ #define UART_IER_RLSINT_EN ((uint32_t)(1<<2)) /** Modem status interrupt enable */ #define UART1_IER_MSINT_EN ((uint32_t)(1<<3)) /** CTS1 signal transition interrupt enable */ #define UART1_IER_CTSINT_EN ((uint32_t)(1<<7)) /** Enables the end of auto-baud interrupt */ #define UART_IER_ABEOINT_EN ((uint32_t)(1<<8)) /** Enables the auto-baud time-out interrupt */ #define UART_IER_ABTOINT_EN ((uint32_t)(1<<9)) /** UART interrupt enable register bit mask */ #define UART_IER_BITMASK ((uint32_t)(0x307)) /** UART1 interrupt enable register bit mask */ #define UART1_IER_BITMASK ((uint32_t)(0x38F)) /*********************************************************************//** * Macro defines for Macro defines for UART interrupt identification register **********************************************************************/ /** Interrupt Status - Active low */ #define UART_IIR_INTSTAT_PEND ((uint32_t)(1<<0)) /** Interrupt identification: Receive line status*/ #define UART_IIR_INTID_RLS ((uint32_t)(3<<1)) /** Interrupt identification: Receive data available*/ #define UART_IIR_INTID_RDA ((uint32_t)(2<<1)) /** Interrupt identification: Character time-out indicator*/ #define UART_IIR_INTID_CTI ((uint32_t)(6<<1)) /** Interrupt identification: THRE interrupt*/ #define UART_IIR_INTID_THRE ((uint32_t)(1<<1)) /** Interrupt identification: Modem interrupt*/ #define UART1_IIR_INTID_MODEM ((uint32_t)(0<<1)) /** Interrupt identification: Interrupt ID mask */ #define UART_IIR_INTID_MASK ((uint32_t)(7<<1)) /** These bits are equivalent to UnFCR[0] */ #define UART_IIR_FIFO_EN ((uint32_t)(3<<6)) /** End of auto-baud interrupt */ #define UART_IIR_ABEO_INT ((uint32_t)(1<<8)) /** Auto-baud time-out interrupt */ #define UART_IIR_ABTO_INT ((uint32_t)(1<<9)) /** UART interrupt identification register bit mask */ #define UART_IIR_BITMASK ((uint32_t)(0x3CF)) /*********************************************************************//** * Macro defines for Macro defines for UART FIFO control register **********************************************************************/ /** UART FIFO enable */ #define UART_FCR_FIFO_EN ((uint8_t)(1<<0)) /** UART FIFO RX reset */ #define UART_FCR_RX_RS ((uint8_t)(1<<1)) /** UART FIFO TX reset */ #define UART_FCR_TX_RS ((uint8_t)(1<<2)) /** UART DMA mode selection */ #define UART_FCR_DMAMODE_SEL ((uint8_t)(1<<3)) /** UART FIFO trigger level 0: 1 character */ #define UART_FCR_TRG_LEV0 ((uint8_t)(0)) /** UART FIFO trigger level 1: 4 character */ #define UART_FCR_TRG_LEV1 ((uint8_t)(1<<6)) /** UART FIFO trigger level 2: 8 character */ #define UART_FCR_TRG_LEV2 ((uint8_t)(2<<6)) /** UART FIFO trigger level 3: 14 character */ #define UART_FCR_TRG_LEV3 ((uint8_t)(3<<6)) /** UART FIFO control bit mask */ #define UART_FCR_BITMASK ((uint8_t)(0xCF)) #define UART_TX_FIFO_SIZE (16) /*********************************************************************//** * Macro defines for Macro defines for UART line control register **********************************************************************/ /** UART 5 bit data mode */ #define UART_LCR_WLEN5 ((uint8_t)(0)) /** UART 6 bit data mode */ #define UART_LCR_WLEN6 ((uint8_t)(1<<0)) /** UART 7 bit data mode */ #define UART_LCR_WLEN7 ((uint8_t)(2<<0)) /** UART 8 bit data mode */ #define UART_LCR_WLEN8 ((uint8_t)(3<<0)) /** UART Two Stop Bits Select */ #define UART_LCR_STOPBIT_SEL ((uint8_t)(1<<2)) /** UART Parity Enable */ #define UART_LCR_PARITY_EN ((uint8_t)(1<<3)) /** UART Odd Parity Select */ #define UART_LCR_PARITY_ODD ((uint8_t)(0)) /** UART Even Parity Select */ #define UART_LCR_PARITY_EVEN ((uint8_t)(1<<4)) /** UART force 1 stick parity */ #define UART_LCR_PARITY_F_1 ((uint8_t)(2<<4)) /** UART force 0 stick parity */ #define UART_LCR_PARITY_F_0 ((uint8_t)(3<<4)) /** UART Transmission Break enable */ #define UART_LCR_BREAK_EN ((uint8_t)(1<<6)) /** UART Divisor Latches Access bit enable */ #define UART_LCR_DLAB_EN ((uint8_t)(1<<7)) /** UART line control bit mask */ #define UART_LCR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART1 Modem Control Register **********************************************************************/ /** Source for modem output pin DTR */ #define UART1_MCR_DTR_CTRL ((uint8_t)(1<<0)) /** Source for modem output pin RTS */ #define UART1_MCR_RTS_CTRL ((uint8_t)(1<<1)) /** Loop back mode select */ #define UART1_MCR_LOOPB_EN ((uint8_t)(1<<4)) /** Enable Auto RTS flow-control */ #define UART1_MCR_AUTO_RTS_EN ((uint8_t)(1<<6)) /** Enable Auto CTS flow-control */ #define UART1_MCR_AUTO_CTS_EN ((uint8_t)(1<<7)) /** UART1 bit mask value */ #define UART1_MCR_BITMASK ((uint8_t)(0x0F3)) /*********************************************************************//** * Macro defines for Macro defines for UART line status register **********************************************************************/ /** Line status register: Receive data ready*/ #define UART_LSR_RDR ((uint8_t)(1<<0)) /** Line status register: Overrun error*/ #define UART_LSR_OE ((uint8_t)(1<<1)) /** Line status register: Parity error*/ #define UART_LSR_PE ((uint8_t)(1<<2)) /** Line status register: Framing error*/ #define UART_LSR_FE ((uint8_t)(1<<3)) /** Line status register: Break interrupt*/ #define UART_LSR_BI ((uint8_t)(1<<4)) /** Line status register: Transmit holding register empty*/ #define UART_LSR_THRE ((uint8_t)(1<<5)) /** Line status register: Transmitter empty*/ #define UART_LSR_TEMT ((uint8_t)(1<<6)) /** Error in RX FIFO*/ #define UART_LSR_RXFE ((uint8_t)(1<<7)) /** UART Line status bit mask */ #define UART_LSR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Modem (UART1 only) status register **********************************************************************/ /** Set upon state change of input CTS */ #define UART1_MSR_DELTA_CTS ((uint8_t)(1<<0)) /** Set upon state change of input DSR */ #define UART1_MSR_DELTA_DSR ((uint8_t)(1<<1)) /** Set upon low to high transition of input RI */ #define UART1_MSR_LO2HI_RI ((uint8_t)(1<<2)) /** Set upon state change of input DCD */ #define UART1_MSR_DELTA_DCD ((uint8_t)(1<<3)) /** Clear To Send State */ #define UART1_MSR_CTS ((uint8_t)(1<<4)) /** Data Set Ready State */ #define UART1_MSR_DSR ((uint8_t)(1<<5)) /** Ring Indicator State */ #define UART1_MSR_RI ((uint8_t)(1<<6)) /** Data Carrier Detect State */ #define UART1_MSR_DCD ((uint8_t)(1<<7)) /** MSR register bit-mask value */ #define UART1_MSR_BITMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Scratch Pad Register **********************************************************************/ /** UART Scratch Pad bit mask */ #define UART_SCR_BIMASK ((uint8_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Auto baudrate control register **********************************************************************/ /** UART Auto-baud start */ #define UART_ACR_START ((uint32_t)(1<<0)) /** UART Auto baudrate Mode 1 */ #define UART_ACR_MODE ((uint32_t)(1<<1)) /** UART Auto baudrate restart */ #define UART_ACR_AUTO_RESTART ((uint32_t)(1<<2)) /** UART End of auto-baud interrupt clear */ #define UART_ACR_ABEOINT_CLR ((uint32_t)(1<<8)) /** UART Auto-baud time-out interrupt clear */ #define UART_ACR_ABTOINT_CLR ((uint32_t)(1<<9)) /** UART Auto Baudrate register bit mask */ #define UART_ACR_BITMASK ((uint32_t)(0x307)) /*********************************************************************//** * Macro defines for Macro defines for UART IrDA control register **********************************************************************/ /** IrDA mode enable */ #define UART_ICR_IRDAEN ((uint32_t)(1<<0)) /** IrDA serial input inverted */ #define UART_ICR_IRDAINV ((uint32_t)(1<<1)) /** IrDA fixed pulse width mode */ #define UART_ICR_FIXPULSE_EN ((uint32_t)(1<<2)) /** PulseDiv - Configures the pulse when FixPulseEn = 1 */ #define UART_ICR_PULSEDIV(n) ((uint32_t)((n&0x07)<<3)) /** UART IRDA bit mask */ #define UART_ICR_BITMASK ((uint32_t)(0x3F)) /*********************************************************************//** * Macro defines for Macro defines for UART Fractional divider register **********************************************************************/ /** Baud-rate generation pre-scaler divisor */ #define UART_FDR_DIVADDVAL(n) ((uint32_t)(n&0x0F)) /** Baud-rate pre-scaler multiplier value */ #define UART_FDR_MULVAL(n) ((uint32_t)((n<<4)&0xF0)) /** UART Fractional Divider register bit mask */ #define UART_FDR_BITMASK ((uint32_t)(0xFF)) /*********************************************************************//** * Macro defines for Macro defines for UART Tx Enable register **********************************************************************/ /** Transmit enable bit */ #define UART_TER_TXEN ((uint8_t)(1<<7)) /** UART Transmit Enable Register bit mask */ #define UART_TER_BITMASK ((uint8_t)(0x80)) /** Transmit enable bit on UART4 */ #define UART4_TER_TXEN ((uint8_t)(1<<0)) /** UART4 Transmit Enable Register bit mask */ #define UART4_TER_BITMASK ((uint8_t)(0x01)) /*********************************************************************//** * Macro defines for Macro defines for UART RS485 Control register **********************************************************************/ /** RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */ #define UART_RS485CTRL_NMM_EN ((uint32_t)(1<<0)) /** The receiver is disabled */ #define UART_RS485CTRL_RX_DIS ((uint32_t)(1<<1)) /** Auto Address Detect (AAD) is enabled */ #define UART_RS485CTRL_AADEN ((uint32_t)(1<<2)) /** If direction control is enabled (bit DCTRL = 1), pin DTR is used for direction control */ #define UART_RS485CTRL_SEL_DTR ((uint32_t)(1<<3)) /** Enable Auto Direction Control */ #define UART_RS485CTRL_DCTRL_EN ((uint32_t)(1<<4)) /** This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin. The direction control pin will be driven to logic "1" when the transmitter has data to be sent */ #define UART_RS485CTRL_OINV_1 ((uint32_t)(1<<5)) /** RS485 control bit-mask value */ #define UART_RS485CTRL_BITMASK ((uint32_t)(0x3F)) /*********************************************************************//** * Macro defines for Macro defines for UART RS-485 Address Match register **********************************************************************/ #define UART_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF)) /**< Bit mask value */ /*********************************************************************//** * Macro defines for Macro defines for UART1 RS-485 Delay value register **********************************************************************/ /* Macro defines for UART1 RS-485 Delay value register */ #define UART_RS485DLY_BITMASK ((uint8_t)(0xFF)) /** Bit mask value */ /** * @} */ /* Public Types --------------------------------------------------------------- */ /** @defgroup UART_Public_Types UART Public Types * @{ */ /** * @brief UART ID */ typedef enum { UART_0 = 0, UART_1, UART_2, UART_3, UART_4, } UART_ID_Type; /** * @brief UART Databit type definitions */ typedef enum { UART_DATABIT_5 = 0, /*!< UART 5 bit data mode */ UART_DATABIT_6, /*!< UART 6 bit data mode */ UART_DATABIT_7, /*!< UART 7 bit data mode */ UART_DATABIT_8 /*!< UART 8 bit data mode */ } UART_DATABIT_Type; /** * @brief UART Stop bit type definitions */ typedef enum { UART_STOPBIT_1 = (0), /*!< UART 1 Stop Bits Select */ UART_STOPBIT_2, /*!< UART Two Stop Bits Select */ } UART_STOPBIT_Type; /** * @brief UART Parity type definitions */ typedef enum { UART_PARITY_NONE = 0, /*!< No parity */ UART_PARITY_ODD, /*!< Odd parity */ UART_PARITY_EVEN, /*!< Even parity */ UART_PARITY_SP_1, /*!< Forced "1" stick parity */ UART_PARITY_SP_0 /*!< Forced "0" stick parity */ } UART_PARITY_Type; /** * @brief FIFO Level type definitions */ typedef enum { UART_FIFO_TRGLEV0 = 0, /*!< UART FIFO trigger level 0: 1 character */ UART_FIFO_TRGLEV1, /*!< UART FIFO trigger level 1: 4 character */ UART_FIFO_TRGLEV2, /*!< UART FIFO trigger level 2: 8 character */ UART_FIFO_TRGLEV3 /*!< UART FIFO trigger level 3: 14 character */ } UART_FITO_LEVEL_Type; /********************************************************************//** * @brief UART Interrupt Type definitions **********************************************************************/ typedef enum { UART_INTCFG_RBR = 0, /*!< RBR Interrupt enable*/ UART_INTCFG_THRE, /*!< THR Interrupt enable*/ UART_INTCFG_RLS, /*!< RX line status interrupt enable*/ UART_INTCFG_MS, /*!< Modem status interrupt enable (UART1 only) */ UART_INTCFG_CTS, /*!< CTS1 signal transition interrupt enable (UART1 only) */ UART_INTCFG_ABEO, /*!< Enables the end of auto-baud interrupt */ UART_INTCFG_ABTO /*!< Enables the auto-baud time-out interrupt */ } UART_INT_Type; /** * @brief UART Line Status Type definition */ typedef enum { UART_LINESTAT_RDR = UART_LSR_RDR, /*!