uart.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #define RX_BUFF_SIZE 0x100
  7. #define TX_BUFF_SIZE 100
  8. typedef enum {
  9. FIVE_BITS = 0x0,
  10. SIX_BITS = 0x1,
  11. SEVEN_BITS = 0x2,
  12. EIGHT_BITS = 0x3
  13. } UartBitsNum4Char;
  14. typedef enum {
  15. ONE_STOP_BIT = 0,
  16. ONE_HALF_STOP_BIT = BIT2,
  17. TWO_STOP_BIT = BIT2
  18. } UartStopBitsNum;
  19. typedef enum {
  20. NONE_BITS = 0,
  21. ODD_BITS = 0,
  22. EVEN_BITS = BIT4
  23. } UartParityMode;
  24. typedef enum {
  25. STICK_PARITY_DIS = 0,
  26. STICK_PARITY_EN = BIT3 | BIT5
  27. } UartExistParity;
  28. typedef enum {
  29. BIT_RATE_9600 = 9600,
  30. BIT_RATE_19200 = 19200,
  31. BIT_RATE_38400 = 38400,
  32. BIT_RATE_57600 = 57600,
  33. BIT_RATE_74880 = 74880,
  34. BIT_RATE_115200 = 115200,
  35. BIT_RATE_230400 = 230400,
  36. BIT_RATE_460800 = 460800,
  37. BIT_RATE_921600 = 921600
  38. } UartBautRate;
  39. typedef enum {
  40. NONE_CTRL,
  41. HARDWARE_CTRL,
  42. XON_XOFF_CTRL
  43. } UartFlowCtrl;
  44. typedef enum {
  45. EMPTY,
  46. UNDER_WRITE,
  47. WRITE_OVER
  48. } RcvMsgBuffState;
  49. typedef struct {
  50. uint32 RcvBuffSize;
  51. uint8 *pRcvMsgBuff;
  52. uint8 *pWritePos;
  53. uint8 *pReadPos;
  54. uint8 TrigLvl; //JLU: may need to pad
  55. RcvMsgBuffState BuffState;
  56. } RcvMsgBuff;
  57. typedef struct {
  58. uint32 TrxBuffSize;
  59. uint8 *pTrxBuff;
  60. } TrxMsgBuff;
  61. typedef enum {
  62. BAUD_RATE_DET,
  63. WAIT_SYNC_FRM,
  64. SRCH_MSG_HEAD,
  65. RCV_MSG_BODY,
  66. RCV_ESC_CHAR,
  67. } RcvMsgState;
  68. typedef struct {
  69. UartBautRate baut_rate;
  70. UartBitsNum4Char data_bits;
  71. UartExistParity exist_parity;
  72. UartParityMode parity; // chip size in byte
  73. UartStopBitsNum stop_bits;
  74. UartFlowCtrl flow_ctrl;
  75. RcvMsgBuff rcv_buff;
  76. TrxMsgBuff trx_buff;
  77. RcvMsgState rcv_state;
  78. int received;
  79. int buff_uart_no; //indicate which uart use tx/rx buffer
  80. } UartDevice;
  81. void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
  82. void uart0_sendStr(const char *str);
  83. void uart0_putc(const char c);
  84. void uart0_tx_buffer(uint8 *buf, uint16 len);
  85. void uart_setup(uint8 uart_no);
  86. STATUS uart_tx_one_char(uint8 uart, uint8 TxChar);
  87. #endif