From a1c61563a0312c9c9f7c050e4a7588537585e49a Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 31 Mar 2017 14:26:29 -0400 Subject: [PATCH] avr: Fix bug causing timer_read_time() to not be in sync with scheduler Commit 16e3dbb1 changed the avr implementation of timer_read_time(). Unfortunately, it raised the possibility for timer_read_time() to be out of sync with the scheduler's understanding of the current time. In particular, it was common for the timer irq to overflow the 16bit hardware counter once at startup, and this would lead to timer_read_time() always returning a time ~4ms ahead of the scheduler on 16Mhz chips. This resulted in "Move queue empty" errors. To resolve this issue, only increment timer_high from timer_periodic() and make sure the timer irqs start immediately after timer_init(). Signed-off-by: Kevin O'Connor --- src/avr/timer.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/avr/timer.c b/src/avr/timer.c index ac7509ed..c0a04624 100644 --- a/src/avr/timer.c +++ b/src/avr/timer.c @@ -70,6 +70,17 @@ timer_repeat_set(uint16_t next) TIFR1 = 1<