uart.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_38400 = 38400,
  38. BIT_RATE_57600 = 57600,
  39. BIT_RATE_74880 = 74880,
  40. BIT_RATE_115200 = 115200,
  41. BIT_RATE_230400 = 230400,
  42. BIT_RATE_256000 = 256000,
  43. BIT_RATE_460800 = 460800,
  44. BIT_RATE_921600 = 921600,
  45. BIT_RATE_1843200 = 1843200,
  46. BIT_RATE_3686400 = 3686400,
  47. } UartBautRate;
  48. typedef enum {
  49. NONE_CTRL,
  50. HARDWARE_CTRL,
  51. XON_XOFF_CTRL
  52. } UartFlowCtrl;
  53. typedef enum {
  54. EMPTY,
  55. UNDER_WRITE,
  56. WRITE_OVER
  57. } RcvMsgBuffState;
  58. typedef struct {
  59. uint32 RcvBuffSize;
  60. uint8 *pRcvMsgBuff;
  61. uint8 *pWritePos;
  62. uint8 *pReadPos;
  63. uint8 TrigLvl; //JLU: may need to pad
  64. RcvMsgBuffState BuffState;
  65. } RcvMsgBuff;
  66. typedef struct {
  67. uint32 TrxBuffSize;
  68. uint8 *pTrxBuff;
  69. } TrxMsgBuff;
  70. typedef enum {
  71. BAUD_RATE_DET,
  72. WAIT_SYNC_FRM,
  73. SRCH_MSG_HEAD,
  74. RCV_MSG_BODY,
  75. RCV_ESC_CHAR,
  76. } RcvMsgState;
  77. typedef struct {
  78. UartBautRate baut_rate;
  79. UartBitsNum4Char data_bits;
  80. UartExistParity exist_parity;
  81. UartParityMode parity; // chip size in byte
  82. UartStopBitsNum stop_bits;
  83. UartFlowCtrl flow_ctrl;
  84. RcvMsgBuff rcv_buff;
  85. TrxMsgBuff trx_buff;
  86. RcvMsgState rcv_state;
  87. int received;
  88. int buff_uart_no; //indicate which uart use tx/rx buffer
  89. } UartDevice;
  90. void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, os_signal_t sig_input);
  91. void uart0_alt(uint8 on);
  92. void uart0_sendStr(const char *str);
  93. void uart0_putc(const char c);
  94. void uart0_tx_buffer(uint8 *buf, uint16 len);
  95. void uart_setup(uint8 uart_no);
  96. STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
  97. void uart_set_alt_output_uart0(void (*fn)(char));
  98. #endif