diff options
Diffstat (limited to 'gm_platform/fw/serial.h')
-rw-r--r-- | gm_platform/fw/serial.h | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/gm_platform/fw/serial.h b/gm_platform/fw/serial.h index c10393a..39ffd18 100644 --- a/gm_platform/fw/serial.h +++ b/gm_platform/fw/serial.h @@ -27,19 +27,46 @@ #include <stdarg.h>
#include <errno.h>
+#include "global.h"
+
struct dma_tx_buf {
- size_t xfr_start; /* Start index of running DMA transfer */
- size_t xfr_end; /* End index of running DMA transfer plus one */
- size_t wr_pos; /* Next index to be written */
+ /* The following fields are accessed only from DMA ISR */
+ ssize_t xfr_start; /* Start index of running DMA transfer */
+ ssize_t xfr_end; /* End index of running DMA transfer plus one */
+ uint8_t cur_packet;
+
+ /* The following fields are written only from non-interrupt code */
+ ssize_t wr_pos; /* Next index to be written */
+ ssize_t packet_start[8];
+
+ /* The following may be accessed by anything */
uint8_t data[512];
- size_t packet_starts[5];
+};
+
+struct __attribute__((__packed__)) ll_pkt {
+ uint32_t crc32;
+ /* CRC computed over entire packet starting here */
+ uint8_t pid;
+ uint8_t _pad;
+ uint8_t data[];
+};
+
+enum ctrl_pkt_type {
+ CTRL_PKT_RESET = 1,
+ CTRL_PKT_ACK = 2,
+ CTRL_PKT_RETRANSMIT = 3,
+};
+
+struct __attribute__((__packed__)) ctrl_pkt {
+ uint8_t type;
+ uint8_t orig_id;
};
extern volatile struct dma_tx_buf usart_tx_buf;
void usart_dma_init(void);
-int usart_dma_fifo_push(volatile struct dma_tx_buf *buf, char c);
-void usart_send_packet(const uint8_t *data, size_t len);
-int usart_send_packet_nonblocking(const uint8_t *data, size_t len);
+int usart_dma_fifo_push(volatile struct dma_tx_buf *buf, uint8_t c);
+int usart_send_packet_nonblocking(struct ll_pkt *pkt, size_t pkt_len);
+int usart_ack_packet(uint8_t idx);
#endif // __SERIAL_H__
|