Skip to content

Commit dfb75aa

Browse files
committed
Merge branch 'feature/uart_get_free_tx_buffer_size_v4.4' into 'release/v4.4'
uart: Add a new API to get the free space size of tx buffer (backport v4.4) See merge request espressif/esp-idf!18977
2 parents bd72694 + f4d33d2 commit dfb75aa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

components/driver/include/driver/uart.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,18 @@ esp_err_t uart_flush_input(uart_port_t uart_num);
594594
*/
595595
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size);
596596

597+
/**
598+
* @brief UART get TX ring buffer free space size
599+
*
600+
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
601+
* @param size Pointer of size_t to accept the free space size
602+
*
603+
* @return
604+
* - ESP_OK Success
605+
* - ESP_ERR_INVALID_ARG Parameter error
606+
*/
607+
esp_err_t uart_get_tx_buffer_free_size(uart_port_t uart_num, size_t *size);
608+
597609
/**
598610
* @brief UART disable pattern detect function.
599611
* Designed for applications like 'AT commands'.

components/driver/uart.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,15 @@ esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
13431343
return ESP_OK;
13441344
}
13451345

1346+
esp_err_t uart_get_tx_buffer_free_size(uart_port_t uart_num, size_t *size)
1347+
{
1348+
ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_ERR_INVALID_ARG, UART_TAG, "uart_num error");
1349+
ESP_RETURN_ON_FALSE((p_uart_obj[uart_num]), ESP_ERR_INVALID_ARG, UART_TAG, "uart driver error");
1350+
ESP_RETURN_ON_FALSE((size != NULL), ESP_ERR_INVALID_ARG, UART_TAG, "arg pointer is NULL");
1351+
*size = p_uart_obj[uart_num]->tx_buf_size - p_uart_obj[uart_num]->tx_len_tot;
1352+
return ESP_OK;
1353+
}
1354+
13461355
esp_err_t uart_flush(uart_port_t uart_num) __attribute__((alias("uart_flush_input")));
13471356

13481357
esp_err_t uart_flush_input(uart_port_t uart_num)

0 commit comments

Comments
 (0)