mirror of
https://github.com/espressif/esp-idf
synced 2025-04-02 04:40:11 -04:00
Merge branch 'bugfix/add_critical_section_in_uart_driver_v4.2' into 'release/v4.2'
UART: add missing critical section wrappers around rx_buffered_len (backport v4.2) See merge request espressif/esp-idf!14775
This commit is contained in:
commit
f65845ef51
@ -210,7 +210,9 @@ esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bit)
|
|||||||
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bit)
|
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bit)
|
||||||
{
|
{
|
||||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||||
|
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
uart_hal_get_stop_bits(&(uart_context[uart_num].hal), stop_bit);
|
uart_hal_get_stop_bits(&(uart_context[uart_num].hal), stop_bit);
|
||||||
|
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +228,9 @@ esp_err_t uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode)
|
|||||||
esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode)
|
esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode)
|
||||||
{
|
{
|
||||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||||
|
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
uart_hal_get_parity(&(uart_context[uart_num].hal), parity_mode);
|
uart_hal_get_parity(&(uart_context[uart_num].hal), parity_mode);
|
||||||
|
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1210,7 +1214,9 @@ esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size)
|
|||||||
{
|
{
|
||||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||||
UART_CHECK((p_uart_obj[uart_num]), "uart driver error", ESP_FAIL);
|
UART_CHECK((p_uart_obj[uart_num]), "uart driver error", ESP_FAIL);
|
||||||
|
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
*size = p_uart_obj[uart_num]->rx_buffered_len;
|
*size = p_uart_obj[uart_num]->rx_buffered_len;
|
||||||
|
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1240,14 +1246,19 @@ esp_err_t uart_flush_input(uart_port_t uart_num)
|
|||||||
}
|
}
|
||||||
data = (uint8_t*) xRingbufferReceive(p_uart->rx_ring_buf, &size, (portTickType) 0);
|
data = (uint8_t*) xRingbufferReceive(p_uart->rx_ring_buf, &size, (portTickType) 0);
|
||||||
if(data == NULL) {
|
if(data == NULL) {
|
||||||
|
bool error = false;
|
||||||
|
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
if( p_uart_obj[uart_num]->rx_buffered_len != 0 ) {
|
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;
|
p_uart_obj[uart_num]->rx_buffered_len = 0;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
//We also need to clear the `rx_buffer_full_flg` here.
|
//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;
|
p_uart_obj[uart_num]->rx_buffer_full_flg = false;
|
||||||
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
|
if (error) {
|
||||||
|
// this must be called outside the critical section
|
||||||
|
ESP_LOGE(UART_TAG, "rx_buffered_len error");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user