Time Event class.
- Details
Time events are special QF events equipped with the notion of time passage. The basic usage model of the time events is as follows. An active object allocates one or more QP::QTimeEvt objects (provides the storage for them). When the active object needs to arrange for a timeout, it arms one of its time events to fire either just once (one-shot) or periodically. Each time event times out independently from the others, so a QF application can make multiple parallel timeout requests (from the same or different active objects). When QF detects that the appropriate moment has arrived, it inserts the time event directly into the recipient's event queue. The recipient then processes the time event just like any other event.
Time events, as any other QF events derive from the QP::QEvt base class. Typically, you will use a time event as-is, but you can also further derive more specialized time events from it by adding some more data members and/or specialized functions that operate on the specialized time events.
Internally, the armed time events are organized into linked lists–one list for every supported ticking rate. These linked lists are scanned in every invocation of the QTIMEEVT_TICK_X() macro. Only armed (timing out) time events are in the list, so only armed time events consume CPU cycles.
- Note
- Even though QP::QTimeEvt is a subclass of QP::QEvt, QP::QTimeEvt instances can NOT be allocated dynamically from event pools. In other words, it is illegal to allocate QP::QTimeEvt instances with the QP::QF::q_new() or QP::QF::q_new_x() function templates.
- Backward Traceability
Definition at line 775 of file qp.hpp.
void QP::QTimeEvt::armX |
( |
std::uint32_t const | nTicks, |
|
|
std::uint32_t const | interval = 0U ) |
|
noexcept |
Arm a time event (extended version for one shot or periodic time event)
- Details
Arms a time event to fire in a specified number of clock ticks and with a specified interval. If the interval is zero, the time event is armed for one shot ('one-shot' time event). When the timeout expires, the time event gets directly posted (using the FIFO policy) into the event queue of the host active object. After posting, a one-shot time event gets automatically disarmed while a periodic time event (interval != 0) is automatically re-armed.
A time event can be disarmed at any time by calling QTimeEvt_disarm(). Also, a time event can be re-armed to fire in a different number of clock ticks by calling the QTimeEvt_rearm().
- Parameters
-
[in] | nTicks | number of clock ticks (at the associated rate) to rearm the time event with. |
[in] | interval | interval (in clock ticks) for periodic time event. |
- Precondition
qf_time:400
- the host AO must be valid,
- the time eveht must be disarmed,
- the number of clock ticks cannot be zero,
- the signal must be valid.
- Attention
- Arming an already armed time event is not allowed and is considered a programming error. The QP/C++ framework will assert if it detects an attempt to arm an already armed time event.
- Backward Traceability
- Usage
The following example shows how to arm a periodic time event as well as one-shot time event from a state machine of an active object:
QState Game_show_logo(Tunnel *
const me,
QEvt const *
const e) {
case Q_ENTRY_SIG: {
QTimeEvt_armX(&me->blinkTimeEvt,
BSP_TICKS_PER_SEC/2U,
BSP_TICKS_PER_SEC/2U);
QTimeEvt_armX(&me->screenTimeEvt,
BSP_TICKS_PER_SEC*5U,
0U);
. . .
break;
}
. . .
QSignal sig
Signal of the event (see Event Signal)
constexpr QEvt(QSignal const s) noexcept
Event constexpr constructor applicable to immutable and mutable event instances.
std::uint_fast8_t QState
Type returned from state-handler functions.
Definition at line 72 of file qf_time.cpp.
void QP::QTimeEvt::tick |
( |
std::uint_fast8_t const | tickRate, |
|
|
void const *const | sender ) |
|
staticnoexcept |
Processes all armed time events at every clock tick.
- Details
This internal helper function processes all armed QP::QTimeEvt objects associated with the tick rate tickRate
.
This function must be called periodically from a time-tick ISR or from a task so that QF can manage the timeout events assigned to the given system clock tick rate.
- Parameters
-
[in] | tickRate | clock tick rate serviced in this call [1..15]. |
[in] | sender | pointer to a sender object (only for QS tracing) |
- Note
- this function should be called only via the macro QTIMEEVT_TICK_X().
-
The calls to QTimeEvt_tick_() with different
tickRate
parameter can preempt each other. For example, higher clock tick rates might be serviced from interrupts while others from tasks (active objects).
- Backward Traceability
Definition at line 258 of file qf_time.cpp.