Skip to content

Commit

Permalink
Merge branch 'feature/uart_get_free_tx_buffer_size_v4.4' into 'releas…
Browse files Browse the repository at this point in the history
…e/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
  • Loading branch information
jack0c committed Jul 13, 2022
2 parents bd72694 + f4d33d2 commit dfb75aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/driver/include/driver/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,18 @@ esp_err_t uart_flush_input(uart_port_t uart_num);
*/
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size);

/**
* @brief UART get TX ring buffer free space size
*
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
* @param size Pointer of size_t to accept the free space size
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t uart_get_tx_buffer_free_size(uart_port_t uart_num, size_t *size);

/**
* @brief UART disable pattern detect function.
* Designed for applications like 'AT commands'.
Expand Down
9 changes: 9 additions & 0 deletions components/driver/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,15 @@ esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
return ESP_OK;
}

esp_err_t uart_get_tx_buffer_free_size(uart_port_t uart_num, size_t *size)
{
ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_ERR_INVALID_ARG, UART_TAG, "uart_num error");
ESP_RETURN_ON_FALSE((p_uart_obj[uart_num]), ESP_ERR_INVALID_ARG, UART_TAG, "uart driver error");
ESP_RETURN_ON_FALSE((size != NULL), ESP_ERR_INVALID_ARG, UART_TAG, "arg pointer is NULL");
*size = p_uart_obj[uart_num]->tx_buf_size - p_uart_obj[uart_num]->tx_len_tot;
return ESP_OK;
}

esp_err_t uart_flush(uart_port_t uart_num) __attribute__((alias("uart_flush_input")));

esp_err_t uart_flush_input(uart_port_t uart_num)
Expand Down

0 comments on commit dfb75aa

Please sign in to comment.