diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-08-10 13:11:27 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-08-11 09:32:06 -0400 |
commit | 8ebba6d27af1e4a0b1bf338d5bc423465a8625b7 (patch) | |
tree | 2a0b4ba4a6c94615f1cdf7e2401a62f467bd2334 /src | |
parent | 1051a52755f3f9b8f8b9d21a430ddf3b9982e5a0 (diff) | |
download | kutter-8ebba6d27af1e4a0b1bf338d5bc423465a8625b7.tar.gz kutter-8ebba6d27af1e4a0b1bf338d5bc423465a8625b7.tar.xz kutter-8ebba6d27af1e4a0b1bf338d5bc423465a8625b7.zip |
avr: Make sure timer_high and timer_event() stay in sync
Schedule the next wakeup time of timer_event() using timer_high.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/avr/timer.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/avr/timer.c b/src/avr/timer.c index ae6c36cd..e40007d8 100644 --- a/src/avr/timer.c +++ b/src/avr/timer.c @@ -137,16 +137,20 @@ timer_read_time(void) static uint_fast8_t timer_event(struct timer *t) { + union u32_u *nextwake = (void*)&wrap_timer.waketime; if (TIFR1 & (1<<TOV1)) { // Hardware timer has overflowed - update overflow counter TIFR1 = 1<<TOV1; timer_high++; + *nextwake = (union u32_u){ .hi = timer_high, .lo = 0x8000 }; + } else { + *nextwake = (union u32_u){ .hi = timer_high + 1, .lo = 0x0000 }; } - wrap_timer.waketime += 0x8000; return SF_RESCHEDULE; } static struct timer wrap_timer = { .func = timer_event, + .waketime = 0x8000, }; #define TIMER_IDLE_REPEAT_TICKS 8000 |