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>
This commit is contained in:
Kevin O'Connor 2017-08-06 19:21:16 -04:00
parent 6a63c27542
commit 78982ebb51
5 changed files with 31 additions and 26 deletions

View file

@ -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;