uart.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. typedef struct {
  22. byte_queue_t tx_queue;
  23. c_buffer_t rx_queue;
  24. dma_channel_enum rx_dma_ch;
  25. dma_channel_enum tx_dma_ch;
  26. uint16_t tx_length;
  27. uint16_t tx_crc16;
  28. uint32_t uart_com;//uart device
  29. uint8_t rx_frame[256];
  30. uint16_t rx_length;
  31. bool escape;
  32. }shark_uart_t;
  33. void shark_uart_init(uart_enum_t uart_no);
  34. void shark_uart_deinit(uart_enum_t uart_no);
  35. void shark_uart_write_frame(uart_enum_t uart_no, uint8_t *bytes, int len);
  36. void shark_uart_frame_start(uart_enum_t uart_no, uint8_t *bytes, int len);
  37. void shark_uart_frame_continue(uart_enum_t uart_no, uint8_t *bytes, int len);
  38. void shark_uart_frame_end(uart_enum_t uart_no);
  39. void shark_uart_write_bytes(uart_enum_t uart_no, u8 *buff, u16 size);
  40. void shark_uart_flush(void);
  41. bool shark_uart_timeout(void);