From 79bd13dba714ceb8b5c4aad43400c75eb9061aa5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 24 Jul 2019 01:03:23 -0400 Subject: [PATCH] armcm_timer: Support micro-controllers faster than 160Mhz Signed-off-by: Kevin O'Connor --- src/generic/armcm_timer.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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);