uart.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef UART_APP_H
  2. #define UART_APP_H
  3. #include "uart_register.h"
  4. #include "eagle_soc.h"
  5. #include "c_types.h"
  6. #include "os_type.h"
  7. #define RX_BUFF_SIZE 0x100
  8. #define TX_BUFF_SIZE 100
  9. typedef enum {
  10. FIVE_BITS = 0x0,
  11. SIX_BITS = 0x1,
  12. SEVEN_BITS = 0x2,
  13. EIGHT_BITS = 0x3
  14. } UartBitsNum4Char;
  15. typedef enum {
  16. ONE_STOP_BIT = 0x1,
  17. ONE_HALF_STOP_BIT = 0x2,
  18. TWO_STOP_BIT = 0x3
  19. } UartStopBitsNum;
  20. typedef enum {
  21. NONE_BITS = 0x2,
  22. ODD_BITS = 1,
  23. EVEN_BITS = 0
  24. } UartParityMode;
  25. typedef enum {
  26. STICK_PARITY_DIS = 0,
  27. STICK_PARITY_EN = 1
  28. } UartExistParity;
  29. typedef enum {
  30. BIT_RATE_300 = 300,
  31. BIT_RATE_600 = 600,
  32. BIT_RATE_1200 = 1200,
  33. BIT_RATE_2400 = 2400,
  34. BIT_RATE_4800 = 4800,
  35. BIT_RATE_9600 = 9600,
  36. BIT_RATE_19200 = 19200,
  37. BIT_RATE_31250 = 31250,
  38. BIT_RATE_38400 = 38400,
  39. BIT_RATE_57600 = 57600,
  40. BIT_RATE_74880 = 74880,
  41. BIT_RATE_115200 = 115200,
  42. BIT_RATE_230400 = 230400,
  43. BIT_RATE_256000 = 256000,
  44. BIT_RATE_460800 = 460800,
  45. BIT_RATE_921600 = 921600,
  46. BIT_RATE_1843200 = 1843200,
  47. BIT_RATE_3686400 = 3686400,
  48. } UartBautRate;
  49. typedef enum {
  50. NONE_CTRL,
  51. HARDWARE_CTRL,
  52. XON_XOFF_CTRL
  53. } UartFlowCtrl;
  54. typedef enum {
  55. EMPTY,
  56. UNDER_WRITE,
  57. WRITE_OVER
  58. } RcvMsgBuffState;
  59. typedef struct {
  60. uint32 RcvBuffSize;
  61. uint8 *pRcvMsgBuff;
  62. uint8 *pWritePos;
  63. uint8 *pReadPos;
  64. uint8 TrigLvl; //JLU: may need to pad
  65. RcvMsgBuffState BuffState;
  66. } RcvMsgBuff;
  67. typedef struct {
  68. uint32 TrxBuffSize;
  69. uint8 *pTrxBuff;
  70. } TrxMsgBuff;
  71. typedef enum {
  72. BAUD_RATE_DET,
  73. WAIT_SYNC_FRM,
  74. SRCH_MSG_HEAD,
  75. RCV_MSG_BODY,
  76. RCV_ESC_CHAR,
  77. } RcvMsgState;
  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. typedef struct {
  92. UartBautRate baut_rate;
  93. UartBitsNum4Char data_bits;
  94. UartExistParity exist_parity;
  95. UartParityMode parity;
  96. UartStopBitsNum stop_bits;
  97. } UartConfig;
  98. void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input, uint8 *flag_input);
  99. UartConfig uart_get_config(uint8 uart_no);
  100. void uart0_alt(uint8 on);
  101. void uart0_sendStr(const char *str);
  102. void uart0_putc(const char c);
  103. void uart0_tx_buffer(uint8 *buf, uint16 len);
  104. void uart_setup(uint8 uart_no);
  105. STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
  106. void uart_set_alt_output_uart0(void (*fn)(char));
  107. #endif