From 310b12a235e94dd8530b941c5ec6036ebd41d3b4 Mon Sep 17 00:00:00 2001 From: ccli8 Date: Mon, 13 Aug 2018 11:39:02 +0800 Subject: [PATCH] [Nuvoton] Fix HAL sleep test failure with lp_ticker Replace wait_us with nu_busy_wait_us in lp_ticker since wait_us is not allowed in sleep test which would suspend us ticker layer on which wait_us relies. nu_busy_wait_us is implemented by calling us ticker HAL API directly rather than relying on us ticker layer. --- targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c | 12 ++++++------ targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c | 12 ++++++------ targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c | 12 ++++++------ targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c | 14 +++++++------- targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c | 12 ++++++------ 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c index 8e0daf379f..d5a0776dfc 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c @@ -19,9 +19,9 @@ #if DEVICE_LPTICKER #include "sleep_api.h" -#include "mbed_wait_api.h" #include "mbed_assert.h" #include "nu_modutil.h" +#include "nu_timer.h" #include "nu_miscutil.h" #include "partition_M2351.h" @@ -137,10 +137,10 @@ void lp_ticker_init(void) // Continuous mode // NOTE: TIMER_CTL_CNTDATEN_Msk exists in NUC472, but not in M451/M480/M2351. In M451/M480/M2351, TIMER_CNT is updated continuously by default. timer_base->CTL = TIMER_CONTINUOUS_MODE | prescale_timer/* | TIMER_CTL_CNTDATEN_Msk*/; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->CMP = cmp_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); // Set vector NVIC_SetVector(TIMER_MODINIT.irq_n, (uint32_t) TIMER_MODINIT.var); @@ -148,13 +148,13 @@ void lp_ticker_init(void) NVIC_DisableIRQ(TIMER_MODINIT.irq_n); TIMER_EnableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_EnableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_Start(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); /* Wait for timer to start counting and raise active flag */ while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); diff --git a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c index 5a09e84a3d..9eb3bda147 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c @@ -19,9 +19,9 @@ #if DEVICE_LPTICKER #include "sleep_api.h" -#include "mbed_wait_api.h" #include "mbed_assert.h" #include "nu_modutil.h" +#include "nu_timer.h" #include "nu_miscutil.h" /* Micro seconds per second */ @@ -103,10 +103,10 @@ void lp_ticker_init(void) // Continuous mode // NOTE: TIMER_CTL_CNTDATEN_Msk exists in NUC472, but not in M451. In M451, TIMER_CNT is updated continuously by default. timer_base->CTL = TIMER_CONTINUOUS_MODE | prescale_timer/* | TIMER_CTL_CNTDATEN_Msk*/; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->CMP = cmp_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); // Set vector NVIC_SetVector(TIMER_MODINIT.irq_n, (uint32_t) TIMER_MODINIT.var); @@ -114,13 +114,13 @@ void lp_ticker_init(void) NVIC_DisableIRQ(TIMER_MODINIT.irq_n); TIMER_EnableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_EnableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_Start(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); /* Wait for timer to start counting and raise active flag */ while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); diff --git a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c index 1811c72dfc..08f5e5f9f1 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c @@ -19,9 +19,9 @@ #if DEVICE_LPTICKER #include "sleep_api.h" -#include "mbed_wait_api.h" #include "mbed_assert.h" #include "nu_modutil.h" +#include "nu_timer.h" #include "nu_miscutil.h" /* Micro seconds per second */ @@ -103,10 +103,10 @@ void lp_ticker_init(void) // Continuous mode // NOTE: TIMER_CTL_CNTDATEN_Msk exists in NUC472, but not in M451/M480. In M451/M480, TIMER_CNT is updated continuously by default. timer_base->CTL = TIMER_CONTINUOUS_MODE | prescale_timer/* | TIMER_CTL_CNTDATEN_Msk*/; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->CMP = cmp_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); // Set vector NVIC_SetVector(TIMER_MODINIT.irq_n, (uint32_t) TIMER_MODINIT.var); @@ -114,13 +114,13 @@ void lp_ticker_init(void) NVIC_DisableIRQ(TIMER_MODINIT.irq_n); TIMER_EnableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_EnableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_Start(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); /* Wait for timer to start counting and raise active flag */ while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk)); diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c index c2faafc856..40c46def52 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c @@ -19,9 +19,9 @@ #if DEVICE_LPTICKER #include "sleep_api.h" -#include "mbed_wait_api.h" #include "mbed_assert.h" #include "nu_modutil.h" +#include "nu_timer.h" #include "nu_miscutil.h" /* Micro seconds per second */ @@ -104,13 +104,13 @@ void lp_ticker_init(void) MBED_ASSERT(cmp_timer >= TMR_CMP_MIN && cmp_timer <= TMR_CMP_MAX); // Continuous mode timer_base->CTL = TIMER_CONTINUOUS_MODE; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->PRECNT = prescale_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->CMPR = cmp_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); // Set vector NVIC_SetVector(TIMER_MODINIT.irq_n, (uint32_t) TIMER_MODINIT.var); @@ -118,13 +118,13 @@ void lp_ticker_init(void) NVIC_DisableIRQ(TIMER_MODINIT.irq_n); TIMER_EnableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_EnableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_Start(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); /* Wait for timer to start counting and raise active flag */ while(! (timer_base->CTL & TIMER_CTL_TMR_ACT_Msk)); diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c index 1f55c08ca2..10417fe4d1 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c @@ -19,9 +19,9 @@ #if DEVICE_LPTICKER #include "sleep_api.h" -#include "mbed_wait_api.h" #include "mbed_assert.h" #include "nu_modutil.h" +#include "nu_timer.h" #include "nu_miscutil.h" /* Micro seconds per second */ @@ -102,10 +102,10 @@ void lp_ticker_init(void) MBED_ASSERT(cmp_timer >= TMR_CMP_MIN && cmp_timer <= TMR_CMP_MAX); // Continuous mode timer_base->CTL = TIMER_CONTINUOUS_MODE | prescale_timer | TIMER_CTL_CNTDATEN_Msk; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); timer_base->CMP = cmp_timer; - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); // Set vector NVIC_SetVector(TIMER_MODINIT.irq_n, (uint32_t) TIMER_MODINIT.var); @@ -113,13 +113,13 @@ void lp_ticker_init(void) NVIC_DisableIRQ(TIMER_MODINIT.irq_n); TIMER_EnableInt(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_EnableWakeup(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); TIMER_Start(timer_base); - wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); + nu_busy_wait_us((NU_US_PER_SEC / NU_TMRCLK_PER_SEC) * 3); /* Wait for timer to start counting and raise active flag */ while(! (timer_base->CTL & TIMER_CTL_ACTSTS_Msk));