diff --git a/src/generic/armcm_timer.c b/src/generic/armcm_timer.c index 7f11cd68..dad768e4 100644 --- a/src/generic/armcm_timer.c +++ b/src/generic/armcm_timer.c @@ -68,6 +68,25 @@ udelay(uint32_t usecs) ; } +// On fast cpus, schedule a recurring timer so SysTick doesn't overflow +static uint_fast8_t +timer_wrap_event(struct timer *t) +{ + t->waketime += 0xffffff; + return SF_RESCHEDULE; +} +static struct timer wrap_timer = { + .func = timer_wrap_event, + .waketime = 0xffffff, +}; +void +timer_reset(void) +{ + if (CONFIG_CLOCK_FREQ > 0xffffff * 10) + sched_add_timer(&wrap_timer); +} +DECL_SHUTDOWN(timer_reset); + void timer_init(void) { @@ -76,6 +95,9 @@ timer_init(void) DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; DWT->CYCCNT = 0; + // Schedule a recurring timer on fast cpus + timer_reset(); + // Enable SysTick irqstatus_t flag = irq_save(); NVIC_SetPriority(SysTick_IRQn, 2);