uart.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "bsp/bsp.h"
  3. #include "os/os_task.h"
  4. #include "libs/byte_queue.h"
  5. #include "libs/circle_buffer.h"
  6. #define CH_START 0xF5
  7. #define CH_END 0xF6
  8. #define CH_ESC 0xF7
  9. #define CH_ESC_START 0x05
  10. #define CH_ESC_END 0x06
  11. #define CH_ESC_ESC 0x07
  12. #if (CONFIG_MC105_HW_VERSION==2)
  13. #define SHARK_UART_TX_MEM_SIZE (256)
  14. #define SHARK_UART_RX_MEM_SIZE 256
  15. #else
  16. #define SHARK_UART_TX_MEM_SIZE (5 * 1024)
  17. #define SHARK_UART_RX_MEM_SIZE 512
  18. #endif
  19. #define RX_FRAME_MAX_LEN 260
  20. #define RX_OLD_FRAME_MAX_LEN 256
  21. typedef enum {
  22. SHARK_UART0 = 0,
  23. SHARK_UART1,
  24. SHARK_UART2,
  25. SHARK_UART3,
  26. SHARK_UART4,
  27. SHARK_UART_COUNT
  28. } uart_enum_t;
  29. typedef struct {
  30. byte_queue_t tx_queue;
  31. c_buffer_t rx_queue;
  32. dma_channel_enum rx_dma_ch;
  33. dma_channel_enum tx_dma_ch;
  34. uint16_t tx_length;
  35. uint16_t tx_crc16;
  36. uint32_t uart_com;//uart device
  37. uint8_t rx_frame[RX_FRAME_MAX_LEN];
  38. uint16_t rx_length;
  39. bool escape;
  40. bool start;
  41. bool uart_no_data;
  42. }shark_uart_t;
  43. void shark_uart_init(uart_enum_t uart_no);
  44. void shark_uart_deinit(uart_enum_t uart_no);
  45. void shark_uart_write_frame(uart_enum_t uart_no, uint8_t *bytes, int len);
  46. void shark_uart_frame_start(uart_enum_t uart_no, uint8_t *bytes, int len);
  47. void shark_uart_frame_continue(uart_enum_t uart_no, uint8_t *bytes, int len);
  48. void shark_uart_frame_end(uart_enum_t uart_no);
  49. void shark_uart_write_bytes(uart_enum_t uart_no, u8 *buff, u16 size);
  50. void shark_uart_flush(void);
  51. bool shark_uart_timeout(void);
  52. void shark_uart_log(void);