Skip to content

Commit 8b86d44

Browse files
ccli80xc0170
authored andcommitted
[M487] Fix premature lp_ticker interrupt
Old lp_ticker handles past event, but it has a bug with premature go-off. The bug can re-produce on mbed-os-tests-mbed_drivers-lp_timeout/mbed-os-tests-mbed_hal-lp_us_tickers (mbed-os commit: 9c1fd48). Because upper layer (mbed-os/hal/mbed_ticker_api.c) has handled past event, this code can be removed from lp_ticker. The similar fix also applies to us_ticker.
1 parent a519b84 commit 8b86d44

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

targets/TARGET_NUVOTON/TARGET_M480/lp_ticker.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,13 @@ timestamp_t lp_ticker_read()
144144

145145
void lp_ticker_set_interrupt(timestamp_t timestamp)
146146
{
147-
uint32_t now = lp_ticker_read();
147+
uint32_t delta = timestamp - lp_ticker_read();
148148
wakeup_tick = timestamp;
149-
149+
150150
TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname));
151-
152-
int delta = (int) (timestamp - now);
153-
if (delta > 0) {
154-
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
155-
lp_ticker_arm_cd();
156-
} else {
157-
// NOTE: With lp_ticker_fire_interrupt() introduced, upper layer would handle past event case.
158-
// This code fragment gets redundant, but it is still kept here for backward-compatible.
159-
void lp_ticker_fire_interrupt(void);
160-
lp_ticker_fire_interrupt();
161-
}
151+
152+
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
153+
lp_ticker_arm_cd();
162154
}
163155

164156
void lp_ticker_fire_interrupt(void)

targets/TARGET_NUVOTON/TARGET_M480/us_ticker.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,10 @@ void us_ticker_clear_interrupt(void)
146146
void us_ticker_set_interrupt(timestamp_t timestamp)
147147
{
148148
TIMER_Stop((TIMER_T *) NU_MODBASE(timer1hires_modinit.modname));
149-
150-
int delta = (int) (timestamp - us_ticker_read());
151-
if (delta > 0) {
152-
cd_major_minor_us = delta * US_PER_TICK;
153-
us_ticker_arm_cd();
154-
} else {
155-
// NOTE: With us_ticker_fire_interrupt() introduced, upper layer would handle past event case.
156-
// This code fragment gets redundant, but it is still kept here for backward-compatible.
157-
void us_ticker_fire_interrupt(void);
158-
us_ticker_fire_interrupt();
159-
}
149+
150+
uint32_t delta = timestamp - us_ticker_read();
151+
cd_major_minor_us = delta * US_PER_TICK;
152+
us_ticker_arm_cd();
160153
}
161154

162155
void us_ticker_fire_interrupt(void)

0 commit comments

Comments
 (0)