Files CCore/inc/task/Tick.h CCore/src/task/Tick.cpp
TickJob can be used to do some processing during the system tick.
class TickJob : NoCopy
{
....
public:
explicit TickJob(Function<void (void)> action_int);
~TickJob();
// IntLocked
bool isActive() const { return active; }
void start();
void stop();
};
The argument of the TickJob constructor is an action function. This function will be called during the system tick, if the TickJob object is activated. The function is called in the interrupt context and as such must be a "quick function".
TickJob destructor calls Abort(), if the object is not deactivated.
All other TickJob methods must be called under IntLock protection.
isActive() returns true, if the object is activated.
start() activates the object. It does nothing, if the object is already active.
stop() deactivates the object. It does nothing, if the object is not active.
The class TickCount is required to count ticks to implement timeouts and periodic time events. It is built using a generic class, parametrized by a tick frequency.
template <unsigned TPS> class TickCount_gen { unsigned t; unsigned r; // represents fraction (t*TPS+r)/1000 public: TickCount_gen() { set(0); } void set(unsigned timeout_msec); bool tick(); bool tick(unsigned period_msec); }; using TickCount = TickCount_gen<TicksPerSec> ;
Internally TickCount stores the remaining time until an event. It decrements it each tick. The initial time in milliseconds can be set by the method set(). Countdown is performed by the method tick(). The method without parameter is used, if the only one event is required. If the periodic tick is required, then tick() with the required period in milliseconds must be used. Both methods return true to signal about the event. The generated event period is statistically precise, unless it is less than the tick period (more precisely, the inequality period_msec > 1000/TPS must hold true, this is satisfied, if TPS >1000 ).
The constant TicksPerSec is a system tick frequency and provided by the target:
const unsigned TicksPerSec = .... ;
in the file dev/DevTick.h.