uart.h File Reference

Go to the source code of this file.

Enumerations

enum  { UART_BW_MUL1 = 0, UART_BW_MUL2 = 1, UART_BW_MUL3 = 2, UART_BW_MUL4 = 3 }
 Define mul bits. More...
 
enum  UART_ParityTypeDef { PARITY_NONE = 0, PARITY_EVEN, PARITY_ODD }
 Define parity type. More...
 
enum  UART_StopBitTypeDef { STOP_BIT_ONE = 0, STOP_BIT_ONE_DOT_FIVE = BIT(4), STOP_BIT_TWO = BIT(5) }
 Define the length of stop bit. More...
 
enum  UART_RTSModeTypeDef { UART_RTS_MODE_AUTO = 0, UART_RTS_MODE_MANUAL }
 Define UART RTS mode. More...
 
enum  UART_TxPinDef {
  UART_TX_PA2 = GPIO_PA2, UART_TX_PB1 = GPIO_PB1, UART_TX_PD0 = GPIO_PD0, UART_TX_PD3 = GPIO_PD3,
  UART_TX_PD7 = GPIO_PD7
}
 Define UART TX pin:A2 B1 D0 D3 D7. More...
 
enum  UART_RxPinDef {
  UART_RX_PA0 = GPIO_PA0, UART_RX_PB0 = GPIO_PB0, UART_RX_PB7 = GPIO_PB7, UART_RX_PC3 = GPIO_PC3,
  UART_RX_PC5 = GPIO_PC5, UART_RX_PD6 = GPIO_PD6
}
 Define UART RX pin: A0 B0 B7 C3 C5 D6. More...
 
enum  UART_CtsPinDef { UART_CTS_PA3 = GPIO_PA3, UART_CTS_PB2 = GPIO_PB2, UART_CTS_PC4 = GPIO_PC4, UART_CTS_PD1 = GPIO_PD1 }
 Define UART CTS pin : A3 B2 C4 D1. More...
 
enum  UART_RtsPinDef { UART_RTS_PA4 = GPIO_PA4, UART_RTS_PB3 = GPIO_PB3, UART_RTS_PB6 = GPIO_PB6, UART_RTS_PC0 = GPIO_PC0 }
 Define UART RTS pin : A4 B3 B6 C0. More...
 

Functions

static unsigned char uart_tx_is_busy (void)
 This function servers to indicate Tx state. More...
 
static void uart_reset (void)
 This function resets the UART module. More...
 
void uart_init (unsigned short g_uart_div, unsigned char g_bwpc, UART_ParityTypeDef Parity, UART_StopBitTypeDef StopBit)
 This function initializes the UART module. More...
 
void uart_init_baudrate (unsigned int Baudrate, unsigned int System_clock, UART_ParityTypeDef Parity, UART_StopBitTypeDef StopBit)
 This function initializes the UART module. More...
 
void uart_dma_enable (unsigned char rx_dma_en, unsigned char tx_dma_en)
 enable uart DMA mode More...
 
void uart_irq_enable (unsigned char rx_irq_en, unsigned char tx_irq_en)
 config the irq of uart tx and rx More...
 
void uart_ndma_send_byte (unsigned char uartData)
 uart send data function with not DMA method. variable uart_TxIndex,it must cycle the four registers 0x90 0x91 0x92 0x93 for the design of SOC. so we need variable to remember the index. More...
 
void uart_ndma_irq_triglevel (unsigned char rx_level, unsigned char tx_level)
 config the number level setting the irq bit of status register 0x9d ie 0x9d[3]. uart_ndma_get_irq If the cnt register value(0x9c[0,3]) larger or equal than the value of 0x99[0,3] or the cnt register value(0x9c[4,7]) less or equal than the value of 0x99[4,7], it will set the irq bit of status register 0x9d, ie 0x9d[3] More...
 
unsigned char uart_ndmairq_get (void)
 get the status of uart irq. More...
 
volatile unsigned char uart_dma_send (unsigned char *Addr)
 uart send data function, this function tell the DMA to get data from the RAM and start the DMA transmission More...
 
volatile unsigned char uart_send_byte (unsigned char byte)
 uart send data function, this function tell the DMA to get data from the RAM and start the DMA transmission More...
 
void uart_recbuff_init (unsigned char *RecvAddr, unsigned short RecvBufLen)
 data receive buffer initiate function. DMA would move received uart data to the address space, uart packet length needs to be no larger than (recBuffLen - 4). More...
 
unsigned char uart_is_parity_error (void)
 This function determines whether parity error occurs once a packet arrives. More...
 
void uart_clear_parity_error (void)
 This function clears parity error status once when it occurs. More...
 
void uart_set_rts (unsigned char Enable, UART_RTSModeTypeDef Mode, unsigned char Thresh, unsigned char Invert, UART_RtsPinDef pin)
 UART hardware flow control configuration. Configure RTS pin. More...
 
void uart_set_rts_level (unsigned char Polarity)
 This function sets the RTS pin's level manually. More...
 
void uart_set_cts (unsigned char Enable, unsigned char Select, UART_CtsPinDef pin)
 UART hardware flow control configuration. Configure CTS pin. More...
 
void uart_gpio_set (UART_TxPinDef tx_pin, UART_RxPinDef rx_pin)
 This function serves to select pin for UART module. More...
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Define mul bits.

Enumerator
UART_BW_MUL1 
UART_BW_MUL2 
UART_BW_MUL3 
UART_BW_MUL4 

◆ UART_ParityTypeDef

Define parity type.

Enumerator
PARITY_NONE 
PARITY_EVEN 
PARITY_ODD 

◆ UART_StopBitTypeDef

Define the length of stop bit.

Enumerator
STOP_BIT_ONE 
STOP_BIT_ONE_DOT_FIVE 
STOP_BIT_TWO 

◆ UART_RTSModeTypeDef

Define UART RTS mode.

Enumerator
UART_RTS_MODE_AUTO 
UART_RTS_MODE_MANUAL 

◆ UART_TxPinDef

Define UART TX pin:A2 B1 D0 D3 D7.

Enumerator
UART_TX_PA2 
UART_TX_PB1 
UART_TX_PD0 
UART_TX_PD3 
UART_TX_PD7 

◆ UART_RxPinDef

Define UART RX pin: A0 B0 B7 C3 C5 D6.

Enumerator
UART_RX_PA0 
UART_RX_PB0 
UART_RX_PB7 
UART_RX_PC3 
UART_RX_PC5 
UART_RX_PD6 

◆ UART_CtsPinDef

Define UART CTS pin : A3 B2 C4 D1.

Enumerator
UART_CTS_PA3 
UART_CTS_PB2 
UART_CTS_PC4 
UART_CTS_PD1 

◆ UART_RtsPinDef

Define UART RTS pin : A4 B3 B6 C0.

Enumerator
UART_RTS_PA4 
UART_RTS_PB3 
UART_RTS_PB6 
UART_RTS_PC0 

Function Documentation

◆ uart_tx_is_busy()

static unsigned char uart_tx_is_busy ( void  )
inlinestatic

This function servers to indicate Tx state.

Parameters
[in]none.
Returns
the state of Tx 0:Tx done 1:not.

◆ uart_reset()

static void uart_reset ( void  )
inlinestatic

This function resets the UART module.

Parameters
[in]none
Returns
none

◆ uart_init()

void uart_init ( unsigned short  g_uart_div,
unsigned char  g_bwpc,
UART_ParityTypeDef  Parity,
UART_StopBitTypeDef  StopBit 
)

This function initializes the UART module.

Parameters
[in]g_uart_div- uart clock divider
[in]g_bwpc- bitwidth, should be set to larger than
        sys_clk      baud rate   g_uart_div         g_bwpc

        16Mhz        9600          118               13
                     19200         118               6
                     115200         9                13

        24Mhz        9600          249               9
                     19200         124               9
                     115200         12               15

        32Mhz        9600          235               13
                     19200         235               6
                     115200         17               13

        48Mhz        9600          499               9
                     19200         249               9
                     115200         25               15
[in]Parity- selected parity type for UART interface
[in]StopBit- selected length of stop bit for UART interface
Returns
none

◆ uart_init_baudrate()

void uart_init_baudrate ( unsigned int  Baudrate,
unsigned int  System_clock,
UART_ParityTypeDef  Parity,
UART_StopBitTypeDef  StopBit 
)

This function initializes the UART module.

Parameters
[in]Baudrate- uart baud rate
[in]System_clock- clock of system
[in]Parity- selected parity type for UART interface
[in]StopBit- selected length of stop bit for UART interface
Returns
none

◆ uart_dma_enable()

void uart_dma_enable ( unsigned char  rx_dma_en,
unsigned char  tx_dma_en 
)

enable uart DMA mode

Parameters
[in]none
Returns
none

◆ uart_irq_enable()

void uart_irq_enable ( unsigned char  rx_irq_en,
unsigned char  tx_irq_en 
)

config the irq of uart tx and rx

Parameters
[in]rx_irq_en- 1:enable rx irq. 0:disable rx irq
[in]tx_irq_en- 1:enable tx irq. 0:disable tx irq
Returns
none

◆ uart_ndma_send_byte()

void uart_ndma_send_byte ( unsigned char  uartData)

uart send data function with not DMA method. variable uart_TxIndex,it must cycle the four registers 0x90 0x91 0x92 0x93 for the design of SOC. so we need variable to remember the index.

Parameters
[in]uartData- the data to be send.
Returns
none

◆ uart_ndma_irq_triglevel()

void uart_ndma_irq_triglevel ( unsigned char  rx_level,
unsigned char  tx_level 
)

config the number level setting the irq bit of status register 0x9d ie 0x9d[3]. uart_ndma_get_irq If the cnt register value(0x9c[0,3]) larger or equal than the value of 0x99[0,3] or the cnt register value(0x9c[4,7]) less or equal than the value of 0x99[4,7], it will set the irq bit of status register 0x9d, ie 0x9d[3]

Parameters
[in]rx_level- receive level value. ie 0x99[0,3]
[in]tx_level- transmit level value.ie 0x99[4,7]
Returns
none

◆ uart_ndmairq_get()

unsigned char uart_ndmairq_get ( void  )

get the status of uart irq.

Parameters
[in]none
Returns
0: not uart irq ; not 0: indicate tx or rx irq

◆ uart_dma_send()

volatile unsigned char uart_dma_send ( unsigned char *  Addr)

uart send data function, this function tell the DMA to get data from the RAM and start the DMA transmission

Parameters
[in]Addr- pointer to the buffer containing data need to send
Returns
1: send success ; 0: DMA busy

◆ uart_send_byte()

volatile unsigned char uart_send_byte ( unsigned char  byte)

uart send data function, this function tell the DMA to get data from the RAM and start the DMA transmission

Parameters
[in]byte- single byte data need to send
Returns
1: send success ; 0: DMA busy

◆ uart_recbuff_init()

void uart_recbuff_init ( unsigned char *  RecvAddr,
unsigned short  RecvBufLen 
)

data receive buffer initiate function. DMA would move received uart data to the address space, uart packet length needs to be no larger than (recBuffLen - 4).

Parameters
[in]RecvAddr- pointer to the receiving buffer
[in]RecvBufLen- length in byte of the receiving buffer
Returns
none

◆ uart_is_parity_error()

unsigned char uart_is_parity_error ( void  )

This function determines whether parity error occurs once a packet arrives.

Parameters
[in]none
Returns
1: parity error ; 0: no parity error

◆ uart_clear_parity_error()

void uart_clear_parity_error ( void  )

This function clears parity error status once when it occurs.

Parameters
[in]none
Returns
none

◆ uart_set_rts()

void uart_set_rts ( unsigned char  Enable,
UART_RTSModeTypeDef  Mode,
unsigned char  Thresh,
unsigned char  Invert,
UART_RtsPinDef  pin 
)

UART hardware flow control configuration. Configure RTS pin.

Parameters
[in]Enable- enable or disable RTS function.
[in]Mode- set the mode of RTS(auto or manual).
[in]Thresh- threshold of trig RTS pin's level toggle(only for auto mode), it means the number of bytes that has arrived in Rx buf.
[in]Invert- whether invert the output of RTS pin(only for auto mode)
[in]pin- RTS pin select,it can be GPIO_PA4/GPIO_PB3/GPIO_PB6/GPIO_PC0.
Returns
none

◆ uart_set_rts_level()

void uart_set_rts_level ( unsigned char  Polarity)

This function sets the RTS pin's level manually.

Parameters
[in]Polarity- set the output of RTS pin(only for manual mode)
Returns
none

◆ uart_set_cts()

void uart_set_cts ( unsigned char  Enable,
unsigned char  Select,
UART_CtsPinDef  pin 
)

UART hardware flow control configuration. Configure CTS pin.

Parameters
[in]Enable- enable or disable CTS function.
[in]Select- when CTS's input equals to select, tx will be stopped
[in]pin- CTS pin select,it can be GPIO_PA3/GPIO_PB2/GPIO_PC4/GPIO_PD1.
Returns
none

◆ uart_gpio_set()

void uart_gpio_set ( UART_TxPinDef  tx_pin,
UART_RxPinDef  rx_pin 
)

This function serves to select pin for UART module.

Parameters
[in]tx_pin- the pin to send data.
[in]rx_pin- the pin to receive data.
Returns
none