[En-Nut-Discussion] Possible problem with timers

Nathan Moore nategoose at gmail.com
Wed Feb 24 15:51:52 CET 2016

With a system time that rolls over it is fairly easily handle rollovers as
long as
timers are never created with durations greater than 1/2 that of
unsigned_ticks_max (0xFFFFFFFF, for a 32 bit tick counter).

To do this rather than:

                if (expire_time <= current_time)


                if (0<= (expire_time - current_time)

Oh, and you have to make sure that you service your timers often enough that
you never let anything sit in the timer queue longer than 1/2 of
unsigned_ticks_max because if things in the queue get old enough they will
cease to be expired and become unexpired again.  Likewise, a time that it
far into the future will appear to be already expired, but this could be
by the timer creation routine.

This will avoid introducing 64 bit values, which were horrible on AVR the
time that I looked, and also avoid having to worry about what happens to
after 584558050 years of continuous operation of a Nut/OS system.


More information about the En-Nut-Discussion mailing list