Skip to content

Commit 7f562e6

Browse files
committed
[M252KG] 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 257fefa commit 7f562e6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

targets/TARGET_NUVOTON/TARGET_M251/serial_api.c

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

8383
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
84-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
8584
#endif
8685

86+
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
87+
8788
bool serial_can_deep_sleep(void);
8889

8990
static struct nu_uart_var uart0_var = {
@@ -459,15 +460,17 @@ static void uart_irq(serial_t *obj)
459460
if (uart_base->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk)) {
460461
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
461462
UART_DISABLE_INT(uart_base, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk));
462-
if (obj->serial.irq_handler) {
463+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
464+
// Call irq_handler() only when RxIrq is enabled
463465
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
464466
}
465467
}
466468

467469
if (uart_base->INTSTS & UART_INTSTS_THREINT_Msk) {
468470
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
469471
UART_DISABLE_INT(uart_base, UART_INTEN_THREIEN_Msk);
470-
if (obj->serial.irq_handler) {
472+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
473+
// Call irq_handler() only when TxIrq is enabled
471474
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
472475
}
473476
}
@@ -1094,6 +1097,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
10941097
}
10951098
}
10961099

1100+
#endif // #if DEVICE_SERIAL_ASYNCH
1101+
10971102
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
10981103
{
10991104
int inten_msk = 0;
@@ -1110,8 +1115,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11101115
return !! inten_msk;
11111116
}
11121117

1113-
#endif // #if DEVICE_SERIAL_ASYNCH
1114-
11151118
bool serial_can_deep_sleep(void)
11161119
{
11171120
bool sleep_allowed = 1;

0 commit comments

Comments
 (0)