Skip to content

Rx fifo latency fix #4328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 8, 2018
Merged
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2400e74
Add a new resetmethod_menu_all macro to give the choice of all the re…
mribble Jan 25, 2018
8fe2727
Change reset menu from all to extra. This gets rid of duplicated code
mribble Jan 26, 2018
666de32
Merge with upstream
mribble Feb 8, 2018
0cb9617
Fix boards.txt
mribble Feb 8, 2018
a4e1b91
Flush the rx fifo when checking available bytes in fifo. This gives …
mribble Feb 8, 2018
0e04ea3
Merge branch 'master' into rx-fifo-latency-fix
devyte Feb 8, 2018
42d4cb3
Merge branch 'master' of https://github.com/esp8266/Arduino
mribble Feb 8, 2018
f23c4b0
Merge branch 'master' of https://github.com/mribble/Arduino-1 into rx…
mribble Feb 8, 2018
aa16f80
Merge branch 'rx-fifo-latency-fix' of https://github.com/mribble/Ardu…
mribble Feb 8, 2018
d1d17d2
When rx_avaiable is checked return rx_buffer plus rx_fifo. Then duri…
mribble Feb 8, 2018
f4a62c0
Clean up early out case.
mribble Feb 9, 2018
7d4f7e0
Merge branch 'master' into rx-fifo-latency-fix
mribble Feb 14, 2018
0d3d43f
Merge branch 'master' of https://github.com/esp8266/Arduino into rx-f…
mribble Feb 14, 2018
001be65
Merge branch 'rx-fifo-latency-fix' of https://github.com/mribble/Ardu…
mribble Feb 14, 2018
e97a9fa
Merge branch 'master' of https://github.com/esp8266/Arduino into rx-f…
mribble Feb 14, 2018
c527a76
Set the rx full fifo ISR to trigger a little sooner. This makes the …
mribble Feb 14, 2018
ff7983f
Merge branch 'master' into rx-fifo-latency-fix
devyte Mar 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions cores/esp8266/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ size_t uart_resize_rx_buffer(uart_t* uart, size_t new_size)
return uart->rx_buffer->size;
}

inline size_t uart_rx_buffer_available(uart_t* uart) {
if(uart->rx_buffer->wpos < uart->rx_buffer->rpos) {
return (uart->rx_buffer->wpos + uart->rx_buffer->size) - uart->rx_buffer->rpos;
}
return uart->rx_buffer->wpos - uart->rx_buffer->rpos;
}

inline size_t uart_rx_fifo_available(uart_t* uart) {
return (USS(uart->uart_nr) >> USRXC) & 0x7F;
}

// Copy all the rx fifo bytes that fit into the rx buffer
inline void uart_rx_copy_fifo_to_buffer(uart_t* uart) {
while(uart_rx_fifo_available(uart)){
size_t nextPos = (uart->rx_buffer->wpos + 1) % uart->rx_buffer->size;
if(nextPos == uart->rx_buffer->rpos) {
// Stop copying if rx buffer is full
break;
}
uint8_t data = USF(uart->uart_nr);
uart->rx_buffer->buffer[uart->rx_buffer->wpos] = data;
uart->rx_buffer->wpos = nextPos;
}
}

int uart_peek_char(uart_t* uart)
{
if(uart == NULL || !uart->rx_enabled) {
Expand All @@ -99,6 +124,11 @@ int uart_peek_char(uart_t* uart)
if (!uart_rx_available(uart)) {
return -1;
}
if (uart_rx_buffer_available(uart) == 0) {
ETS_UART_INTR_DISABLE();
uart_rx_copy_fifo_to_buffer(uart);
ETS_UART_INTR_ENABLE();
}
return uart->rx_buffer->buffer[uart->rx_buffer->rpos];
}

Expand All @@ -119,10 +149,7 @@ size_t uart_rx_available(uart_t* uart)
if(uart == NULL || !uart->rx_enabled) {
return 0;
}
if(uart->rx_buffer->wpos < uart->rx_buffer->rpos) {
return (uart->rx_buffer->wpos + uart->rx_buffer->size) - uart->rx_buffer->rpos;
}
return uart->rx_buffer->wpos - uart->rx_buffer->rpos;
return uart_rx_buffer_available(uart) + uart_rx_fifo_available(uart);
}


Expand All @@ -135,14 +162,7 @@ void ICACHE_RAM_ATTR uart_isr(void * arg)
return;
}
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;
}
}
uart_rx_copy_fifo_to_buffer(uart);
}
USIC(uart->uart_nr) = USIS(uart->uart_nr);
}
Expand All @@ -152,7 +172,11 @@ void uart_start_isr(uart_t* uart)
if(uart == NULL || !uart->rx_enabled) {
return;
}
USC1(uart->uart_nr) = (127 << UCFFT) | (0x02 << UCTOT) | (1 <<UCTOE );
// UCFFT value is when the RX fifo full interrupt triggers. A value of 1
// triggers the IRS very often. A value of 127 would not leave much time
// for ISR to clear fifo before the next byte is dropped. So pick a value
// in the middle.
USC1(uart->uart_nr) = (100 << UCFFT) | (0x02 << UCTOT) | (1 <<UCTOE );
USIC(uart->uart_nr) = 0xffff;
USIE(uart->uart_nr) = (1 << UIFF) | (1 << UIFR) | (1 << UITO);
ETS_UART_INTR_ATTACH(uart_isr, (void *)uart);
Expand Down