Skip to content

Commit a4df65f

Browse files
committed
Added UART RX interrupt function
1 parent ef99cd7 commit a4df65f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cores/esp32/esp32-hal-uart.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ static void IRAM_ATTR _uart_isr(void *arg)
8585
uart->dev->int_clr.rxfifo_tout = 1;
8686
while(uart->dev->status.rxfifo_cnt || (uart->dev->mem_rx_status.wr_addr != uart->dev->mem_rx_status.rd_addr)) {
8787
c = uart->dev->fifo.rw_byte;
88-
if(uart->queue != NULL) {
88+
if(arg != NULL){ // Check if an interrupt handler function has been specified
89+
// Fully optimized code would not create the queue anymore if an function has been specified as an argument.
90+
(*((void(**)())arg))(c); // There is, call it with c as an parameter. Don't pass it to the queue anymore
91+
}else if(uart->queue != NULL) {
8992
xQueueSendFromISR(uart->queue, &c, &xHigherPriorityTaskWoken);
9093
}
9194
}
@@ -96,7 +99,7 @@ static void IRAM_ATTR _uart_isr(void *arg)
9699
}
97100
}
98101

99-
void uartEnableInterrupt(uart_t* uart)
102+
void uartEnableInterrupt(uart_t* uart, void * func)
100103
{
101104
UART_MUTEX_LOCK();
102105
uart->dev->conf1.rxfifo_full_thrhd = 112;
@@ -107,7 +110,7 @@ void uartEnableInterrupt(uart_t* uart)
107110
uart->dev->int_ena.rxfifo_tout = 1;
108111
uart->dev->int_clr.val = 0xffffffff;
109112

110-
esp_intr_alloc(UART_INTR_SOURCE(uart->num), (int)ESP_INTR_FLAG_IRAM, _uart_isr, NULL, &uart->intr_handle);
113+
esp_intr_alloc(UART_INTR_SOURCE(uart->num), (int)ESP_INTR_FLAG_IRAM, _uart_isr, func, &uart->intr_handle);
111114
UART_MUTEX_UNLOCK();
112115
}
113116

@@ -148,7 +151,7 @@ void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
148151
}
149152
pinMode(rxPin, INPUT);
150153
pinMatrixInAttach(rxPin, UART_RXD_IDX(uart->num), inverted);
151-
uartEnableInterrupt(uart);
154+
uartEnableInterrupt(uart, NULL); // No interrupt handler function by default
152155
}
153156

154157
void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)

cores/esp32/esp32-hal-uart.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ unsigned long uartDetectBaudrate(uart_t *uart);
8080

8181
bool uartRxActive(uart_t* uart);
8282

83+
void uartDisableInterrupt(uart_t* uart);
84+
void uartEnableInterrupt(uart_t* uart,void * func );
85+
8386
#ifdef __cplusplus
8487
}
8588
#endif

0 commit comments

Comments
 (0)