-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix for #4565 (rx fifo length), protect access to rx_buffer #4568
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
Changes from 3 commits
9247bd0
7f0e690
982663d
9f2af3f
ec358a9
e40f5a8
0b6ea38
ebe5f4d
912536b
225e570
c0470bb
ae40588
c610910
6fa79ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ inline size_t uart_rx_buffer_available(uart_t* uart) { | |
} | ||
|
||
inline size_t uart_rx_fifo_available(uart_t* uart) { | ||
return (USS(uart->uart_nr) >> USRXC) & 0x7F; | ||
return (USS(uart->uart_nr) >> USRXC) & 0xFF; | ||
} | ||
|
||
const char overrun_str [] ICACHE_RODATA_ATTR STORE_ATTR = "uart input full!\r\n"; | ||
|
@@ -140,15 +140,17 @@ int uart_peek_char(uart_t* uart) | |
if(uart == NULL || !uart->rx_enabled) { | ||
return -1; | ||
} | ||
ETS_UART_INTR_DISABLE(); //access to rx_buffer can be interrupted by the isr (similar to a critical section), so disable interrupts here | ||
if (!uart_rx_available(uart)) { | ||
ETS_UART_INTR_ENABLE(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uart_rx_available() also conflictly calls INTR_DISABLE+ENABLE. Maybe adding a new static uart_rx_available_unprotected() would help (L82 too) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, this needs rework. |
||
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]; | ||
int ret = uart->rx_buffer->buffer[uart->rx_buffer->rpos]; | ||
ETS_UART_INTR_ENABLE(); | ||
return ret; | ||
} | ||
|
||
int uart_read_char(uart_t* uart) | ||
|
@@ -158,7 +160,9 @@ int uart_read_char(uart_t* uart) | |
} | ||
int data = uart_peek_char(uart); | ||
if(data != -1) { | ||
ETS_UART_INTR_DISABLE(); | ||
uart->rx_buffer->rpos = (uart->rx_buffer->rpos + 1) % uart->rx_buffer->size; | ||
ETS_UART_INTR_ENABLE(); | ||
} | ||
return data; | ||
} | ||
|
@@ -168,7 +172,11 @@ size_t uart_rx_available(uart_t* uart) | |
if(uart == NULL || !uart->rx_enabled) { | ||
return 0; | ||
} | ||
return uart_rx_buffer_available(uart) + uart_rx_fifo_available(uart); | ||
ETS_UART_INTR_DISABLE(); | ||
int uartrxbufferavailable = uart_rx_buffer_available(uart); | ||
ETS_UART_INTR_ENABLE(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, for more clarity, what about renaming |
||
|
||
return uartrxbufferavailable + uart_rx_fifo_available(uart); | ||
} | ||
|
||
|
||
|
@@ -186,7 +194,7 @@ void ICACHE_RAM_ATTR uart_isr(void * arg) | |
USIC(uart->uart_nr) = USIS(uart->uart_nr); | ||
} | ||
|
||
void uart_start_isr(uart_t* uart) | ||
static void uart_start_isr(uart_t* uart) | ||
{ | ||
if(uart == NULL || !uart->rx_enabled) { | ||
return; | ||
|
@@ -202,7 +210,7 @@ void uart_start_isr(uart_t* uart) | |
ETS_UART_INTR_ENABLE(); | ||
} | ||
|
||
void uart_stop_isr(uart_t* uart) | ||
static void uart_stop_isr(uart_t* uart) | ||
{ | ||
if(uart == NULL || !uart->rx_enabled) { | ||
return; | ||
|
@@ -383,6 +391,8 @@ void uart_uninit(uart_t* uart) | |
return; | ||
} | ||
|
||
uart_stop_isr(uart); | ||
|
||
switch(uart->rx_pin) { | ||
case 3: | ||
pinMode(3, INPUT); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment right next to uart_rx_copy_fifo_to_buffer(). For more clarity, I guess it could be renamed to uart_rx_copy_fifo_to_buffer_unprotected() too.