Host handshake mostly working
This commit is contained in:
parent
af15c38a05
commit
587ecdd72d
8 changed files with 94 additions and 26 deletions
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
volatile struct {
|
||||
struct dma_buf dma;
|
||||
uint8_t data[128];
|
||||
uint8_t data[256];
|
||||
} usart2_buf = { .dma = { .len = sizeof(usart2_buf.data) } };
|
||||
|
||||
struct dma_usart_file usart2_out_s = {
|
||||
|
|
@ -25,7 +25,15 @@ struct dma_usart_file usart2_out_s = {
|
|||
struct dma_usart_file *usart2_out = &usart2_out_s;
|
||||
|
||||
void dma1_stream6_isr(void) {
|
||||
dma_clear_interrupt_flags(usart2_out->dma, usart2_out->stream, DMA_TCIF);
|
||||
if (dma_get_interrupt_flag(usart2_out->dma, usart2_out->stream, DMA_FEIF)) {
|
||||
/* Ignore FIFO errors as they're 100% non-critical for UART applications */
|
||||
dma_clear_interrupt_flags(usart2_out->dma, usart2_out->stream, DMA_FEIF);
|
||||
LOG_PRINTF("USART2 DMA FIFO error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Transfer complete interrupt */
|
||||
dma_clear_interrupt_flags(usart2_out->dma, usart2_out->stream, DMA_TCIF);
|
||||
|
||||
if (usart2_out->buf->wr_pos != usart2_out->buf->xfr_end) /* buffer not empty */
|
||||
schedule_dma(usart2_out);
|
||||
|
|
@ -37,6 +45,7 @@ void usart2_isr(void) {
|
|||
LOG_PRINTF("USART2 data register overrun\n");
|
||||
/* Clear interrupt flag */
|
||||
(void)USART2_DR; /* FIXME make sure this read is not optimized out */
|
||||
host_packet_length = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -44,14 +53,19 @@ void usart2_isr(void) {
|
|||
|
||||
if (host_packet_length) {
|
||||
LOG_PRINTF("USART2 COBS buffer overrun\n");
|
||||
host_packet_length = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
ssize_t rv = cobs_decode_incremental(&host_cobs_state, (char *)host_packet_buf, sizeof(host_packet_buf), data);
|
||||
if (rv == -2) {
|
||||
LOG_PRINTF("Host interface COBS packet too large\n");
|
||||
host_packet_length = -1;
|
||||
} else if (rv == -3) {
|
||||
LOG_PRINTF("Got double null byte from host\n");
|
||||
} else if (rv < 0) {
|
||||
LOG_PRINTF("Host interface COBS framing error\n");
|
||||
host_packet_length = -1;
|
||||
} else if (rv > 0) {
|
||||
host_packet_length = rv;
|
||||
} /* else just return and wait for next byte */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue