mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-05 04:15:21 +02:00
Allow VFS file descriptors in select()
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "soc/uart_struct.h"
|
||||
#include "driver/uart.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "driver/uart_select.h"
|
||||
|
||||
#define XOFF (char)0x13
|
||||
#define XON (char)0x11
|
||||
@@ -100,12 +101,14 @@ typedef struct {
|
||||
uint8_t tx_brk_flg; /*!< Flag to indicate to send a break signal in the end of the item sending procedure */
|
||||
uint8_t tx_brk_len; /*!< TX break signal cycle length/number */
|
||||
uint8_t tx_waiting_brk; /*!< Flag to indicate that TX FIFO is ready to send break signal after FIFO is empty, do not push data into TX FIFO right now.*/
|
||||
uart_select_notif_callback_t uart_select_notif_callback; /*!< Notification about select() events */
|
||||
} uart_obj_t;
|
||||
|
||||
static uart_obj_t *p_uart_obj[UART_NUM_MAX] = {0};
|
||||
/* DRAM_ATTR is required to avoid UART array placed in flash, due to accessed from ISR */
|
||||
static DRAM_ATTR uart_dev_t* const UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2};
|
||||
static portMUX_TYPE uart_spinlock[UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED};
|
||||
static portMUX_TYPE uart_selectlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)
|
||||
{
|
||||
@@ -831,6 +834,11 @@ static void uart_rx_intr_handler_default(void *param)
|
||||
uart_clear_intr_status(uart_num, UART_RXFIFO_TOUT_INT_CLR_M | UART_RXFIFO_FULL_INT_CLR_M);
|
||||
uart_event.type = UART_DATA;
|
||||
uart_event.size = rx_fifo_len;
|
||||
UART_ENTER_CRITICAL_ISR(&uart_selectlock);
|
||||
if (p_uart->uart_select_notif_callback) {
|
||||
p_uart->uart_select_notif_callback(uart_num, UART_SELECT_READ_NOTIF, &HPTaskAwoken);
|
||||
}
|
||||
UART_EXIT_CRITICAL_ISR(&uart_selectlock);
|
||||
}
|
||||
p_uart->rx_stash_len = rx_fifo_len;
|
||||
//If we fail to push data to ring buffer, we will have to stash the data, and send next time.
|
||||
@@ -889,15 +897,30 @@ static void uart_rx_intr_handler_default(void *param)
|
||||
uart_reg->int_clr.rxfifo_ovf = 1;
|
||||
UART_EXIT_CRITICAL_ISR(&uart_spinlock[uart_num]);
|
||||
uart_event.type = UART_FIFO_OVF;
|
||||
UART_ENTER_CRITICAL_ISR(&uart_selectlock);
|
||||
if (p_uart->uart_select_notif_callback) {
|
||||
p_uart->uart_select_notif_callback(uart_num, UART_SELECT_ERROR_NOTIF, &HPTaskAwoken);
|
||||
}
|
||||
UART_EXIT_CRITICAL_ISR(&uart_selectlock);
|
||||
} else if(uart_intr_status & UART_BRK_DET_INT_ST_M) {
|
||||
uart_reg->int_clr.brk_det = 1;
|
||||
uart_event.type = UART_BREAK;
|
||||
} else if(uart_intr_status & UART_FRM_ERR_INT_ST_M) {
|
||||
uart_reg->int_clr.frm_err = 1;
|
||||
uart_event.type = UART_FRAME_ERR;
|
||||
UART_ENTER_CRITICAL_ISR(&uart_selectlock);
|
||||
if (p_uart->uart_select_notif_callback) {
|
||||
p_uart->uart_select_notif_callback(uart_num, UART_SELECT_ERROR_NOTIF, &HPTaskAwoken);
|
||||
}
|
||||
UART_EXIT_CRITICAL_ISR(&uart_selectlock);
|
||||
} else if(uart_intr_status & UART_PARITY_ERR_INT_ST_M) {
|
||||
uart_reg->int_clr.parity_err = 1;
|
||||
uart_event.type = UART_PARITY_ERR;
|
||||
UART_ENTER_CRITICAL_ISR(&uart_selectlock);
|
||||
if (p_uart->uart_select_notif_callback) {
|
||||
p_uart->uart_select_notif_callback(uart_num, UART_SELECT_ERROR_NOTIF, &HPTaskAwoken);
|
||||
}
|
||||
UART_EXIT_CRITICAL_ISR(&uart_selectlock);
|
||||
} else if(uart_intr_status & UART_TX_BRK_DONE_INT_ST_M) {
|
||||
UART_ENTER_CRITICAL_ISR(&uart_spinlock[uart_num]);
|
||||
uart_reg->conf0.txd_brk = 0;
|
||||
@@ -1255,6 +1278,7 @@ esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_b
|
||||
p_uart_obj[uart_num]->tx_ring_buf = NULL;
|
||||
p_uart_obj[uart_num]->tx_buf_size = 0;
|
||||
}
|
||||
p_uart_obj[uart_num]->uart_select_notif_callback = NULL;
|
||||
} else {
|
||||
ESP_LOGE(UART_TAG, "UART driver already installed");
|
||||
return ESP_FAIL;
|
||||
@@ -1342,3 +1366,15 @@ esp_err_t uart_driver_delete(uart_port_t uart_num)
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
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]) {
|
||||
p_uart_obj[uart_num]->uart_select_notif_callback = (uart_select_notif_callback_t) uart_select_notif_callback;
|
||||
}
|
||||
}
|
||||
|
||||
portMUX_TYPE *uart_get_selectlock()
|
||||
{
|
||||
return &uart_selectlock;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user