From da153799076446be9f8e74e8fe15fb73ddd64f4d Mon Sep 17 00:00:00 2001 From: ccli8 Date: Thu, 8 Sep 2016 14:53:31 +0800 Subject: [PATCH] [NUC472/M453] Remove fix of lp_ticker wrap-around The original fix cannot handle both wrap-around and scheduled alarm behind now well. Leave wrap-around as known issue. --- targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c | 9 ++++++++- targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c index 84a4c9b36b..74cd964403 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c @@ -147,7 +147,14 @@ void lp_ticker_set_interrupt(timestamp_t timestamp) TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname)); - int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now); + /** + * FIXME: Scheduled alarm may go off incorrectly due to wrap around. + * Conditions in which delta is negative: + * 1. Wrap around + * 2. Newly scheduled alarm is behind now + */ + //int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now); + int delta = (int) (timestamp - now); if (delta > 0) { cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC; lp_ticker_arm_cd(); diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c index 2d05f33c50..5ed5a719c0 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c @@ -146,7 +146,14 @@ void lp_ticker_set_interrupt(timestamp_t timestamp) TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname)); - int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now); + /** + * FIXME: Scheduled alarm may go off incorrectly due to wrap around. + * Conditions in which delta is negative: + * 1. Wrap around + * 2. Newly scheduled alarm is behind now + */ + //int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now); + int delta = (int) (timestamp - now); if (delta > 0) { cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC; lp_ticker_arm_cd();