blob: 2f762db5a2b368c2550acd06f8f6e92023e563e7 [file] [log] [blame]
Damien George075d5972014-11-27 20:30:33 +00001#ifndef _INCLUDED_UART_H_
2#define _INCLUDED_UART_H_
3
4#define UART0 (0)
5#define UART1 (1)
6
7typedef enum {
8 UART_FIVE_BITS = 0x0,
9 UART_SIX_BITS = 0x1,
10 UART_SEVEN_BITS = 0x2,
11 UART_EIGHT_BITS = 0x3
12} UartBitsNum4Char;
13
14typedef enum {
15 UART_ONE_STOP_BIT = 0,
16 UART_ONE_HALF_STOP_BIT = BIT2,
17 UART_TWO_STOP_BIT = BIT2
18} UartStopBitsNum;
19
20typedef enum {
21 UART_NONE_BITS = 0,
22 UART_ODD_BITS = 0,
23 UART_EVEN_BITS = BIT4
24} UartParityMode;
25
26typedef enum {
27 UART_STICK_PARITY_DIS = 0,
28 UART_STICK_PARITY_EN = BIT3 | BIT5
29} UartExistParity;
30
31typedef enum {
32 UART_BIT_RATE_9600 = 9600,
33 UART_BIT_RATE_19200 = 19200,
34 UART_BIT_RATE_38400 = 38400,
35 UART_BIT_RATE_57600 = 57600,
36 UART_BIT_RATE_74880 = 74880,
37 UART_BIT_RATE_115200 = 115200,
38 UART_BIT_RATE_230400 = 230400,
39 UART_BIT_RATE_256000 = 256000,
40 UART_BIT_RATE_460800 = 460800,
41 UART_BIT_RATE_921600 = 921600
42} UartBautRate;
43
44typedef enum {
45 UART_NONE_CTRL,
46 UART_HARDWARE_CTRL,
47 UART_XON_XOFF_CTRL
48} UartFlowCtrl;
49
50typedef enum {
51 UART_EMPTY,
52 UART_UNDER_WRITE,
53 UART_WRITE_OVER
54} RcvMsgBuffState;
55
56typedef struct {
57 uint32 RcvBuffSize;
58 uint8 *pRcvMsgBuff;
59 uint8 *pWritePos;
60 uint8 *pReadPos;
61 uint8 TrigLvl; //JLU: may need to pad
62 RcvMsgBuffState BuffState;
63} RcvMsgBuff;
64
65typedef struct {
66 uint32 TrxBuffSize;
67 uint8 *pTrxBuff;
68} TrxMsgBuff;
69
70typedef enum {
71 UART_BAUD_RATE_DET,
72 UART_WAIT_SYNC_FRM,
73 UART_SRCH_MSG_HEAD,
74 UART_RCV_MSG_BODY,
75 UART_RCV_ESC_CHAR,
76} RcvMsgState;
77
78typedef struct {
79 UartBautRate baut_rate;
80 UartBitsNum4Char data_bits;
81 UartExistParity exist_parity;
82 UartParityMode parity; // chip size in byte
83 UartStopBitsNum stop_bits;
84 UartFlowCtrl flow_ctrl;
85 RcvMsgBuff rcv_buff;
86 TrxMsgBuff trx_buff;
87 RcvMsgState rcv_state;
88 int received;
89 int buff_uart_no; //indicate which uart use tx/rx buffer
90} UartDevice;
91
92void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
93int uart0_rx(void);
94void uart_tx_one_char(uint8 uart, uint8 TxChar);
Paul Sokolovskyd9d4a722016-01-03 07:33:42 +020095void uart_flush(uint8 uart);
Damien George96eca222016-04-06 00:12:58 +030096void uart_os_config(int uart);
Damien George075d5972014-11-27 20:30:33 +000097
98#endif // _INCLUDED_UART_H_