Bare Metal Programming Tool Kit
|
one-short timer More...
#include <rtos.h>
Public Member Functions | |
timer (task *t, const char *name="") | |
create a timer for task t, specify its name | |
void | set (time t) |
set the timer to timeout after the specified time | |
void | await (time t) |
set the timer to timeout at the specified time | |
void | cancel () |
stop and clear the timer | |
void | print (std::ostream &s, bool header=true) const |
print the timer (for debugging) | |
Friends | |
void | add (timer *t) |
void | print (std::ostream &stream) |
prints statistics about the tasks to the stream. | |
void | beat () |
one-short timer
A (one-shot) timer is a special type of flag, which can be instructed to set itself after a fixed amount of time. The amount of time is supplied with the timer::set() call. This call starts the timer. A timer that is running (waiting for its timeout to expire) can be canceled by the timer::cancel() call. When a timer that is already running is set again the previous timeout is overwritten by the new one. The suspend/resume state of its owner taks has no effect on a timer: even when the task is suspended the timer will run to its timeout and set isetlf. But of course the task, being suspended, will not be able to react.
The example below again (like the flags example) produces a left-shifting polarity-flipping Kitt display, but the actions are now caused by two timers inside the one task. Note that these timers must be started initially, and must be re-started after each timeout.
void bmptk::rtos::timer::await | ( | time | t | ) |
set the timer to timeout at the specified time
Start the timer: it will set itself at the indicated time. When the timer was already running the previous timout is overwritten.
void bmptk::rtos::timer::cancel | ( | ) |
stop and clear the timer
Stop the timer (when it was running), and clears its (when it was set).
void bmptk::rtos::timer::set | ( | time | t | ) |
set the timer to timeout after the specified time
Start the timer: it will set itself after the indicated timeout, starting from now. When the timer was already running the previous timout is overwritten.