mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
VFS: Check in select() if the UART driver is installed or not
Closes https://github.com/espressif/esp-idf/issues/4627
This commit is contained in:
parent
55834dd001
commit
642dc19c25
@ -155,6 +155,17 @@ typedef struct {
|
||||
|
||||
typedef intr_handle_t uart_isr_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Checks whether the driver is installed or not
|
||||
*
|
||||
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||
*
|
||||
* @return
|
||||
* - true driver is installed
|
||||
* - false driver is not installed
|
||||
*/
|
||||
bool uart_is_driver_installed(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief Set UART data bits.
|
||||
*
|
||||
|
@ -1485,6 +1485,11 @@ esp_err_t uart_driver_delete(uart_port_t uart_num)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool uart_is_driver_installed(uart_port_t uart_num)
|
||||
{
|
||||
return uart_num < UART_NUM_MAX && (p_uart_obj[uart_num] != NULL);
|
||||
}
|
||||
|
||||
void uart_set_select_notif_callback(uart_port_t uart_num, uart_select_notif_callback_t uart_select_notif_callback)
|
||||
{
|
||||
if (uart_num < UART_NUM_MAX && p_uart_obj[uart_num]) {
|
||||
|
@ -420,6 +420,14 @@ static esp_err_t uart_start_select(int nfds, fd_set *readfds, fd_set *writefds,
|
||||
const int max_fds = MIN(nfds, UART_NUM);
|
||||
*end_select_args = NULL;
|
||||
|
||||
for (int i = 0; i < max_fds; ++i) {
|
||||
if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exceptfds)) {
|
||||
if (!uart_is_driver_installed(i)) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uart_select_args_t *args = malloc(sizeof(uart_select_args_t));
|
||||
|
||||
if (args == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user