| NANO102/112 BSP V3.04.000 The Board Support Package for Nano102/112 Series

uart.h
Go to the documentation of this file.
1/**************************************************************************/
13#ifndef __UART_H__
14#define __UART_H__
15
16#ifdef __cplusplus
17 extern "C"
18{
19#endif
20
21
35/*---------------------------------------------------------------------------------------------------------*/
36/* UA_LCR constants definitions */
37/*---------------------------------------------------------------------------------------------------------*/
38#define UART_WORD_LEN_5 (0)
39#define UART_WORD_LEN_6 (1)
40#define UART_WORD_LEN_7 (2)
41#define UART_WORD_LEN_8 (3)
43#define UART_PARITY_NONE (0x0 << UART_TLCTL_PBE_Pos)
44#define UART_PARITY_ODD (0x1 << UART_TLCTL_PBE_Pos)
45#define UART_PARITY_EVEN (0x3 << UART_TLCTL_PBE_Pos)
46#define UART_PARITY_MARK (0x5 << UART_TLCTL_PBE_Pos)
47#define UART_PARITY_SPACE (0x7 << UART_TLCTL_PBE_Pos)
49#define UART_STOP_BIT_1 (0x0 << UART_TLCTL_NSB_Pos)
50#define UART_STOP_BIT_1_5 (0x1 << UART_TLCTL_NSB_Pos)
51#define UART_STOP_BIT_2 (0x1 << UART_TLCTL_NSB_Pos)
53#define UART_TLCTL_RFITL_1BYTE (0x0 << UART_TLCTL_RFITL_Pos)
54#define UART_TLCTL_RFITL_4BYTES (0x1 << UART_TLCTL_RFITL_Pos)
55#define UART_TLCTL_RFITL_8BYTES (0x2 << UART_TLCTL_RFITL_Pos)
56#define UART_TLCTL_RFITL_14BYTES (0x3 << UART_TLCTL_RFITL_Pos)
58#define UART_TLCTL_RTS_TRI_LEV_1BYTE (0x0 << UART_TLCTL_RTS_TRI_LEV_Pos)
59#define UART_TLCTL_RTS_TRI_LEV_4BYTES (0x1 << UART_TLCTL_RTS_TRI_LEV_Pos)
60#define UART_TLCTL_RTS_TRI_LEV_8BYTES (0x2 << UART_TLCTL_RTS_TRI_LEV_Pos)
61#define UART_TLCTL_RTS_TRI_LEV_14BYTES (0x3 << UART_TLCTL_RTS_TRI_LEV_Pos)
64/*---------------------------------------------------------------------------------------------------------*/
65/* UART RTS LEVEL TRIGGER constants definitions */
66/*---------------------------------------------------------------------------------------------------------*/
67#define UART_RTS_IS_HIGH_LEV_TRG (0x1 << UART_MCSR_LEV_RTS_Pos)
68#define UART_RTS_IS_LOW_LEV_TRG (0x0 << UART_MCSR_LEV_RTS_Pos)
70/*---------------------------------------------------------------------------------------------------------*/
71/* UA_FUNC_SEL constants definitions */
72/*---------------------------------------------------------------------------------------------------------*/
73#define UART_FUNC_SEL_UART (0x0 << UART_FUN_SEL_FUN_SEL_Pos)
74#define UART_FUNC_SEL_LIN (0x1 << UART_FUN_SEL_FUN_SEL_Pos)
75#define UART_FUNC_SEL_IrDA (0x2 << UART_FUN_SEL_FUN_SEL_Pos)
76#define UART_FUNC_SEL_RS485 (0x3 << UART_FUN_SEL_FUN_SEL_Pos) /* end of group NANO1X2_UART_EXPORTED_CONSTANTS */
80
81
94#define UART_BAUD_MODE0 (0)
95
104#define UART_BAUD_MODE1 (UART_BAUD_DIV_16_EN_Msk)
105
106
116#define UART_BAUD_MODE1_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate*8)) / u32BaudRate >> 4)-1)
117
126#define UART_BAUD_MODE0_DIVIDER(u32SrcFreq, u32BaudRate) (((u32SrcFreq + (u32BaudRate/2)) / u32BaudRate)-1)
127
128
137#define UART_WRITE(uart, u8Data) (uart->THR = (u8Data))
138
146#define UART_READ(uart) (uart->RBR)
147
148
156#define UART_GET_TX_EMPTY(uart) (uart->FSR & UART_FSR_TX_EMPTY_F_Msk)
157
158
166#define UART_GET_RX_EMPTY(uart) (uart->FSR & UART_FSR_RX_EMPTY_F_Msk)
167
175#define UART_IS_TX_EMPTY(uart) ((uart->FSR & UART_FSR_TE_F_Msk) >> UART_FSR_TE_F_Pos)
176
177
185#define UART_WAIT_TX_EMPTY(uart) while(!((uart->FSR) & (UART_FSR_TX_EMPTY_F_Msk | UART_FSR_TE_F_Msk)) )
186
196#define UART_IS_RX_READY(uart) ((uart->ISR & UART_ISR_RDA_IS_Msk)>>UART_ISR_RDA_IS_Pos)
197
198
208#define UART_IS_TX_FULL(uart) ((uart->FSR & UART_FSR_TX_FULL_F_Msk)>>UART_FSR_TX_FULL_F_Pos)
209
220#define UART_IS_RX_FULL(uart) ((uart->FSR & UART_FSR_RX_FULL_F_Msk)>>UART_FSR_RX_FULL_F_Pos)
221
222
230#define UART_GET_TX_FULL(uart) (uart->FSR & UART_FSR_TX_FULL_F_Msk)
231
232
240#define UART_GET_RX_FULL(uart) (uart->FSR & UART_FSR_RX_FULL_F_Msk)
241
250#define UART_SET_RX_FIFO_INTTRGLV(uart, u32TriggerLevel) ((uart)->TLCTL = ((uart)->TLCTL & ~UART_TLCTL_RFITL_Msk) | (u32TriggerLevel))
251
269#define UART_ENABLE_INT(uart, u32eIntSel) (uart->IER |= (u32eIntSel))
270
271
288#define UART_DISABLE_INT(uart, u32eIntSel) (uart->IER &= ~ (u32eIntSel))
289
290
310#define UART_GET_INT_FLAG(uart,u32eIntTypeFlag) ((uart->ISR & (u32eIntTypeFlag))?1:0)
311
312
319__STATIC_INLINE void UART_CLEAR_RTS(UART_T* uart)
320{
321 uart->MCSR |= UART_MCSR_LEV_RTS_Msk;
322}
323
330__STATIC_INLINE void UART_SET_RTS(UART_T* uart)
331{
332 uart->MCSR &= ~UART_MCSR_LEV_RTS_Msk;
333}
334
341#define UART_RS485_CLEAR_ADDR_FLAG(uart) (uart->TRSR = UART_TRSR_RS485_ADDET_F_Msk)
342
343
350#define UART_RS485_GET_ADDR_FLAG(uart) ((uart->TRSR & UART_TRSR_RS485_ADDET_F_Msk) >> UART_TRSR_RS485_ADDET_F_Pos)
351
352
353 void UART_ClearIntFlag(UART_T* uart , uint32_t u32InterruptFlag);
354 void UART_Close(UART_T* uart );
355 void UART_DisableFlowCtrl(UART_T* uart );
356 void UART_DisableInt(UART_T* uart, uint32_t u32InterruptFlag );
357 void UART_EnableFlowCtrl(UART_T* uart );
358 void UART_EnableInt(UART_T* uart, uint32_t u32InterruptFlag );
359 void UART_Open(UART_T* uart, uint32_t u32baudrate);
360uint32_t UART_Read(UART_T* uart, uint8_t *pu8RxBuf, uint32_t u32ReadBytes);
361 void UART_SetLine_Config(UART_T* uart, uint32_t u32baudrate, uint32_t u32data_width, uint32_t u32parity, uint32_t u32stop_bits);
362 void UART_SetTimeoutCnt(UART_T* uart, uint32_t u32TOC);
363 void UART_SelectIrDAMode(UART_T* uart, uint32_t u32Buadrate, uint32_t u32Direction);
364 void UART_SelectRS485Mode(UART_T* uart, uint32_t u32Mode, uint32_t u32Addr);
365 void UART_SelectLINMode(UART_T* uart, uint32_t u32Mode, uint32_t u32BreakLength);
366uint32_t UART_Write(UART_T* uart,uint8_t *pu8TxBuf, uint32_t u32WriteBytes);
367
368 /* end of group NANO1X2_UART_EXPORTED_FUNCTIONS */
370 /* end of group NANO1X2_UART_Driver */
372 /* end of group NANO1X2_Device_Driver */
374
375#ifdef __cplusplus
376}
377#endif
378
379#endif //__UART_H__
380
381/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/
UART_MCSR_LEV_RTS_Msk
#define UART_MCSR_LEV_RTS_Msk
Definition: Nano1X2Series.h:10221
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:361
UART_SelectLINMode
void UART_SelectLINMode(UART_T *uart, uint32_t u32Mode, uint32_t u32BreakLength)
Select and configure LIN function.
Definition: uart.c:382
UART_EnableInt
void UART_EnableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to enable UART specified interrupt.
Definition: uart.c:157
UART_CLEAR_RTS
__STATIC_INLINE void UART_CLEAR_RTS(UART_T *uart)
Set RTS pin is low.
Definition: uart.h:319
UART_SET_RTS
__STATIC_INLINE void UART_SET_RTS(UART_T *uart)
Set RTS pin is high.
Definition: uart.h:330
UART_SetTimeoutCnt
void UART_SetTimeoutCnt(UART_T *uart, uint32_t u32TOC)
This function use to set Rx timeout count.
Definition: uart.c:305
UART_Close
void UART_Close(UART_T *uart)
The function is used to disable UART.
Definition: uart.c:83
UART_ClearIntFlag
void UART_ClearIntFlag(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to clear UART specified interrupt flag.
Definition: uart.c:41
UART_DisableFlowCtrl
void UART_DisableFlowCtrl(UART_T *uart)
The function is used to disable UART auto flow control.
Definition: uart.c:96
UART_EnableFlowCtrl
void UART_EnableFlowCtrl(UART_T *uart)
The function is used to Enable UART auto flow control.
Definition: uart.c:133
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:403
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:257
UART_DisableInt
void UART_DisableInt(UART_T *uart, uint32_t u32InterruptFlag)
The function is used to disable UART specified interrupt.
Definition: uart.c:119
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:321
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:223
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:171
UART_T::MCSR
__IO uint32_t MCSR
Definition: Nano1X2Series.h:9888
UART_T
Definition: Nano1X2Series.h:9480