Skip to content

Commit 38e78fa

Browse files
committed
[NANO130] Ticker: add fire interrupt now function
1 parent c7cd9b6 commit 38e78fa

File tree

2 files changed

+22
-34
lines changed

2 files changed

+22
-34
lines changed

targets/TARGET_NUVOTON/TARGET_NANO100/lp_ticker.c

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,23 @@ timestamp_t lp_ticker_read()
148148

149149
void lp_ticker_set_interrupt(timestamp_t timestamp)
150150
{
151-
uint32_t now = lp_ticker_read();
151+
uint32_t delta = timestamp - lp_ticker_read();
152152
wakeup_tick = timestamp;
153153

154154
TIMER_Stop((TIMER_T *) NU_MODBASE(timer3_modinit.modname));
155-
155+
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
156+
lp_ticker_arm_cd();
157+
158+
}
159+
160+
void lp_ticker_fire_interrupt(void)
161+
{
162+
cd_major_minor_clks = cd_minor_clks = 0;
156163
/**
157-
* NOTE: Scheduled alarm may go off incorrectly due to wrap around.
158-
* Conditions in which delta is negative:
159-
* 1. Wrap around
160-
* 2. Newly scheduled alarm is behind now
161-
*/
162-
//int delta = (timestamp > now) ? (timestamp - now) : (uint32_t) ((uint64_t) timestamp + 0xFFFFFFFFu - now);
163-
int delta = (int) (timestamp - now);
164-
if (delta > 0) {
165-
cd_major_minor_clks = (uint64_t) delta * US_PER_TICK * TMR3_CLK_PER_SEC / US_PER_SEC;
166-
lp_ticker_arm_cd();
167-
}
168-
else {
169-
cd_major_minor_clks = cd_minor_clks = 0;
170-
/**
171-
* This event was in the past. Set the interrupt as pending, but don't process it here.
172-
* This prevents a recurive loop under heavy load which can lead to a stack overflow.
173-
*/
174-
NVIC_SetPendingIRQ(timer3_modinit.irq_n);
175-
}
164+
* This event was in the past. Set the interrupt as pending, but don't process it here.
165+
* This prevents a recurive loop under heavy load which can lead to a stack overflow.
166+
*/
167+
NVIC_SetPendingIRQ(timer3_modinit.irq_n);
176168
}
177169

178170
void lp_ticker_disable_interrupt(void)

targets/TARGET_NUVOTON/TARGET_NANO100/us_ticker.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,15 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
148148
{
149149
TIMER_Stop((TIMER_T *) NU_MODBASE(timer1hires_modinit.modname));
150150

151-
int delta = (int) (timestamp - us_ticker_read());
152-
if (delta > 0) {
153-
cd_major_minor_us = delta * US_PER_TICK;
154-
us_ticker_arm_cd();
155-
}
156-
else {
157-
cd_major_minor_us = cd_minor_us = 0;
158-
/**
159-
* This event was in the past. Set the interrupt as pending, but don't process it here.
160-
* This prevents a recurive loop under heavy load which can lead to a stack overflow.
161-
*/
162-
NVIC_SetPendingIRQ(timer1hires_modinit.irq_n);
163-
}
151+
uint32_t delta = timestamp - us_ticker_read();
152+
cd_major_minor_us = delta * US_PER_TICK;
153+
us_ticker_arm_cd();
154+
}
155+
156+
void us_ticker_fire_interrupt(void)
157+
{
158+
cd_major_minor_us = cd_minor_us = 0;
159+
NVIC_SetPendingIRQ(timer1hires_modinit.irq_n);
164160
}
165161

166162
void TMR0_IRQHandler(void)

0 commit comments

Comments
 (0)