uart.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #define SHARK_UART_TX_MEM_SIZE (22 * 1024)
  13. #define SHARK_UART_RX_MEM_SIZE 512
  14. #define RX_FRAME_MAX_LEN 260
  15. #define RX_OLD_FRAME_MAX_LEN 256
  16. typedef enum {
  17. SHARK_UART0 = 0,
  18. SHARK_UART1,
  19. SHARK_UART2,
  20. SHARK_UART3,
  21. SHARK_UART4,
  22. SHARK_UART_COUNT
  23. } uart_enum_t;
  24. typedef struct {
  25. byte_queue_t tx_queue;
  26. c_buffer_t rx_queue;
  27. dma_channel_enum rx_dma_ch;
  28. dma_channel_enum tx_dma_ch;
  29. uint16_t tx_length;
  30. uint16_t tx_crc16;
  31. uint32_t uart_com;//uart device
  32. uint8_t rx_frame[RX_FRAME_MAX_LEN];
  33. uint16_t rx_length;
  34. bool escape;
  35. bool start;
  36. bool uart_no_data;
  37. }shark_uart_t;
  38. void shark_uart_init(uart_enum_t uart_no);
  39. void shark_uart_deinit(uart_enum_t uart_no);
  40. void shark_uart_write_frame(uart_enum_t uart_no, uint8_t *bytes, int len);
  41. void shark_uart_frame_start(uart_enum_t uart_no, uint8_t *bytes, int len);
  42. void shark_uart_frame_continue(uart_enum_t uart_no, uint8_t *bytes, int len);
  43. void shark_uart_frame_end(uart_enum_t uart_no);
  44. void shark_uart_write_bytes(uart_enum_t uart_no, u8 *buff, u16 size);
  45. void shark_uart_flush(void);
  46. bool shark_uart_timeout(void);
  47. void shark_uart_log(void);