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();