Time Event class. More...
#include <qp.h>
Public Member Functions | |
| void | QTimeEvt_ctorX (QTimeEvt *const me, QActive *const act, enum_t const sig, uint_fast8_t const tickRate) |
| The "extended" constructor to initialize a Time Event. | |
| void | QTimeEvt_armX (QTimeEvt *const me, uint32_t const nTicks, uint32_t const interval) |
| Arm a time event (extended version for one-shot or periodic time event). | |
| bool | QTimeEvt_disarm (QTimeEvt *const me) |
| Disarm a time event. | |
| bool | QTimeEvt_rearm (QTimeEvt *const me, uint32_t const nTicks) |
| Rearm a time event. | |
| bool | QTimeEvt_wasDisarmed (QTimeEvt *const me) |
| Check the "was disarmed" status of a time event. | |
| QTimeEvtCtr | QTimeEvt_getCtr (QTimeEvt const *const me) |
| Get the current value of the down-counter of a time event. | |
| Public Member Functions inherited from QEvtPtr | |
| void | QEvt_ctor (QEvt *const me, enum_t const sig) |
| QEvt constructor | |
| QEvt * | QEvt_init (QEvt *const me, uint8_t const dummy) |
| Event without parameters initialization. | |
Static Public Member Functions | |
| bool | QTimeEvt_noActive (uint_fast8_t const tickRate) |
| Check if any time events are active at a given clock tick rate. | |
Protected Attributes | |
| QEvt | super |
Private Member Functions | |
| QTimeEvt * | QTimeEvt_expire_ (QTimeEvt *const me, QTimeEvt *const prev_link, QActive const *const act, uint_fast8_t const tickRate) |
Static Private Member Functions | |
| void | QTimeEvt_init (void) |
| void | QTimeEvt_tick_ (uint_fast8_t const tickRate, void const *const sender) |
| Processes all armed time events at every clock tick. | |
| void | QTimeEvt_tick1_ (uint_fast8_t const tickRate, void const *const sender) |
| Processes one clock tick for QUTest. | |
Private Attributes | |
| struct QTimeEvt * | next |
| Link to the next time event in the list. | |
| void * | act |
| Active object that receives the time events. | |
| QTimeEvtCtr | ctr |
| Down-counter of the time event. | |
| QTimeEvtCtr | interval |
| Interval for periodic time event (zero for one-shot time event). | |
| uint8_t | tickRate |
| uint8_t | flags |
| QTimeEvt | QTimeEvt_timeEvtHead_ [QF_MAX_TICK_RATE] |
| Static array of heads of linked lists of time events (one for every clock tick rate). | |
Additional Inherited Members | |
| Public Attributes inherited from QEvtPtr | |
| uint32_t | sig: 16 |
| Event signal (see Event Signal). | |
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 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 that 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 QEvt base class. Typically, you will use a time event as-is. Still, 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
| void QTimeEvt_ctorX | ( | QTimeEvt *const | me, |
| QActive *const | act, | ||
| enum_t const | sig, | ||
| uint_fast8_t const | tickRate ) |
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,out] | me | current instance pointer (see SAS_QP_OOA) |
| [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..15]. |
Forward Traceability
| void QTimeEvt_armX | ( | QTimeEvt *const | me, |
| uint32_t const | nTicks, | ||
| uint32_t const | interval ) |
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().
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
| [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. |
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:
Forward Traceability
| bool QTimeEvt_disarm | ( | QTimeEvt *const | me | ) |
Disarm a time event.
Details
Disarm the time event so it can be safely reused.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
Forward Traceability
| bool QTimeEvt_rearm | ( | QTimeEvt *const | me, |
| uint32_t const | nTicks ) |
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,out] | me | current instance pointer (see SAS_QP_OOA) |
| [in] | nTicks | number of clock ticks (at the associated rate) to rearm the time event with. |
Forward Traceability
| bool QTimeEvt_wasDisarmed | ( | QTimeEvt *const | me | ) |
Check the "was disarmed" status of a time event.
Details
Useful for checking whether a one-shot time event was disarmed in the QTimeEvt_disarm() operation.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
Forward Traceability
| QTimeEvtCtr QTimeEvt_getCtr | ( | QTimeEvt const *const | me | ) |
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.
| [in,out] | me | current instance pointer (see SAS_QP_OOA) |
Forward Traceability
|
staticprivate |
Processes all armed time events at every clock tick.
Details
This internal helper function processes all armed 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 [1..15]. |
| [in] | sender | pointer to a sender object (only for QS tracing) |
Forward Traceability
|
staticprivate |
|
static |
Check if any time events are active at a given clock tick rate.
| [in] | tickRate | system clock tick rate to find out about. |
Forward Traceability
|
private |
|
private |
|
private |
Down-counter of the time event.
Details
The down-counter is decremented by 1 in every QTimeEvt_tick_() call. The time event fires (gets posted or published) when the down-counter reaches zero.
Forward Traceability
|
private |
|
private |