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