Time Event class. More...
Public Member Functions | |
| QTimeEvt (QActive *const act, QSignal const sig, std::uint_fast8_t const tickRate=0U) noexcept | |
| The "extended" constructor to initialize a Time Event. | |
| void | 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). | |
| bool | disarm () noexcept |
| Disarm a time event. | |
| bool | rearm (std::uint32_t const nTicks) noexcept |
| Rearm a time event. | |
| bool | wasDisarmed () noexcept |
| Check whether the timeout being processed is valid (not stale). | |
| void const * | getAct () const & |
| void const * | getAct () const &&=delete |
| QTimeEvtCtr | getCtr () const noexcept |
| Get the current value of the down-counter of a time event. | |
| QTimeEvtCtr | getInterval () const noexcept |
| std::uint8_t | getTickRate () const noexcept |
| std::uint8_t | getFlags () const noexcept |
| Get the internal status flags of a time event. | |
| QActive * | toActive () noexcept |
| Get the recipient Active Object of a time event (as a pointer to QP::QActive). | |
| QTimeEvt * | toTimeEvt () noexcept |
| Get the list of newly armed time events from a head time event (as a pointer to QP::QTimeEvt). | |
| Public Member Functions inherited from QP::QEvt | |
| constexpr | QEvt (QSignal const s) noexcept |
| Event constexpr constructor applicable to immutable and mutable event instances. | |
| QEvt ()=delete | |
| Disallowed default event constructor (documented and traced together with all constructors of QP::QEvt under the code UID QP::QEvt::QEvt()). | |
| void | init () const =delete |
| Deleted initialization without arguments: compile-time check for a missing init() in event classes derived from QP::QEvt when #QEVT_PAR_INIT is defined (documented and traced together with the other overload under the code UID QP::QEvt::init()). | |
| void | init (DynEvt const dummy) const noexcept |
| Event initialization for dynamic events. | |
Static Public Member Functions | |
| static void | tick (std::uint_fast8_t const tickRate, void const *const sender) noexcept |
| Processes all armed time events at every clock tick. | |
| static void | tick1_ (std::uint_fast8_t const tickRate, void const *const sender) |
| Processes one (the next upcoming) clock tick for QUTest. | |
| static void | tickFromISR (std::uint_fast8_t const tickRate, void *const par, void const *sender) noexcept |
| static bool | noActive (std::uint_fast8_t const tickRate) noexcept |
| Check if any time events are active at a given clock tick rate. | |
Private Member Functions | |
| QTimeEvt * | expire_ (QTimeEvt *const prev_link, QActive const *const act, std::uint_fast8_t const tickRate) noexcept |
Private Attributes | |
| QTimeEvt * | m_next |
| Link to the next time event in the list . | |
| void * | m_act |
| Active object that receives the time events . | |
| QTimeEvtCtr | m_ctr |
| Down-counter of the time event. | |
| QTimeEvtCtr | m_interval |
| Interval for periodic time event (zero for one-shot time event). | |
| std::uint8_t | m_tickRate |
| std::uint8_t | m_flags |
Friends | |
| class | QXThread |
| class | QS |
Additional Inherited Members | |
| Public Types inherited from QP::QEvt | |
| enum | DynEvt : std::uint8_t { DYNAMIC } |
| Public Attributes inherited from QP::QEvt | |
| std::uint32_t | sig: 16 |
| Signal of the event (see Event Signal). | |
| std::uint32_t | poolNum_: 8 |
| Event pool number of this event. | |
| std::uint32_t | refCtr_: 8 |
| Event reference counter. | |
| std::uint32_t | filler_ |
| Member of QP::QEvt to make it identical size in QP/C++ and SafeQP/C++. | |
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.
Backward Traceability
Forward Traceability
|
noexcept |
The "extended" constructor to initialize a Time Event.
Details
When creating a time event, you must commit it to a specific active object act, tick rate tickRate and event signal sig. You cannot change these attributes later.
| [in] | act | pointer to the active object associated with this time event. The time event will post itself to this AO. |
| [in] | sig | signal to associate with this time event. |
| [in] | tickRate | system clock tick rate to associate with this time event in the range [0..(QF_MAX_TICK_RATE - 1)]. |
Backward Traceability
Forward Traceability
Definition at line 54 of file qf_time.cpp.
|
noexcept |
Definition at line 383 of file qf_time.cpp.
|
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 QP::QTimeEvt::disarm(). Also, a time event can be re-armed to fire in a different number of clock ticks by calling QP::QTimeEvt::rearm().
| [in] | nTicks | number of clock ticks (at the associated rate) to arm the time event with, in the range [1..max], where max is the maximum value of QP::QTimeEvtCtr ( 0xFF for QF_TIMEEVT_CTR_SIZE == 1U, 0xFFFF for QF_TIMEEVT_CTR_SIZE == 2U, 0xFFFFFFFF for 4U). |
| [in] | interval | interval (in clock ticks) for periodic time event, in the range [0..max] (0 means one-shot). |
Usage
The following example shows how to arm a periodic time event as well as a one-shot time event from a state machine of an active object:
Backward Traceability
Forward Traceability
Definition at line 80 of file qf_time.cpp.
|
noexcept |
Disarm a time event.
Details
Disarm the time event so it can be safely reused.
| true | If the time event was truly disarmed, that is, it was running. |
| false | If the time event was not running (never armed, already disarmed explicitly, or a one-shot time event that has been automatically disarmed upon expiration). In the last case, the time event has already been posted and should be expected in the active object's event queue. |
Backward Traceability
Forward Traceability
Definition at line 151 of file qf_time.cpp.
|
noexcept |
Rearm a time event.
Details
Rearms a time event with a new number of clock ticks. This function can be used to adjust the current period of a periodic time event or to prevent a one-shot time event from expiring (e.g., a watchdog time event). Rearming a periodic timer leaves the interval unchanged and is a convenient method to adjust the phasing of a periodic time event.
| [in] | nTicks | number of clock ticks (at the associated rate) to rearm the time event with, in the range [1..max] (max as in QP::QTimeEvt::armX()). |
After the call, the time event is armed to expire in nTicks clock ticks, regardless of the returned status. The interval is left unchanged, so a time event that was last armed as periodic stays periodic. If a timeout of this time event is still pending (posted, not acknowledged by QP::QTimeEvt::wasDisarmed()), rearming the time event makes that timeout stale (see QP::QTimeEvt::wasDisarmed()).
| true | If the time event was running as it was rearmed. |
| false | If the time event was not running (never armed, disarmed explicitly, or a one-shot time event that has been automatically disarmed upon expiration). In the last case, the previous timeout has already been posted and should be expected in the active object's event queue. |
Backward Traceability
Forward Traceability
Definition at line 196 of file qf_time.cpp.
|
noexcept |
Check whether the timeout being processed is valid (not stale).
Details
Recognizes a stale timeout in the recipient active object when a time event is reused in successive states (armed in the entry action, disarmed in the exit action): a timeout posted by the clock tick and not processed yet when the time event was disarmed, armed, or rearmed is stale and must be ignored, because it belongs to the previous use of the time event. The function is called in every state that processes the timeout of the time event (typically as a guard). The name reflects the typical case: 'true' means that the previous use ended with the time event truly disarmed (nothing pending), so the timeout belongs to the current use.
The time event tracks one pending timeout: QP::QTimeEvt::tick() marks the time event as "posted" when it posts the timeout; QP::QTimeEvt::armX(), QP::QTimeEvt::rearm(), and QP::QTimeEvt::disarm() make the pending timeout stale; this function acknowledges the timeout. A time event that has not posted any timeout yet reports its first timeout as valid.
| true | The timeout being processed is valid. |
| false | The timeout being processed is stale (posted before the time event was disarmed, armed, or rearmed) and should be ignored. |
Usage
Backward Traceability
Forward Traceability
Definition at line 270 of file qf_time.cpp.
|
inlinenoexcept |
Get the current value of the down-counter of a time event.
Details
Useful for checking how many clock ticks (at the tick rate associated with the time event) remain until the time event expires.
| value | For an armed time event, the function returns the current value of the down-counter of the given time event. The value should be != 0. |
| 0 | If the time event is not armed. |
Backward Traceability
Forward Traceability
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Get the internal status flags of a time event.
Details
Returns the internal status flags of the time event (linked in its tick-rate list, the next timeout valid, timeout posted and not acknowledged). The flags occupy the high nibble of the returned byte. Used by the QS-RX query of the current Time Event object (Query-TE), which reports the tick rate in the low nibble and these flags in the high nibble of one byte.
Backward Traceability
Forward Traceability
|
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.
| [in] | tickRate | clock tick rate serviced in this call [0..(QF_MAX_TICK_RATE - 1)]. |
| [in] | sender | pointer to a sender object (only for QS tracing) |
Backward Traceability
Forward Traceability
Definition at line 288 of file qf_time.cpp.
|
static |
Processes one (the next upcoming) clock tick for QUTest.
Forward Traceability
|
staticnoexcept |
Check if any time events are active at a given clock tick rate.
| [in] | tickRate | system clock tick rate to find out about. |
| true | If no time events are armed at the given tick rate |
| false | Otherwise. |
Backward Traceability
Forward Traceability
Definition at line 370 of file qf_time.cpp.
|
inlinenoexcept |
Get the recipient Active Object of a time event (as a pointer to QP::QActive).
Details
Returns the pointer stored in the time event as a pointer to QP::QActive. Used inside the Framework to post the time event to its recipient when the time event expires.
Forward Traceability
|
inlinenoexcept |
Get the list of newly armed time events from a head time event (as a pointer to QP::QTimeEvt).
Details
Returns the pointer stored in the time event as a pointer to QP::QTimeEvt. Used only for the special head time events (QP::QTimeEvt_head_), in which this pointer links the time events that were armed (or re-armed) since the last processing of the given tick rate.
Forward Traceability
|
privatenoexcept |
Definition at line 394 of file qf_time.cpp.
|
private |
|
private |
|
private |
Down-counter of the time event.
Details
The down-counter is decremented by 1 in every QP::QTimeEvt::tick() call. The time event fires (gets posted or published) when the down-counter reaches zero.
|
private |