Skip to content

Commit adb8ba4

Browse files
author
Deepika
committed
Added xx_ticker_fire_interrupt function for M2351 device
1 parent a5f9629 commit adb8ba4

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

targets/TARGET_NUVOTON/TARGET_M2351/lp_ticker.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,23 @@ timestamp_t lp_ticker_read()
145145

146146
void lp_ticker_set_interrupt(timestamp_t timestamp)
147147
{
148-
uint32_t now = lp_ticker_read();
148+
uint32_t delta = timestamp - lp_ticker_read();
149149
wakeup_tick = timestamp;
150150

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

176167
void lp_ticker_disable_interrupt(void)

targets/TARGET_NUVOTON/TARGET_M2351/us_ticker.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,20 @@ void us_ticker_clear_interrupt(void)
152152
void us_ticker_set_interrupt(timestamp_t timestamp)
153153
{
154154
TIMER_Stop((TIMER_T *) NU_MODBASE(timer1hires_modinit.modname));
155-
int delta = (int) (timestamp - us_ticker_read());
156155

157-
if (delta > 0) {
158-
cd_major_minor_us = delta * US_PER_TICK;
159-
us_ticker_arm_cd();
160-
}
161-
else {
162-
cd_major_minor_us = cd_minor_us = 0;
163-
/**
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(timer1hires_modinit.irq_n);
168-
}
156+
uint32_t delta = timestamp - us_ticker_read();
157+
cd_major_minor_us = delta * US_PER_TICK;
158+
us_ticker_arm_cd();
159+
}
160+
161+
void us_ticker_fire_interrupt(void)
162+
{
163+
cd_major_minor_us = cd_minor_us = 0;
164+
/**
165+
* This event was in the past. Set the interrupt as pending, but don't process it here.
166+
* This prevents a recurive loop under heavy load which can lead to a stack overflow.
167+
*/
168+
NVIC_SetPendingIRQ(timer1hires_modinit.irq_n);
169169
}
170170

171171
static void tmr0_vec(void)

0 commit comments

Comments
 (0)