From 9ee83f575af5e1df94ea804c6d57f1b372abbc99 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Wed, 8 Aug 2018 09:38:48 +0800 Subject: [PATCH 1/4] [Nuvoton] Fix spurious us_ticker/lp_ticker interrupts If us_ticker/lp_ticker is scheduled and then the interrupt is disabled, the originally scheduled interrupt may still become pending. If this occurs, then an interrupt will fire twice on the next call to us_ticker_set_interrupt/lp_ticker_set_interrupt - once immediately and then a second time at the appropriate time. This patch prevents the first interrupt by clearing interrupts in us_ticker_set_interrupt/lp_ticker_set_interrupt before calling NVIC_EnableIRQ. --- targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c | 6 ++++-- targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c | 6 ++++-- 10 files changed, 40 insertions(+), 20 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c index 8e0daf379fd..d7b4eb6e47f 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c @@ -101,8 +101,6 @@ void lp_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ lp_ticker_disable_interrupt(); - lp_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -203,6 +201,10 @@ timestamp_t lp_ticker_read() void lp_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + lp_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c index a8034561fcc..9a336110c7c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c @@ -75,8 +75,6 @@ void us_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ us_ticker_disable_interrupt(); - us_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -159,6 +157,10 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + us_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c index 5a09e84a3df..98e8631e4e0 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c @@ -76,8 +76,6 @@ void lp_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ lp_ticker_disable_interrupt(); - lp_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -166,6 +164,10 @@ timestamp_t lp_ticker_read() void lp_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + lp_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c index 0fadea09deb..66e9a97c42c 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c @@ -52,8 +52,6 @@ void us_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ us_ticker_disable_interrupt(); - us_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -124,6 +122,10 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + us_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c index 1811c72dfcf..04b88e8a614 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c @@ -76,8 +76,6 @@ void lp_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ lp_ticker_disable_interrupt(); - lp_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -166,6 +164,10 @@ timestamp_t lp_ticker_read() void lp_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + lp_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c index 1441cf26b3e..715857241d4 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c @@ -52,8 +52,6 @@ void us_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ us_ticker_disable_interrupt(); - us_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -124,6 +122,10 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + us_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c index c2faafc8564..fc249fc38e1 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c @@ -78,8 +78,6 @@ void lp_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ lp_ticker_disable_interrupt(); - lp_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -170,6 +168,10 @@ timestamp_t lp_ticker_read() void lp_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + lp_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c index 0c5160d839d..f1bf49467e0 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c @@ -54,8 +54,6 @@ void us_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ us_ticker_disable_interrupt(); - us_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -126,6 +124,10 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + us_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c index 1f55c08ca21..c7972dcabde 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c @@ -76,8 +76,6 @@ void lp_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ lp_ticker_disable_interrupt(); - lp_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -165,6 +163,10 @@ timestamp_t lp_ticker_read() void lp_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + lp_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c index 03e58bac608..a135a7585ab 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c @@ -52,8 +52,6 @@ void us_ticker_init(void) /* By HAL spec, ticker_init allows the ticker to keep counting and disables the * ticker interrupt. */ us_ticker_disable_interrupt(); - us_ticker_clear_interrupt(); - NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); return; } ticker_inited = 1; @@ -123,6 +121,10 @@ uint32_t us_ticker_read() void us_ticker_set_interrupt(timestamp_t timestamp) { + /* Clear any previously pending interrupts */ + us_ticker_clear_interrupt(); + NVIC_ClearPendingIRQ(TIMER_MODINIT.irq_n); + /* In continuous mode, counter will be reset to zero with the following sequence: * 1. Stop counting * 2. Configure new CMP value From 6639a92bcde7f9057601ed7bb80631c02cf41c54 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Tue, 14 Aug 2018 18:04:11 +0800 Subject: [PATCH 2/4] [Nuvoton] Fix lp_ticker_free cannot pass speed test --- targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c | 16 ---------------- targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c | 16 ---------------- targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c | 16 ---------------- .../TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c | 16 ---------------- targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c | 16 ---------------- 5 files changed, 80 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c index d7b4eb6e47f..10f7adbf150 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c @@ -160,23 +160,7 @@ void lp_ticker_init(void) void lp_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - - /* Disable wakeup */ - TIMER_DisableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock diff --git a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c index 98e8631e4e0..c723e77cb12 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c @@ -126,23 +126,7 @@ void lp_ticker_init(void) void lp_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - - /* Disable wakeup */ - TIMER_DisableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c index 04b88e8a614..fe6a923ceee 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c @@ -126,23 +126,7 @@ void lp_ticker_init(void) void lp_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - - /* Disable wakeup */ - TIMER_DisableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c index fc249fc38e1..41b1ec55d71 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c @@ -130,23 +130,7 @@ void lp_ticker_init(void) void lp_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk)); - - /* Disable wakeup */ - TIMER_DisableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c index c7972dcabde..0b4f99e7174 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c @@ -125,23 +125,7 @@ void lp_ticker_init(void) void lp_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - - /* Disable wakeup */ - TIMER_DisableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); - NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ From ab7b93ca583fe0779dd52f0ee41e41fed70ee2c5 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Tue, 14 Aug 2018 18:07:08 +0800 Subject: [PATCH 3/4] [Nuvoton] Synchronize us_ticker to lp_ticker This is to make implementations of us_ticker/lp_ticker consistent. --- targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c | 9 --------- targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c | 9 --------- targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c | 9 --------- targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c | 9 --------- targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c | 9 --------- 5 files changed, 45 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c index 9a336110c7c..2f81310e7c2 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c @@ -123,16 +123,7 @@ void us_ticker_init(void) void us_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock diff --git a/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c index 66e9a97c42c..c04d4a940ea 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/us_ticker.c @@ -91,16 +91,7 @@ void us_ticker_init(void) void us_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c index 715857241d4..48624e308e7 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c @@ -91,16 +91,7 @@ void us_ticker_init(void) void us_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c index f1bf49467e0..67fbe283174 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c @@ -93,16 +93,7 @@ void us_ticker_init(void) void us_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_TMR_ACT_Msk)); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c index a135a7585ab..78997c68a90 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/us_ticker.c @@ -90,16 +90,7 @@ void us_ticker_init(void) void us_ticker_free(void) { - TIMER_T *timer_base = (TIMER_T *) NU_MODBASE(TIMER_MODINIT.modname); - - /* Stop counting */ - TIMER_Stop(timer_base); - - /* Wait for timer to stop counting and unset active flag */ - while((timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); - /* Disable interrupt */ - TIMER_DisableInt(timer_base); NVIC_DisableIRQ(TIMER_MODINIT.irq_n); /* Disable IP clock */ From 4888ff2b1108219f7f027af72b32a649dc5f712a Mon Sep 17 00:00:00 2001 From: ccli8 Date: Tue, 14 Aug 2018 18:40:19 +0800 Subject: [PATCH 4/4] Fix Greentea test common_tickers failed 1. Disable ticker interrupt which would interfere with fire_interrupt speed test 2. Enlarge test period to avoid timeout error --- TESTS/mbed_hal/common_tickers/main.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/TESTS/mbed_hal/common_tickers/main.cpp b/TESTS/mbed_hal/common_tickers/main.cpp index 98f879e70e3..e1a26dc79e1 100644 --- a/TESTS/mbed_hal/common_tickers/main.cpp +++ b/TESTS/mbed_hal/common_tickers/main.cpp @@ -473,11 +473,14 @@ void ticker_speed_test(void) /* ---- Test fire_interrupt function. ---- */ counter = NUM_OF_CALLS; + /* Disable ticker interrupt which would interfere with speed test */ + core_util_critical_section_enter(); start = us_ticker_read(); while (counter--) { intf->fire_interrupt(); } stop = us_ticker_read(); + core_util_critical_section_exit(); TEST_ASSERT(diff_us(start, stop, us_ticker_info) < (NUM_OF_CALLS * (MAX_FUNC_EXEC_TIME_US + DELTA_FUNC_EXEC_TIME_US))); @@ -569,7 +572,7 @@ utest::v1::status_t lp_ticker_teardown(const Case *const source, const size_t pa utest::v1::status_t test_setup(const size_t number_of_cases) { - GREENTEA_SETUP(30, "default_auto"); + GREENTEA_SETUP(80, "default_auto"); return verbose_test_setup_handler(number_of_cases); }