Skip to content

Commit f2ff36b

Browse files
authored
Merge pull request #6055 from mprse/ticker_k64f_set_interrupt_delta_fix
K64F lp ticker driver - calculation bug fix.
2 parents 0368a84 + b6a01de commit f2ff36b

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/us_ticker.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,15 @@ void us_ticker_clear_interrupt(void)
8383

8484
void us_ticker_set_interrupt(timestamp_t timestamp)
8585
{
86+
uint32_t now_us, delta_us;
87+
88+
now_us = us_ticker_read();
89+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
90+
8691
uint32_t delta = timestamp - us_ticker_read();
8792
PIT_StopTimer(PIT, kPIT_Chnl_3);
8893
PIT_StopTimer(PIT, kPIT_Chnl_2);
89-
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta);
94+
PIT_SetTimerPeriod(PIT, kPIT_Chnl_3, (uint32_t)delta_us);
9095
PIT_EnableInterrupts(PIT, kPIT_Chnl_3, kPIT_TimerInterruptEnable);
9196
PIT_StartTimer(PIT, kPIT_Chnl_3);
9297
PIT_StartTimer(PIT, kPIT_Chnl_2);

targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/api/lp_ticker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void lp_ticker_set_interrupt(timestamp_t timestamp)
135135

136136
lptmr_schedule = 0;
137137
now_us = lp_ticker_read();
138-
delta_us = timestamp > now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
138+
delta_us = timestamp >= now_us ? timestamp - now_us : (uint32_t)((uint64_t)timestamp + 0xFFFFFFFF - now_us);
139139

140140
/* Checking if LPTRM can handle this sleep */
141141
delta_ticks = USEC_TO_COUNT(delta_us, CLOCK_GetFreq(kCLOCK_Er32kClk));

0 commit comments

Comments
 (0)