From 8cd331a8bae04a6f1443ff0c93539af4720d8ddf Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Mon, 1 Aug 2016 12:34:32 +0300 Subject: [PATCH] optimize uart rx isr and lower fifo full treshold (#2355) --- cores/esp8266/uart.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/cores/esp8266/uart.c b/cores/esp8266/uart.c index 104a61570..375381e7e 100644 --- a/cores/esp8266/uart.c +++ b/cores/esp8266/uart.c @@ -127,39 +127,21 @@ void ICACHE_RAM_ATTR uart_isr(void * arg) { uart_t* uart = (uart_t*)arg; if(uart == NULL || !uart->rx_enabled) { - USIC(uart->uart_nr) = 0xffff; + USIC(uart->uart_nr) = USIS(uart->uart_nr); ETS_UART_INTR_DISABLE(); return; } - - uint32_t int_status = USIS(uart->uart_nr); - - if(int_status & (1 << UIFR)) { - USIC(uart->uart_nr) = (1 << UIFR);//clear any frame error - } - - if(int_status & (1 << UIFF) || int_status & (1 << UITO)){ - ETS_UART_INTR_DISABLE(); - while(((USS(uart->uart_nr) >> USRXC) & 0x7F) != 0){ + if(USIS(uart->uart_nr) & ((1 << UIFF) | (1 << UITO))){ + while((USS(uart->uart_nr) >> USRXC) & 0x7F){ uint8_t data = USF(uart->uart_nr); size_t nextPos = (uart->rx_buffer->wpos + 1) % uart->rx_buffer->size; if(nextPos != uart->rx_buffer->rpos) { uart->rx_buffer->buffer[uart->rx_buffer->wpos] = data; uart->rx_buffer->wpos = nextPos; - } else { - //rx buffer OverFlow - //maybe stop the loop and try later? } } - int_status = USIS(uart->uart_nr); - if(int_status & (1 << UIFF)) { - USIC(uart->uart_nr) = (1 << UIFF);//clear any FIFO FULL error - } - if(int_status & (1 << UITO)) { - USIC(uart->uart_nr) = (1 << UITO);//clear any TimeOut error - } - ETS_UART_INTR_ENABLE(); } + USIC(uart->uart_nr) = USIS(uart->uart_nr); } void uart_start_isr(uart_t* uart)