Skip to content

Commit 5b7beab

Browse files
committed
M263: Fix redundant call to UART IRQ handler
Honor RxIrq/TxIrq to avoid redundant call to UART IRQ handler. This is also to fix FPGA CI test mbed_hal_fpga_ci_test_shield-uart.
1 parent eb435b7 commit 5b7beab

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

targets/TARGET_NUVOTON/TARGET_M261/serial_api.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ static void serial_rx_enable_event(serial_t *obj, int event, uint8_t enable);
8686
static int serial_is_rx_complete(serial_t *obj);
8787

8888
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
89-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
9089
#endif
9190

91+
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
92+
9293
bool serial_can_deep_sleep(void);
9394

9495
static struct nu_uart_var uart0_var = {
@@ -519,15 +520,17 @@ static void uart_irq(serial_t *obj)
519520
if (uart_base->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk)) {
520521
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
521522
UART_DISABLE_INT(uart_base, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk));
522-
if (obj->serial.irq_handler) {
523+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
524+
// Call irq_handler() only when RxIrq is enabled
523525
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
524526
}
525527
}
526528

527529
if (uart_base->INTSTS & UART_INTSTS_THREINT_Msk) {
528530
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
529531
UART_DISABLE_INT(uart_base, UART_INTEN_THREIEN_Msk);
530-
if (obj->serial.irq_handler) {
532+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
533+
// Call irq_handler() only when TxIrq is enabled
531534
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
532535
}
533536
}
@@ -1167,6 +1170,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
11671170
}
11681171
}
11691172

1173+
#endif // #if DEVICE_SERIAL_ASYNCH
1174+
11701175
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11711176
{
11721177
int inten_msk = 0;
@@ -1183,8 +1188,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11831188
return !! inten_msk;
11841189
}
11851190

1186-
#endif // #if DEVICE_SERIAL_ASYNCH
1187-
11881191
bool serial_can_deep_sleep(void)
11891192
{
11901193
bool sleep_allowed = 1;

0 commit comments

Comments
 (0)