forked from espressif/esp-idf
fix(uart): fix send_size calculation in uart_write_bytes
MIN() macro is only an expansion of a conditional operator. xRingbufferGetCurFreeSize was called twice in the original code, which may return different values in two calls, leading to incorrect send_size calculation and eventually could trigger task watchdog.
This commit is contained in:
@@ -1638,7 +1638,8 @@ static int uart_tx_all(uart_port_t uart_num, const char *src, size_t size, bool
|
||||
}
|
||||
xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *) &evt, sizeof(uart_tx_data_t), portMAX_DELAY);
|
||||
while (size > 0) {
|
||||
size_t send_size = MIN(size, xRingbufferGetCurFreeSize(p_uart_obj[uart_num]->tx_ring_buf));
|
||||
size_t free_size = xRingbufferGetCurFreeSize(p_uart_obj[uart_num]->tx_ring_buf);
|
||||
size_t send_size = MIN(size, free_size);
|
||||
if (send_size > 0) {
|
||||
xRingbufferSend(p_uart_obj[uart_num]->tx_ring_buf, (void *)(src + offset), send_size, portMAX_DELAY);
|
||||
size -= send_size;
|
||||
|
||||
Reference in New Issue
Block a user