uart.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef UART_APP_H
  2. #define UART_APP_H
  3. #include "driver/uart_register.h"
  4. #include "eagle_soc.h"
  5. #include "c_types.h"
  6. #include "ets_sys.h"
  7. #include "osapi.h"
  8. #include <mem.h>
  9. #define RX_BUFF_SIZE 0x100
  10. #define TX_BUFF_SIZE 100
  11. #define UART_HW_RTS 0
  12. #define UART_HW_CTS 0
  13. #define UART0 0
  14. #define UART1 1
  15. typedef enum {
  16. FIVE_BITS = 0x0,
  17. SIX_BITS = 0x1,
  18. SEVEN_BITS = 0x2,
  19. EIGHT_BITS = 0x3
  20. } UartBitsNum4Char;
  21. typedef enum {
  22. ONE_STOP_BIT = 0,
  23. ONE_HALF_STOP_BIT = BIT2,
  24. TWO_STOP_BIT = BIT2
  25. } UartStopBitsNum;
  26. typedef enum {
  27. NONE_BITS = 0,
  28. ODD_BITS = 0,
  29. EVEN_BITS = BIT4
  30. } UartParityMode;
  31. typedef enum {
  32. STICK_PARITY_DIS = 0,
  33. STICK_PARITY_EN = BIT3 | BIT5
  34. } UartExistParity;
  35. typedef enum {
  36. BIT_RATE_9600 = 9600,
  37. BIT_RATE_19200 = 19200,
  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_460800 = 460800,
  44. BIT_RATE_921600 = 921600
  45. } UartBautRate;
  46. typedef enum {
  47. NONE_CTRL,
  48. HARDWARE_CTRL,
  49. XON_XOFF_CTRL
  50. } UartFlowCtrl;
  51. typedef enum {
  52. EMPTY,
  53. UNDER_WRITE,
  54. WRITE_OVER
  55. } RcvMsgBuffState;
  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. typedef struct {
  65. uint32 TrxBuffSize;
  66. uint8 *pTrxBuff;
  67. } TrxMsgBuff;
  68. typedef enum {
  69. BAUD_RATE_DET,
  70. WAIT_SYNC_FRM,
  71. SRCH_MSG_HEAD,
  72. RCV_MSG_BODY,
  73. RCV_ESC_CHAR,
  74. } RcvMsgState;
  75. typedef struct {
  76. UartBautRate baut_rate;
  77. UartBitsNum4Char data_bits;
  78. UartExistParity exist_parity;
  79. UartParityMode parity; // chip size in byte
  80. UartStopBitsNum stop_bits;
  81. UartFlowCtrl flow_ctrl;
  82. RcvMsgBuff rcv_buff;
  83. TrxMsgBuff trx_buff;
  84. RcvMsgState rcv_state;
  85. int received;
  86. int buff_uart_no; //indicate which uart use tx/rx buffer
  87. } UartDevice;
  88. #define DISABLE_UART1 0
  89. #define ENABLE_UART1 1
  90. void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, bool enable_uart1);
  91. int uart0_rx_one_char();
  92. void uart0_send(const char *buf);
  93. #define uart0_sendStr uart0_send
  94. #endif