From 762381237d04c0710fa24ff984a17268e979310e Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sat, 15 Aug 2020 11:01:26 +0200 Subject: [PATCH] no inline --- armsrc/usart.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/armsrc/usart.c b/armsrc/usart.c index 203572f90..b6ed97310 100644 --- a/armsrc/usart.c +++ b/armsrc/usart.c @@ -51,25 +51,32 @@ static size_t us_rxfifo_high = 0; static void usart_fill_rxfifo(void) { uint16_t rxfifo_free ; if (pUS1->US_RNCR == 0) { // One buffer got filled, backup buffer being used + if (us_rxfifo_low > us_rxfifo_high) rxfifo_free = us_rxfifo_low - us_rxfifo_high; else rxfifo_free = sizeof(us_rxfifo) - us_rxfifo_high + us_rxfifo_low; + uint16_t available = USART_BUFFLEN - usart_cur_inbuf_off; + if (available <= rxfifo_free) { + for (uint16_t i = 0; i < available; i++) { us_rxfifo[us_rxfifo_high++] = usart_cur_inbuf[usart_cur_inbuf_off + i]; if (us_rxfifo_high == sizeof(us_rxfifo)) us_rxfifo_high = 0; } + // Give next buffer pUS1->US_RNPR = (uint32_t)usart_cur_inbuf; pUS1->US_RNCR = USART_BUFFLEN; + // Swap current buff if (usart_cur_inbuf == us_inbuf1) usart_cur_inbuf = us_inbuf2; else usart_cur_inbuf = us_inbuf1; + usart_cur_inbuf_off = 0; } else { // Take only what we have room for @@ -83,12 +90,16 @@ static void usart_fill_rxfifo(void) { return; } } + if (pUS1->US_RCR < USART_BUFFLEN - usart_cur_inbuf_off) { // Current buffer partially filled + if (us_rxfifo_low > us_rxfifo_high) rxfifo_free = us_rxfifo_low - us_rxfifo_high; else rxfifo_free = sizeof(us_rxfifo) - us_rxfifo_high + us_rxfifo_low; + uint16_t available = USART_BUFFLEN - pUS1->US_RCR - usart_cur_inbuf_off; + if (available > rxfifo_free) available = rxfifo_free; for (uint16_t i = 0; i < available; i++) { @@ -150,7 +161,7 @@ uint32_t usart_read_ng(uint8_t *data, size_t len) { } // transfer from device to client -inline int usart_writebuffer_sync(uint8_t *data, size_t len) { +int usart_writebuffer_sync(uint8_t *data, size_t len) { // Wait for current PDC bank to be free // (and check next bank too, in case there will be a usart_writebuffer_async)