Skip to content

Commit da15379

Browse files
committed
[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.
1 parent 9b7642d commit da15379

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

targets/TARGET_NUVOTON/TARGET_M451/lp_ticker.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,14 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
147147

148148
TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname));
149149

150-
int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now);
150+
/**
151+
* FIXME: Scheduled alarm may go off incorrectly due to wrap around.
152+
* Conditions in which delta is negative:
153+
* 1. Wrap around
154+
* 2. Newly scheduled alarm is behind now
155+
*/
156+
//int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now);
157+
int delta = (int) (timestamp - now);
151158
if (delta > 0) {
152159
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
153160
lp_ticker_arm_cd();

targets/TARGET_NUVOTON/TARGET_NUC472/lp_ticker.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,14 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
146146

147147
TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname));
148148

149-
int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now);
149+
/**
150+
* FIXME: Scheduled alarm may go off incorrectly due to wrap around.
151+
* Conditions in which delta is negative:
152+
* 1. Wrap around
153+
* 2. Newly scheduled alarm is behind now
154+
*/
155+
//int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now);
156+
int delta = (int) (timestamp - now);
150157
if (delta > 0) {
151158
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
152159
lp_ticker_arm_cd();

0 commit comments

Comments
 (0)