mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
uart: Fix ticks_to_wait when 0 or expired
Closes: https://github.com/espressif/esp-idf/issues/3301 Closes: IDFGH-964
This commit is contained in:
parent
22a30e2740
commit
355f209dba
@ -1040,20 +1040,25 @@ esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait)
|
||||
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||
UART_CHECK((p_uart_obj[uart_num]), "uart driver error", ESP_FAIL);
|
||||
BaseType_t res;
|
||||
portTickType ticks_end = xTaskGetTickCount() + ticks_to_wait;
|
||||
portTickType ticks_start = xTaskGetTickCount();
|
||||
//Take tx_mux
|
||||
res = xSemaphoreTake(p_uart_obj[uart_num]->tx_mux, (portTickType)ticks_to_wait);
|
||||
if(res == pdFALSE) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
ticks_to_wait = ticks_end - xTaskGetTickCount();
|
||||
xSemaphoreTake(p_uart_obj[uart_num]->tx_done_sem, 0);
|
||||
ticks_to_wait = ticks_end - xTaskGetTickCount();
|
||||
if(UART[uart_num]->status.txfifo_cnt == 0) {
|
||||
xSemaphoreGive(p_uart_obj[uart_num]->tx_mux);
|
||||
return ESP_OK;
|
||||
}
|
||||
uart_enable_intr_mask(uart_num, UART_TX_DONE_INT_ENA_M);
|
||||
|
||||
TickType_t ticks_end = xTaskGetTickCount();
|
||||
if (ticks_end - ticks_start > ticks_to_wait) {
|
||||
ticks_to_wait = 0;
|
||||
} else {
|
||||
ticks_to_wait = ticks_to_wait - (ticks_end - ticks_start);
|
||||
}
|
||||
//take 2nd tx_done_sem, wait given from ISR
|
||||
res = xSemaphoreTake(p_uart_obj[uart_num]->tx_done_sem, (portTickType)ticks_to_wait);
|
||||
if(res == pdFALSE) {
|
||||
|
Loading…
Reference in New Issue
Block a user