Damien George | 075d597 | 2014-11-27 20:30:33 +0000 | [diff] [blame] | 1 | #ifndef _INCLUDED_UART_H_ |
| 2 | #define _INCLUDED_UART_H_ |
| 3 | |
| 4 | #define UART0 (0) |
| 5 | #define UART1 (1) |
| 6 | |
| 7 | typedef enum { |
| 8 | UART_FIVE_BITS = 0x0, |
| 9 | UART_SIX_BITS = 0x1, |
| 10 | UART_SEVEN_BITS = 0x2, |
| 11 | UART_EIGHT_BITS = 0x3 |
| 12 | } UartBitsNum4Char; |
| 13 | |
| 14 | typedef enum { |
| 15 | UART_ONE_STOP_BIT = 0, |
| 16 | UART_ONE_HALF_STOP_BIT = BIT2, |
| 17 | UART_TWO_STOP_BIT = BIT2 |
| 18 | } UartStopBitsNum; |
| 19 | |
| 20 | typedef enum { |
| 21 | UART_NONE_BITS = 0, |
| 22 | UART_ODD_BITS = 0, |
| 23 | UART_EVEN_BITS = BIT4 |
| 24 | } UartParityMode; |
| 25 | |
| 26 | typedef enum { |
| 27 | UART_STICK_PARITY_DIS = 0, |
| 28 | UART_STICK_PARITY_EN = BIT3 | BIT5 |
| 29 | } UartExistParity; |
| 30 | |
| 31 | typedef 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 | |
| 44 | typedef enum { |
| 45 | UART_NONE_CTRL, |
| 46 | UART_HARDWARE_CTRL, |
| 47 | UART_XON_XOFF_CTRL |
| 48 | } UartFlowCtrl; |
| 49 | |
| 50 | typedef enum { |
| 51 | UART_EMPTY, |
| 52 | UART_UNDER_WRITE, |
| 53 | UART_WRITE_OVER |
| 54 | } RcvMsgBuffState; |
| 55 | |
| 56 | typedef 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 | |
| 65 | typedef struct { |
| 66 | uint32 TrxBuffSize; |
| 67 | uint8 *pTrxBuff; |
| 68 | } TrxMsgBuff; |
| 69 | |
| 70 | typedef 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 | |
| 78 | typedef 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 | |
| 92 | void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); |
| 93 | int uart0_rx(void); |
| 94 | void uart_tx_one_char(uint8 uart, uint8 TxChar); |
Paul Sokolovsky | d9d4a72 | 2016-01-03 07:33:42 +0200 | [diff] [blame] | 95 | void uart_flush(uint8 uart); |
Damien George | 96eca22 | 2016-04-06 00:12:58 +0300 | [diff] [blame^] | 96 | void uart_os_config(int uart); |
Damien George | 075d597 | 2014-11-27 20:30:33 +0000 | [diff] [blame] | 97 | |
| 98 | #endif // _INCLUDED_UART_H_ |