| NUC472_NUC442_BSP V3.03.003 The Board Support Package for NUC472/NUC442

uart.h
Go to the documentation of this file.
1/**************************************************************************/
14#ifndef __UART_H__
15#define __UART_H__
16
17#ifdef __cplusplus
18 extern "C"
19{
20#endif
21
22
35/*---------------------------------------------------------------------------------------------------------*/
36/* UART_FCR constants definitions */
37/*---------------------------------------------------------------------------------------------------------*/
38
39#define UART_FIFO_RFITL_1BYTE (0x0 << UART_FIFO_RFITL_Pos)
40#define UART_FIFO_RFITL_4BYTES (0x1 << UART_FIFO_RFITL_Pos)
41#define UART_FIFO_RFITL_8BYTES (0x2 << UART_FIFO_RFITL_Pos)
42#define UART_FIFO_RFITL_14BYTES (0x3 << UART_FIFO_RFITL_Pos)
44#define UART_FIFO_RTSTRGLV_1BYTE (0x0 << UART_FIFO_RTSTRGLV_Pos)
45#define UART_FIFO_RTSTRGLV_4BYTES (0x1 << UART_FIFO_RTSTRGLV_Pos)
46#define UART_FIFO_RTSTRGLV_8BYTES (0x2 << UART_FIFO_RTSTRGLV_Pos)
47#define UART_FIFO_RTSTRGLV_14BYTES (0x3 << UART_FIFO_RTSTRGLV_Pos)
49/*---------------------------------------------------------------------------------------------------------*/
50/* UART_LCR constants definitions */
51/*---------------------------------------------------------------------------------------------------------*/
52#define UART_WORD_LEN_5 (0)
53#define UART_WORD_LEN_6 (1)
54#define UART_WORD_LEN_7 (2)
55#define UART_WORD_LEN_8 (3)
57#define UART_PARITY_NONE (0x0 << UART_LINE_PBE_Pos)
58#define UART_PARITY_ODD (0x1 << UART_LINE_PBE_Pos)
59#define UART_PARITY_EVEN (0x3 << UART_LINE_PBE_Pos)
60#define UART_PARITY_MARK (0x5 << UART_LINE_PBE_Pos)
61#define UART_PARITY_SPACE (0x7 << UART_LINE_PBE_Pos)
63#define UART_STOP_BIT_1 (0x0 << UART_LINE_NSB_Pos)
64#define UART_STOP_BIT_1_5 (0x1 << UART_LINE_NSB_Pos)
65#define UART_STOP_BIT_2 (0x1 << UART_LINE_NSB_Pos)
68/*---------------------------------------------------------------------------------------------------------*/
69/* UART RTS LEVEL TRIGGER constants definitions */
70/*---------------------------------------------------------------------------------------------------------*/
71#define UART_RTS_IS_HIGH_LEV_TRG (0x1 << UART_MODEM_RTSACTLV_Pos)
72#define UART_RTS_IS_LOW_LEV_TRG (0x0 << UART_MODEM_RTSACTLV_Pos)
74/*---------------------------------------------------------------------------------------------------------*/
75/* UART CTS LEVEL TRIGGER constants definitions */
76/*---------------------------------------------------------------------------------------------------------*/
77#define UART_CTS_IS_HIGH_LEV_TRG (0x1 << UART_MODEMSTS_CTSACTLV_Pos)
78#define UART_CTS_IS_LOW_LEV_TRG (0x0 << UART_MODEMSTS_CTSACTLV_Pos)
80/*---------------------------------------------------------------------------------------------------------*/
81/* UART_FUNC_SEL constants definitions */
82/*---------------------------------------------------------------------------------------------------------*/
83#define UART_FUNCSEL_UART (0x0 << UART_FUNCSEL_FUNCSEL_Pos)
84#define UART_FUNCSEL_IrDA (0x2 << UART_FUNCSEL_FUNCSEL_Pos)
85#define UART_FUNCSEL_RS485 (0x3 << UART_FUNCSEL_FUNCSEL_Pos)
87/*---------------------------------------------------------------------------------------------------------*/
88/* UART BAUDRATE MODE constants definitions */
89/*---------------------------------------------------------------------------------------------------------*/
90#define UART_BAUD_MODE0 (0)
91#define UART_BAUD_MODE2 (UART_BAUD_BAUDM1_Msk | UART_BAUD_BAUDM0_Msk) /* end of group NUC472_442_UART_EXPORTED_CONSTANTS */
96
97
113#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate*8)) / u32BaudRate >> 4)-2)
114
124#define UART_BAUD_MODE2_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate/2)) / u32BaudRate)-2)
125
126
136#define UART_WRITE(uart, u8Data) (uart->DAT = (u8Data))
137
146#define UART_READ(uart) (uart->DAT)
147
148
157#define UART_GET_TX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_TXEMPTY_Msk)
158
159
168#define UART_GET_RX_EMPTY(uart) (uart->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk)
169
178#define UART_IS_TX_EMPTY(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos)
179
180
189#define UART_WAIT_TX_EMPTY(uart) while(!(((uart->FIFOSTS) & UART_FIFOSTS_TXEMPTYF_Msk) >> UART_FIFOSTS_TXEMPTYF_Pos))
190
201#define UART_IS_RX_READY(uart) ((uart->INTSTS & UART_INTSTS_RDAIF_Msk)>>UART_INTSTS_RDAIF_Pos)
202
203
214#define UART_IS_TX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)>>UART_FIFOSTS_TXFULL_Pos)
215
227#define UART_IS_RX_FULL(uart) ((uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)>>UART_FIFOSTS_RXFULL_Pos)
228
229
238#define UART_GET_TX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_TXFULL_Msk)
239
240
249#define UART_GET_RX_FULL(uart) (uart->FIFOSTS & UART_FIFOSTS_RXFULL_Msk)
250
251
269#define UART_ENABLE_INT(uart, u32eIntSel) (uart->INTEN |= (u32eIntSel))
270
271
288#define UART_DISABLE_INT(uart, u32eIntSel) (uart->INTEN &= ~ (u32eIntSel))
289
290
324#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) ((uart->INTSTS & (u32eIntTypeFlag))?1:0)
325
326
333__STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
334{
335 uart->MODEM |= UART_MODEM_RTSACTLV_Msk;
336 uart->MODEM &= UART_MODEM_RTS_Msk;
337}
338
345__STATIC_INLINE void UART_SET_RTS(UART_T* uart)
346{
347 uart->MODEM |= UART_MODEM_RTSACTLV_Msk | UART_MODEM_RTS_Msk;
348}
349
357#define UART_RS485_CLEAR_ADDR_FLAG(uart) (uart->FIFOSTS |= UART_FIFOSTS_ADDRDETF_Msk)
358
359
367#define UART_RS485_GET_ADDR_FLAG(uart) ((uart->FIFOSTS & UART_FIFOSTS_ADDRDETF_Msk) >> UART_FIFOSTS_ADDRDETF_Pos)
368
369
370 void UART_ClearIntFlag(UART_T* uart, uint32_t u32InterruptFlag);
371 void UART_Close(UART_T* uart );
372 void UART_DisableFlowCtrl(UART_T* uart );
373 void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag );
374 void UART_EnableFlowCtrl(UART_T* uart );
375 void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag );
376 void UART_Open(UART_T* uart, uint32_t u32baudrate);
377uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
378 void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
379 void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
380 void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
381 void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
382uint32_t UART_Write(UART_T* uart,uint8_t *pu8TxBuf, uint32_t u32WriteBytes);
383
384 /* end of group NUC472_442_UART_EXPORTED_FUNCTIONS */
386 /* end of group NUC472_442_UART_Driver */
388 /* end of group NUC472_442_Device_Driver */
390
391#ifdef __cplusplus
392}
393#endif
394
395#endif //__UART_H__
396
397/*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/
398
399
400
401
UART_MODEM_RTS_Msk
#define UART_MODEM_RTS_Msk
Definition: NUC472_442.h:25884
UART_MODEM_RTSACTLV_Msk
#define UART_MODEM_RTSACTLV_Msk
Definition: NUC472_442.h:25887
UART_SelectRS485Mode
void UART_SelectRS485Mode(UART_T *uart, uint32_t u32Mode, uint32_t u32Addr)
The function is used to set RS485 relative setting.
Definition: uart.c:310
UART_EnableInt
void UART_EnableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to enable UART specified interrupt and disable NVIC UART IRQ.
Definition: uart.c:146
UART_CLEAR_RTS
__STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart)
Set RTS pin is low.
Definition: uart.h:333
UART_SET_RTS
__STATIC_INLINE void UART_SET_RTS(UART_T *uart)
Set RTS pin is high.
Definition: uart.h:345
UART_SetTimeoutCnt
void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC)
This function use to set Rx timeout count.
Definition: uart.c:264
UART_Close
void UART_Close(UART_T *uart)
The function is used to disable UART.
Definition: uart.c:72
UART_ClearIntFlag
void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to clear UART specified interrupt flag.
Definition: uart.c:43
UART_DisableFlowCtrl
void UART_DisableFlowCtrl(UART_T *uart)
The function is used to disable UART auto flow control.
Definition: uart.c:85
UART_EnableFlowCtrl
void UART_EnableFlowCtrl(UART_T *uart)
The function is used to Enable UART auto flow control.
Definition: uart.c:121
UART_Write
uint32_t UART_Write(UART_T *uart, uint8_t *pu8TxBuf, uint32_t u32WriteBytes)
The function is to write data into TX buffer to transmit data by UART.
Definition: uart.c:329
UART_SetLine_Config
void UART_SetLine_Config(UART_T *uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits)
This function use to config UART line setting.
Definition: uart.c:229
UART_DisableInt
void UART_DisableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to disable UART specified interrupt and disable NVIC UART IRQ.
Definition: uart.c:107
UART_SelectIrDAMode
void UART_SelectIrDAMode(UART_T *uart, uint32_t u32Buadrate, uint32_t u32Direction)
The function is used to configure IrDA relative settings. It consists of TX or RX mode and baudrate.
Definition: uart.c:280
UART_Read
uint32_t UART_Read(UART_T *uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes)
The function is used to read Rx data from RX FIFO and the data will be stored in pu8RxBuf.
Definition: uart.c:199
UART_Open
void UART_Open(UART_T *uart, uint32_t u32baudrate)
This function use to enable UART function and set baud-rate.
Definition: uart.c:160
UART_T::MODEM
__IO uint32_t MODEM
Definition: NUC472_442.h:25344
UART_T
Definition: NUC472_442.h:25170