aboutsummaryrefslogtreecommitdiffstats
path: root/src/generic/armcm_timer.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-07-24 01:03:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-07-24 01:08:18 -0400
commit79bd13dba714ceb8b5c4aad43400c75eb9061aa5 (patch)
tree4fefc981f14c2d47f134cad7809393d0e909bc6b /src/generic/armcm_timer.c
parent4e5ddff00bac76efd5bae61ab50164f045ccb578 (diff)
downloadkutter-79bd13dba714ceb8b5c4aad43400c75eb9061aa5.tar.gz
kutter-79bd13dba714ceb8b5c4aad43400c75eb9061aa5.tar.xz
kutter-79bd13dba714ceb8b5c4aad43400c75eb9061aa5.zip
armcm_timer: Support micro-controllers faster than 160Mhz
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/generic/armcm_timer.c')
-rw-r--r--src/generic/armcm_timer.c22
1 files changed, 22 insertions, 0 deletions
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);