diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-08-06 19:21:16 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-08-08 00:27:28 -0400 |
commit | 78982ebb51b0895b3178a85edcb1543939dc13b4 (patch) | |
tree | a1961fb294104a81e37ff3af93e643fdd35e5f30 /src/sched.c | |
parent | 6a63c27542fc7b432ed438ce1d62243b5aebc3da (diff) | |
download | kutter-78982ebb51b0895b3178a85edcb1543939dc13b4.tar.gz kutter-78982ebb51b0895b3178a85edcb1543939dc13b4.tar.xz kutter-78982ebb51b0895b3178a85edcb1543939dc13b4.zip |
avr: Implement internal avr specific timer to handle 16bit overflows
Don't rely on the generic scheduler code to always have a timer no
more than 1ms in the future. Instead, create an avr specific timer
that will be called every 0x8000 ticks. This simplifies the generic
code and it reduces the amount of code that needs to be run every
millisecond.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/sched.c')
-rw-r--r-- | src/sched.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/sched.c b/src/sched.c index 92fc5504..0aadcc75 100644 --- a/src/sched.c +++ b/src/sched.c @@ -24,12 +24,11 @@ static struct timer sentinel_timer, deleted_timer; // The periodic_timer simplifies the timer code by ensuring there is // always a timer on the timer list and that there is always a timer -// not more than 1ms in the future. +// not far in the future. static uint_fast8_t periodic_event(struct timer *t) { - timer_periodic(); - periodic_timer.waketime += timer_from_us(1000); + periodic_timer.waketime += timer_from_us(100000); sentinel_timer.waketime = periodic_timer.waketime + 0x80000000; return SF_RESCHEDULE; } @@ -162,9 +161,9 @@ sched_timer_dispatch(void) return next_waketime; } -// Shutdown all user timers on an emergency stop. -void -sched_timer_shutdown(void) +// Remove all user timers on a shutdown +static void +sched_timer_reset(void) { timer_list = &deleted_timer; deleted_timer.waketime = periodic_timer.waketime; @@ -172,7 +171,6 @@ sched_timer_shutdown(void) periodic_timer.next = &sentinel_timer; timer_kick(); } -DECL_SHUTDOWN(sched_timer_shutdown); /**************************************************************** @@ -230,6 +228,7 @@ run_shutdown(int reason) if (!shutdown_status) shutdown_reason = reason; shutdown_status = 2; + sched_timer_reset(); extern void ctr_run_shutdownfuncs(void); ctr_run_shutdownfuncs(); shutdown_status = 1; |