Skip to content

Commit f530acf

Browse files
committed
lpc1768 and beetle: fix us ticker set interrupt for timestamp in the past
If the event is in the past, set pending interrupt instead of directly using timestamp.
1 parent cbfb234 commit f530acf

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

targets/TARGET_ARM_SSG/TARGET_BEETLE/us_ticker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void us_ticker_set_interrupt(timestamp_t timestamp) {
9999
/* Check if the event was in the past */
100100
if (delta <= 0) {
101101
/* This event was in the past */
102-
Timer_SetInterrupt(TIMER0, 0);
102+
NVIC_SetPendingIRQ(Timer_GetIRQn(TIMER0));
103103
return;
104104
}
105105

targets/TARGET_NXP/TARGET_LPC176X/us_ticker.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ uint32_t us_ticker_read() {
4949
}
5050

5151
void us_ticker_set_interrupt(timestamp_t timestamp) {
52-
// set match value
53-
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
54-
// enable match interrupt
55-
US_TICKER_TIMER->MCR |= 1;
52+
int current_time = us_ticker_read();
53+
int delta = (int)(timestamp - current_time);
54+
if (delta <= 0) {
55+
NVIC_SetPendingIRQ(US_TICKER_TIMER_IRQn);
56+
} else {
57+
// set match value
58+
US_TICKER_TIMER->MR0 = (uint32_t)timestamp;
59+
// enable match interrupt
60+
US_TICKER_TIMER->MCR |= 1;
61+
}
62+
5663
}
5764

5865
void us_ticker_disable_interrupt(void) {

0 commit comments

Comments
 (0)