serial.h 674 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef _SERIAL_H__
  2. #define _SERIAL_H__
  3. #include "libs/types.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 RX_FRAME_MAX_LEN 130
  12. typedef struct {
  13. u8 tx_buf[128];
  14. u8 rx_buf[128];
  15. c_buffer_t c_tx_buff;
  16. c_buffer_t c_rx_buff;
  17. c_buffer_t rx_queue;
  18. uint16_t tx_length;
  19. uint16_t tx_crc16;
  20. uint8_t rx_frame[RX_FRAME_MAX_LEN];
  21. uint16_t rx_length;
  22. bool escape;
  23. }uart_t;
  24. void serial_init(void);
  25. void serial_write(u8 *data, int len);
  26. void uart_write_frame(uint8_t *bytes, int len);
  27. #endif /* _SERIAL_H__ */