Skip to content

Commit 9299d9f

Browse files
committed
[Nuvoton] 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 867b330 commit 9299d9f

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/serial_api.c

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

8787
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
88-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
8988
#endif
9089

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

9394
static struct nu_uart_var uart0_var = {
@@ -531,15 +532,17 @@ static void uart_irq(serial_t *obj)
531532
if (uart_base->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk)) {
532533
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
533534
UART_DISABLE_INT(uart_base, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk));
534-
if (obj->serial.irq_handler) {
535+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
536+
// Call irq_handler() only when RxIrq is enabled
535537
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
536538
}
537539
}
538540

539541
if (uart_base->INTSTS & UART_INTSTS_THREINT_Msk) {
540542
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
541543
UART_DISABLE_INT(uart_base, UART_INTEN_THREIEN_Msk);
542-
if (obj->serial.irq_handler) {
544+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
545+
// Call irq_handler() only when TxIrq is enabled
543546
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
544547
}
545548
}
@@ -1179,6 +1182,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
11791182
}
11801183
}
11811184

1185+
#endif // #if DEVICE_SERIAL_ASYNCH
1186+
11821187
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11831188
{
11841189
int inten_msk = 0;
@@ -1195,8 +1200,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11951200
return !! inten_msk;
11961201
}
11971202

1198-
#endif // #if DEVICE_SERIAL_ASYNCH
1199-
12001203
bool serial_can_deep_sleep(void)
12011204
{
12021205
bool sleep_allowed = 1;

targets/TARGET_NUVOTON/TARGET_M451/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 = {
@@ -464,15 +465,17 @@ static void uart_irq(serial_t *obj)
464465
if (uart_base->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk)) {
465466
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
466467
UART_DISABLE_INT(uart_base, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk));
467-
if (obj->serial.irq_handler) {
468+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
469+
// Call irq_handler() only when RxIrq is enabled
468470
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
469471
}
470472
}
471473

472474
if (uart_base->INTSTS & UART_INTSTS_THREINT_Msk) {
473475
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
474476
UART_DISABLE_INT(uart_base, UART_INTEN_THREIEN_Msk);
475-
if (obj->serial.irq_handler) {
477+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
478+
// Call irq_handler() only when TxIrq is enabled
476479
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
477480
}
478481
}
@@ -1102,6 +1105,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
11021105
}
11031106
}
11041107

1108+
#endif // #if DEVICE_SERIAL_ASYNCH
1109+
11051110
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11061111
{
11071112
int inten_msk = 0;
@@ -1118,8 +1123,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11181123
return !! inten_msk;
11191124
}
11201125

1121-
#endif // #if DEVICE_SERIAL_ASYNCH
1122-
11231126
bool serial_can_deep_sleep(void)
11241127
{
11251128
bool sleep_allowed = 1;

targets/TARGET_NUVOTON/TARGET_M480/serial_api.c

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

8787
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
88-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
8988
#endif
9089

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

9394
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
}
@@ -1154,6 +1157,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
11541157
}
11551158
}
11561159

1160+
#endif // #if DEVICE_SERIAL_ASYNCH
1161+
11571162
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11581163
{
11591164
int inten_msk = 0;
@@ -1170,8 +1175,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11701175
return !! inten_msk;
11711176
}
11721177

1173-
#endif // #if DEVICE_SERIAL_ASYNCH
1174-
11751178
bool serial_can_deep_sleep(void)
11761179
{
11771180
bool sleep_allowed = 1;

targets/TARGET_NUVOTON/TARGET_NANO100/serial_api.c

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

7676
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
77-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
7877
#endif
7978

79+
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
80+
8081
bool serial_can_deep_sleep(void);
8182

8283
static struct nu_uart_var uart0_var = {
@@ -426,15 +427,17 @@ static void uart_irq(serial_t *obj)
426427
if (uart_base->ISR & (UART_ISR_RDA_IS_Msk | UART_ISR_RTO_IS_Msk)) {
427428
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
428429
UART_DISABLE_INT(uart_base, (UART_IER_RDA_IE_Msk | UART_IER_RTO_IE_Msk));
429-
if (obj->serial.irq_handler) {
430+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
431+
// Call irq_handler() only when RxIrq is enabled
430432
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
431433
}
432434
}
433435

434436
if (uart_base->ISR & UART_ISR_THRE_IS_Msk) {
435437
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
436438
UART_DISABLE_INT(uart_base, UART_IER_THRE_IE_Msk);
437-
if (obj->serial.irq_handler) {
439+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
440+
// Call irq_handler() only when TxIrq is enabled
438441
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
439442
}
440443
}
@@ -1003,6 +1006,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
10031006
}
10041007
}
10051008

1009+
#endif // #if DEVICE_SERIAL_ASYNCH
1010+
10061011
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
10071012
{
10081013
int ier_msk = 0;
@@ -1019,8 +1024,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
10191024
return !! ier_msk;
10201025
}
10211026

1022-
#endif // #if DEVICE_SERIAL_ASYNCH
1023-
10241027
bool serial_can_deep_sleep(void)
10251028
{
10261029
bool sleep_allowed = 1;

targets/TARGET_NUVOTON/TARGET_NUC472/serial_api.c

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

8787
static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch);
88-
static int serial_is_irq_en(serial_t *obj, SerialIrq irq);
8988
#endif
9089

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

9394
static struct nu_uart_var uart0_var = {
@@ -504,15 +505,17 @@ static void uart_irq(serial_t *obj)
504505
if (uart_base->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOINT_Msk)) {
505506
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next read.
506507
UART_DISABLE_INT(uart_base, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXTOIEN_Msk));
507-
if (obj->serial.irq_handler) {
508+
if (obj->serial.irq_handler && serial_is_irq_en(obj, RxIrq)) {
509+
// Call irq_handler() only when RxIrq is enabled
508510
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, RxIrq);
509511
}
510512
}
511513

512514
if (uart_base->INTSTS & UART_INTSTS_THREINT_Msk) {
513515
// Simulate clear of the interrupt flag. Temporarily disable the interrupt here and to be recovered on next write.
514516
UART_DISABLE_INT(uart_base, UART_INTEN_THREIEN_Msk);
515-
if (obj->serial.irq_handler) {
517+
if (obj->serial.irq_handler && serial_is_irq_en(obj, TxIrq)) {
518+
// Call irq_handler() only when TxIrq is enabled
516519
((uart_irq_handler) obj->serial.irq_handler)(obj->serial.irq_id, TxIrq);
517520
}
518521
}
@@ -1148,6 +1151,8 @@ static void serial_check_dma_usage(DMAUsage *dma_usage, int *dma_ch)
11481151
}
11491152
}
11501153

1154+
#endif // #if DEVICE_SERIAL_ASYNCH
1155+
11511156
static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11521157
{
11531158
int inten_msk = 0;
@@ -1164,8 +1169,6 @@ static int serial_is_irq_en(serial_t *obj, SerialIrq irq)
11641169
return !! inten_msk;
11651170
}
11661171

1167-
#endif // #if DEVICE_SERIAL_ASYNCH
1168-
11691172
bool serial_can_deep_sleep(void)
11701173
{
11711174
bool sleep_allowed = 1;

0 commit comments

Comments
 (0)