From a542e6f29122a4e880b371fc45b96c0cba56f0ac Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 9 Dec 2017 19:54:21 +0100 Subject: Framing experiments --- fw/main.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'fw/main.c') diff --git a/fw/main.c b/fw/main.c index 4ba6457..663f7a4 100644 --- a/fw/main.c +++ b/fw/main.c @@ -350,9 +350,12 @@ void uart_config(void) { static unsigned int overruns = 0; static unsigned int frame_overruns = 0; +#define SYNC_LENGTH 32 /* Must be a power of two */ void USART1_IRQHandler(void) { static uint8_t expect_framing = 1; static int rxpos = 0; + static int resync = SYNC_LENGTH+1; + static int sync_chars = 0; GPIOA->BSRR = GPIO_BSRR_BS_0; // Debug @@ -364,16 +367,27 @@ void USART1_IRQHandler(void) { USART1->ICR = USART_ICR_ORECF; } else { /* RXNE */ uint8_t data = USART1->RDR; - if (expect_framing) { + + if (data == 0x23) + sync_chars++; + else + sync_chars = 0; + + if (resync) { + if (sync_chars == SYNC_LENGTH+1) { + resync = 0; + } + } else if (expect_framing) { if (data == 0x42) { expect_framing = 0; } else { rxpos = 0; + resync = 1; } } else { rx_buf.byte_data[rxpos] = data; rxpos++; - if ((rxpos&0x1F) == 0) { + if ((rxpos&(SYNC_LENGTH-1)) == 0) { expect_framing = 1; } if (rxpos >= sizeof(rx_buf.set_fb_rq)) { @@ -524,6 +538,10 @@ int main(void) { led_state = (led_state+1)&7; } if (fb_op == FB_FORMAT) { + for (int i=0; i