Re: Possible problem with timers

Nathan Moore <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.ethernut
Message-ID <CAAJh09UkmvPektq68oivbrDRyUgMFAcjvdN5m09Z6o4hgkE+XA@mail.gmail.com>
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)

do:

                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
too
far into the future will appear to be already expired, but this could be
caught
by the timer creation routine.

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


Nathan
_______________________________________________
http://lists.egnite.de/mailman/listinfo/en-nut-discussion
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.