Skip to content

Commit 8cd331a

Browse files
authored
optimize uart rx isr and lower fifo full treshold (esp8266#2355)
1 parent 0718188 commit 8cd331a

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

cores/esp8266/uart.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -127,39 +127,21 @@ void ICACHE_RAM_ATTR uart_isr(void * arg)
127127
{
128128
uart_t* uart = (uart_t*)arg;
129129
if(uart == NULL || !uart->rx_enabled) {
130-
USIC(uart->uart_nr) = 0xffff;
130+
USIC(uart->uart_nr) = USIS(uart->uart_nr);
131131
ETS_UART_INTR_DISABLE();
132132
return;
133133
}
134-
135-
uint32_t int_status = USIS(uart->uart_nr);
136-
137-
if(int_status & (1 << UIFR)) {
138-
USIC(uart->uart_nr) = (1 << UIFR);//clear any frame error
139-
}
140-
141-
if(int_status & (1 << UIFF) || int_status & (1 << UITO)){
142-
ETS_UART_INTR_DISABLE();
143-
while(((USS(uart->uart_nr) >> USRXC) & 0x7F) != 0){
134+
if(USIS(uart->uart_nr) & ((1 << UIFF) | (1 << UITO))){
135+
while((USS(uart->uart_nr) >> USRXC) & 0x7F){
144136
uint8_t data = USF(uart->uart_nr);
145137
size_t nextPos = (uart->rx_buffer->wpos + 1) % uart->rx_buffer->size;
146138
if(nextPos != uart->rx_buffer->rpos) {
147139
uart->rx_buffer->buffer[uart->rx_buffer->wpos] = data;
148140
uart->rx_buffer->wpos = nextPos;
149-
} else {
150-
//rx buffer OverFlow
151-
//maybe stop the loop and try later?
152141
}
153142
}
154-
int_status = USIS(uart->uart_nr);
155-
if(int_status & (1 << UIFF)) {
156-
USIC(uart->uart_nr) = (1 << UIFF);//clear any FIFO FULL error
157-
}
158-
if(int_status & (1 << UITO)) {
159-
USIC(uart->uart_nr) = (1 << UITO);//clear any TimeOut error
160-
}
161-
ETS_UART_INTR_ENABLE();
162143
}
144+
USIC(uart->uart_nr) = USIS(uart->uart_nr);
163145
}
164146

165147
void uart_start_isr(uart_t* uart)

0 commit comments

Comments
 (0)