uart.h 1.4 KB

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