27 #ifndef __LPC17XX_UART_H
28 #define __LPC17XX_UART_H
48 #define UART_BLOCKING_TIMEOUT (0xFFFFFFFFUL)
60 #define UART_ACCEPTED_BAUDRATE_ERROR (3)
67 #define UART_RBR_MASKBIT ((uint8_t)0xFF)
72 #define UART_THR_MASKBIT ((uint8_t)0xFF)
77 #define UART_LOAD_DLL(div) ((div) & 0xFF)
78 #define UART_DLL_MASKBIT ((uint8_t)0xFF)
83 #define UART_DLM_MASKBIT ((uint8_t)0xFF)
84 #define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF)
89 #define UART_IER_RBRINT_EN ((uint32_t)(1<<0))
90 #define UART_IER_THREINT_EN ((uint32_t)(1<<1))
91 #define UART_IER_RLSINT_EN ((uint32_t)(1<<2))
92 #define UART1_IER_MSINT_EN ((uint32_t)(1<<3))
93 #define UART1_IER_CTSINT_EN ((uint32_t)(1<<7))
94 #define UART_IER_ABEOINT_EN ((uint32_t)(1<<8))
95 #define UART_IER_ABTOINT_EN ((uint32_t)(1<<9))
96 #define UART_IER_BITMASK ((uint32_t)(0x307))
97 #define UART1_IER_BITMASK ((uint32_t)(0x38F))
102 #define UART_IIR_INTSTAT_PEND ((uint32_t)(1<<0))
103 #define UART_IIR_INTID_RLS ((uint32_t)(3<<1))
104 #define UART_IIR_INTID_RDA ((uint32_t)(2<<1))
105 #define UART_IIR_INTID_CTI ((uint32_t)(6<<1))
106 #define UART_IIR_INTID_THRE ((uint32_t)(1<<1))
107 #define UART1_IIR_INTID_MODEM ((uint32_t)(0<<1))
108 #define UART_IIR_INTID_MASK ((uint32_t)(7<<1))
109 #define UART_IIR_FIFO_EN ((uint32_t)(3<<6))
110 #define UART_IIR_ABEO_INT ((uint32_t)(1<<8))
111 #define UART_IIR_ABTO_INT ((uint32_t)(1<<9))
112 #define UART_IIR_BITMASK ((uint32_t)(0x3CF))
117 #define UART_FCR_FIFO_EN ((uint8_t)(1<<0))
118 #define UART_FCR_RX_RS ((uint8_t)(1<<1))
119 #define UART_FCR_TX_RS ((uint8_t)(1<<2))
120 #define UART_FCR_DMAMODE_SEL ((uint8_t)(1<<3))
121 #define UART_FCR_TRG_LEV0 ((uint8_t)(0))
122 #define UART_FCR_TRG_LEV1 ((uint8_t)(1<<6))
123 #define UART_FCR_TRG_LEV2 ((uint8_t)(2<<6))
124 #define UART_FCR_TRG_LEV3 ((uint8_t)(3<<6))
125 #define UART_FCR_BITMASK ((uint8_t)(0xCF))
126 #define UART_TX_FIFO_SIZE (16)
131 #define UART_LCR_WLEN5 ((uint8_t)(0))
132 #define UART_LCR_WLEN6 ((uint8_t)(1<<0))
133 #define UART_LCR_WLEN7 ((uint8_t)(2<<0))
134 #define UART_LCR_WLEN8 ((uint8_t)(3<<0))
135 #define UART_LCR_STOPBIT_SEL ((uint8_t)(1<<2))
136 #define UART_LCR_PARITY_EN ((uint8_t)(1<<3))
137 #define UART_LCR_PARITY_ODD ((uint8_t)(0))
138 #define UART_LCR_PARITY_EVEN ((uint8_t)(1<<4))
139 #define UART_LCR_PARITY_F_1 ((uint8_t)(2<<4))
140 #define UART_LCR_PARITY_F_0 ((uint8_t)(3<<4))
141 #define UART_LCR_BREAK_EN ((uint8_t)(1<<6))
142 #define UART_LCR_DLAB_EN ((uint8_t)(1<<7))
143 #define UART_LCR_BITMASK ((uint8_t)(0xFF))
148 #define UART1_MCR_DTR_CTRL ((uint8_t)(1<<0))
149 #define UART1_MCR_RTS_CTRL ((uint8_t)(1<<1))
150 #define UART1_MCR_LOOPB_EN ((uint8_t)(1<<4))
151 #define UART1_MCR_AUTO_RTS_EN ((uint8_t)(1<<6))
152 #define UART1_MCR_AUTO_CTS_EN ((uint8_t)(1<<7))
153 #define UART1_MCR_BITMASK ((uint8_t)(0x0F3))
158 #define UART_LSR_RDR ((uint8_t)(1<<0))
159 #define UART_LSR_OE ((uint8_t)(1<<1))
160 #define UART_LSR_PE ((uint8_t)(1<<2))
161 #define UART_LSR_FE ((uint8_t)(1<<3))
162 #define UART_LSR_BI ((uint8_t)(1<<4))
163 #define UART_LSR_THRE ((uint8_t)(1<<5))
164 #define UART_LSR_TEMT ((uint8_t)(1<<6))
165 #define UART_LSR_RXFE ((uint8_t)(1<<7))
166 #define UART_LSR_BITMASK ((uint8_t)(0xFF))
171 #define UART1_MSR_DELTA_CTS ((uint8_t)(1<<0))
172 #define UART1_MSR_DELTA_DSR ((uint8_t)(1<<1))
173 #define UART1_MSR_LO2HI_RI ((uint8_t)(1<<2))
174 #define UART1_MSR_DELTA_DCD ((uint8_t)(1<<3))
175 #define UART1_MSR_CTS ((uint8_t)(1<<4))
176 #define UART1_MSR_DSR ((uint8_t)(1<<5))
177 #define UART1_MSR_RI ((uint8_t)(1<<6))
178 #define UART1_MSR_DCD ((uint8_t)(1<<7))
179 #define UART1_MSR_BITMASK ((uint8_t)(0xFF))
184 #define UART_SCR_BIMASK ((uint8_t)(0xFF))
189 #define UART_ACR_START ((uint32_t)(1<<0))
190 #define UART_ACR_MODE ((uint32_t)(1<<1))
191 #define UART_ACR_AUTO_RESTART ((uint32_t)(1<<2))
192 #define UART_ACR_ABEOINT_CLR ((uint32_t)(1<<8))
193 #define UART_ACR_ABTOINT_CLR ((uint32_t)(1<<9))
194 #define UART_ACR_BITMASK ((uint32_t)(0x307))
199 #define UART_ICR_IRDAEN ((uint32_t)(1<<0))
200 #define UART_ICR_IRDAINV ((uint32_t)(1<<1))
201 #define UART_ICR_FIXPULSE_EN ((uint32_t)(1<<2))
202 #define UART_ICR_PULSEDIV(n) ((uint32_t)((n&0x07)<<3))
203 #define UART_ICR_BITMASK ((uint32_t)(0x3F))
208 #define UART_FDR_DIVADDVAL(n) ((uint32_t)(n&0x0F))
209 #define UART_FDR_MULVAL(n) ((uint32_t)((n<<4)&0xF0))
210 #define UART_FDR_BITMASK ((uint32_t)(0xFF))
215 #define UART_TER_TXEN ((uint8_t)(1<<7))
216 #define UART_TER_BITMASK ((uint8_t)(0x80))
221 #define UART1_RS485CTRL_NMM_EN ((uint32_t)(1<<0))
223 #define UART1_RS485CTRL_RX_DIS ((uint32_t)(1<<1))
224 #define UART1_RS485CTRL_AADEN ((uint32_t)(1<<2))
225 #define UART1_RS485CTRL_SEL_DTR ((uint32_t)(1<<3))
227 #define UART1_RS485CTRL_DCTRL_EN ((uint32_t)(1<<4))
228 #define UART1_RS485CTRL_OINV_1 ((uint32_t)(1<<5))
231 #define UART1_RS485CTRL_BITMASK ((uint32_t)(0x3F))
236 #define UART1_RS485ADRMATCH_BITMASK ((uint8_t)(0xFF))
242 #define UART1_RS485DLY_BITMASK ((uint8_t)(0xFF))
247 #define UART_FIFOLVL_RXFIFOLVL(n) ((uint32_t)(n&0x0F))
248 #define UART_FIFOLVL_TXFIFOLVL(n) ((uint32_t)((n>>8)&0x0F))
249 #define UART_FIFOLVL_BITMASK ((uint32_t)(0x0F0F))
255 #define PARAM_UART_DATABIT(databit) ((databit==UART_DATABIT_5) || (databit==UART_DATABIT_6)\
256 || (databit==UART_DATABIT_7) || (databit==UART_DATABIT_8))
259 #define PARAM_UART_STOPBIT(stopbit) ((stopbit==UART_STOPBIT_1) || (stopbit==UART_STOPBIT_2))
262 #define PARAM_UART_PARITY(parity) ((parity==UART_PARITY_NONE) || (parity==UART_PARITY_ODD) \
263 || (parity==UART_PARITY_EVEN) || (parity==UART_PARITY_SP_1) \
264 || (parity==UART_PARITY_SP_0))
267 #define PARAM_UART_FIFO_LEVEL(fifo) ((fifo==UART_FIFO_TRGLEV0) \
268 || (fifo==UART_FIFO_TRGLEV1) || (fifo==UART_FIFO_TRGLEV2) \
269 || (fifo==UART_FIFO_TRGLEV3))
272 #define PARAM_UART_INTCFG(IntCfg) ((IntCfg==UART_INTCFG_RBR) || (IntCfg==UART_INTCFG_THRE) \
273 || (IntCfg==UART_INTCFG_RLS) || (IntCfg==UART_INTCFG_ABEO) \
274 || (IntCfg==UART_INTCFG_ABTO))
277 #define PARAM_UART1_INTCFG(IntCfg) ((IntCfg==UART1_INTCFG_MS) || (IntCfg==UART1_INTCFG_CTS))
280 #define PARAM_UART_AUTOBAUD_MODE(ABmode) ((ABmode==UART_AUTOBAUD_MODE0) || (ABmode==UART_AUTOBAUD_MODE1))
283 #define PARAM_UART_AUTOBAUD_INTSTAT(ABIntStat) ((ABIntStat==UART_AUTOBAUD_INTSTAT_ABEO) || \
284 (ABIntStat==UART_AUTOBAUD_INTSTAT_ABTO))
287 #define PARAM_UART_IrDA_PULSEDIV(PulseDiv) ((PulseDiv==UART_IrDA_PULSEDIV2) || (PulseDiv==UART_IrDA_PULSEDIV4) \
288 || (PulseDiv==UART_IrDA_PULSEDIV8) || (PulseDiv==UART_IrDA_PULSEDIV16) \
289 || (PulseDiv==UART_IrDA_PULSEDIV32) || (PulseDiv==UART_IrDA_PULSEDIV64) \
290 || (PulseDiv==UART_IrDA_PULSEDIV128) || (PulseDiv==UART_IrDA_PULSEDIV256))
293 #define PARAM_UART1_SIGNALSTATE(x) ((x==INACTIVE) || (x==ACTIVE))
296 #define PARAM_UART1_MODEM_PIN(x) ((x==UART1_MODEM_PIN_DTR) || (x==UART1_MODEM_PIN_RTS))
299 #define PARAM_UART1_MODEM_MODE(x) ((x==UART1_MODEM_MODE_LOOPBACK) || (x==UART1_MODEM_MODE_AUTO_RTS) \
300 || (x==UART1_MODEM_MODE_AUTO_CTS))
303 #define PARAM_UART_RS485_DIRCTRL_PIN(x) ((x==UART1_RS485_DIRCTRL_RTS) || (x==UART1_RS485_DIRCTRL_DTR))
306 #define PARAM_UARTx(x) ((((uint32_t *)x)==((uint32_t *)LPC_UART0)) \
307 || (((uint32_t *)x)==((uint32_t *)LPC_UART1)) \
308 || (((uint32_t *)x)==((uint32_t *)LPC_UART2)) \
309 || (((uint32_t *)x)==((uint32_t *)LPC_UART3)))
310 #define PARAM_UART_IrDA(x) (((uint32_t *)x)==((uint32_t *)LPC_UART3))
311 #define PARAM_UART1_MODEM(x) (((uint32_t *)x)==((uint32_t *)LPC_UART1))
314 #define PARAM_UART1_RS485_CFG_MATCHADDRVALUE(x) ((x<0xFF))
317 #define PARAM_UART1_RS485_CFG_DELAYVALUE(x) ((x<0xFF))
564 uint8_t MatchAddrValue;