diff --git a/components/driver/uart.c b/components/driver/uart.c index 60ecb1ef19..128a0781ba 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -1208,9 +1208,16 @@ int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickTyp esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size) { +<<<<<<< HEAD UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL); UART_CHECK((p_uart_obj[uart_num]), "uart driver error", ESP_FAIL); +======= + ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_FAIL, UART_TAG, "uart_num error"); + ESP_RETURN_ON_FALSE((p_uart_obj[uart_num]), ESP_FAIL, UART_TAG, "uart driver error"); + UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); +>>>>>>> e41e67f2f1... uart: Add missing critical section wrappers around rx_buffered_len *size = p_uart_obj[uart_num]->rx_buffered_len; + UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); return ESP_OK; } @@ -1240,12 +1247,15 @@ esp_err_t uart_flush_input(uart_port_t uart_num) } data = (uint8_t*) xRingbufferReceive(p_uart->rx_ring_buf, &size, (portTickType) 0); if(data == NULL) { + UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); if( p_uart_obj[uart_num]->rx_buffered_len != 0 ) { - ESP_LOGE(UART_TAG, "rx_buffered_len error"); p_uart_obj[uart_num]->rx_buffered_len = 0; + UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); + // this must be called outside the critical section + ESP_LOGE(UART_TAG, "rx_buffered_len error"); + UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); } //We also need to clear the `rx_buffer_full_flg` here. - UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock)); p_uart_obj[uart_num]->rx_buffer_full_flg = false; UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock)); break;