Public QEP/C interface. More...
#include "qevent.h"#include "qs_port.h"Go to the source code of this file.
Data Structures | |
| struct | QFsm |
| Finite State Machine. More... | |
Defines | |
| #define | QFsm_ctor(me_, initial_) ((me_)->state = (initial_)) |
| Protected "constructor" of a FSM. | |
| #define | QHsm_ctor(me_, initial_) ((me_)->state = (initial_)) |
| protected "constructor" of a HSM. Performs the first step of HSM initialization by assigning the initial pseudostate to the currently active state of the state machine. | |
| #define | Q_RET_IGNORED ((QState)1) |
| Value returned by a non-hierarchical state-handler function when it ignores (does not handle) the event. | |
| #define | Q_IGNORED() (Q_RET_IGNORED) |
| The macro returned from a non-hierarchical state-handler function when it ignores (does not handle) the event. | |
| #define | Q_RET_HANDLED ((QState)0) |
| Value returned by a state-handler function when it handles the event. | |
| #define | Q_HANDLED() (Q_RET_HANDLED) |
| Value returned by a state-handler function when it handles the event. | |
| #define | Q_RET_TRAN ((QState)2) |
| Value returned by a state-handler function when it takes a regular state transition. | |
| #define | Q_TRAN(target_) (((QFsm *)me)->state = (QStateHandler)(target_), Q_RET_TRAN) |
| Designates a target for an initial or regular transition. Q_TRAN() can be used both in the FSMs and HSMs. | |
| #define | Q_RET_SUPER ((QState)3) |
| Value returned by a state-handler function when it cannot handle the event. | |
| #define | Q_SUPER(super_) (((QHsm *)me)->state = (QStateHandler)(super_), Q_RET_SUPER) |
| Designates the superstate of a given state in an HSM. | |
| #define | QS_SIG_(sig_) QS_u8_(sig_) |
| Internal QS macro to output an unformatted event signal data element. | |
Typedefs | |
| typedef uint8_t | QState |
| Type returned from a state-handler function. | |
| typedef QState(* | QStateHandler )(void *me, QEvent const *e) |
| pointer to state-handler function | |
| typedef struct QFsmTag | QHsm |
| Hierarchical State Machine. | |
Enumerations | |
| enum | QReservedSignals { Q_ENTRY_SIG = 1, Q_EXIT_SIG, Q_INIT_SIG, Q_USER_SIG } |
QEP reserved signals. More... | |
Functions | |
| char const Q_ROM *Q_ROM_VAR | QEP_getVersion (void) |
| obtain the current QEP version number string | |
| void | QFsm_init (QFsm *me, QEvent const *e) |
| Performs the second step of FSM initialization by triggering the top-most initial transition. | |
| void | QFsm_dispatch (QFsm *me, QEvent const *e) |
| Dispatches an event to a FSM. | |
| void | QHsm_init (QHsm *me, QEvent const *e) |
| Performs the second step of HSM initialization by triggering the top-most initial transition. | |
| void | QHsm_dispatch (QHsm *me, QEvent const *e) |
| Dispatches an event to a HSM. | |
| uint8_t | QHsm_isIn (QHsm *me, QStateHandler state) |
| Tests if a given state is part of the current active state configuratioin. | |
| QState | QHsm_top (QHsm *me, QEvent const *e) |
| the top-state. | |
Public QEP/C interface.
This header file must be included, perhaps indirectly, in all modules (*.c files) that use QEP/C
Definition in file qep.h.
| #define Q_HANDLED | ( | ) | (Q_RET_HANDLED) |
Value returned by a state-handler function when it handles the event.
You call that macro after the return statement (return Q_HANDLED();) Q_HANDLED() can be used both in the FSMs and HSMs.
| #define Q_IGNORED | ( | ) | (Q_RET_IGNORED) |
The macro returned from a non-hierarchical state-handler function when it ignores (does not handle) the event.
You call that macro after the return statement (return Q_IGNORED();)
Definition at line 219 of file qep.h.
Referenced by QHsm_top().
| #define Q_SUPER | ( | super_ | ) | (((QHsm *)me)->state = (QStateHandler)(super_), Q_RET_SUPER) |
| #define Q_TRAN | ( | target_ | ) | (((QFsm *)me)->state = (QStateHandler)(target_), Q_RET_TRAN) |
| #define QFsm_ctor | ( | me_, | |||
| initial_ | ) | ((me_)->state = (initial_)) |
Protected "constructor" of a FSM.
Performs the first step of FSM initialization by assigning the initial pseudostate to the currently active state of the state machine.
The following example illustrates how to invoke QFsm_ctor() in the "constructor" of a derived state machine:
void QBomb_ctor(QBomb *me) { QFsm_ctor(&me->super, (QStateHandler)&QBomb_initial);/* superclass ctor */ }
| #define QHsm_ctor | ( | me_, | |||
| initial_ | ) | ((me_)->state = (initial_)) |
protected "constructor" of a HSM. Performs the first step of HSM initialization by assigning the initial pseudostate to the currently active state of the state machine.
The following example illustrates how to invoke QHsm_ctor() in the "constructor" of a derived state machine:
void QCalc_ctor(QCalc *me) { QHsm_ctor(&me->super, (QStateHandler)&QCalc_initial); }
| #define QS_SIG_ | ( | sig_ | ) | QS_u8_(sig_) |
Internal QS macro to output an unformatted event signal data element.
Definition at line 286 of file qep.h.
Referenced by QActive_get_(), QActive_postFIFO(), QActive_postLIFO(), QActive_subscribe(), QActive_unsubscribe(), QActive_unsubscribeAll(), QEQueue_get(), QEQueue_postFIFO(), QEQueue_postLIFO(), QF_gc(), QF_new_(), QF_publish(), QF_tick(), QFsm_dispatch(), and QHsm_dispatch().
| typedef struct QFsmTag QHsm |
Hierarchical State Machine.
QHsm represents a Hierarchical Finite State Machine (HSM) with full support for hierarchical nesting of states, entry/exit actions, and initial transitions in any composite state.
The following example illustrates how to derive a state machine structure from QHsm. Please note that the QHsm member super is defined as the FIRST member of the derived struct.
| enum QReservedSignals |
| char const Q_ROM* Q_ROM_VAR QEP_getVersion | ( | void | ) |
obtain the current QEP version number string
Definition at line 46 of file qep.c.
References Q_ROM, Q_ROM_VAR, and QP_VERSION.
Dispatches an event to a FSM.
Processes one event at a time in Run-to-Completion fashion. The argument me is the pointer the state machine structure derived from QFsm. The argument e is a constant pointer the QEvent or a structure derived from QEvent.
Definition at line 37 of file qfsm_dis.c.
References Q_ENTRY_SIG, Q_EXIT_SIG, Q_RET_HANDLED, Q_RET_TRAN, QEP_TRIG_, QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_IGNORED, QS_QEP_INTERN_TRAN, QS_QEP_TRAN, QS_SIG_, QS_smObj_, QEvent::sig, and QFsm::state.
Performs the second step of FSM initialization by triggering the top-most initial transition.
| me | pointer the state machine structure derived from QFsm | |
| e | constant pointer the QEvent or a structure derived from QEvent |
The following example illustrates how to initialize a FSM, and dispatch events to it:
#include "qep.h" /* QEP/C public interface */ #include "qbomb.h" /* QBomb FSM derived from QFsm */ static QBomb l_qbomb; /* an instance of QBomb FSM */ int main() { QBombInitEvt ie; /* initialization event for QBomb FSM */ QBomb_ctor(&l_qbomb); /* QBomb FSM "constructor" invokes QFsm_ctor_() */ /* set the initialization event ie */ QFsm_init((QFsm *)&l_qbomb, &ie); /* trigger initial transition */ for (;;) { /* event loop */ QEvent e; . . . /* wait for the next event and assign it to the event object e */ . . . QFsm_dispatch((QFsm *)&l_qbomb, &e); /* dispatch e to l_qbomb */ } return 0; }
Definition at line 40 of file qfsm_ini.c.
References Q_ALLEGE, Q_ENTRY_SIG, Q_RET_TRAN, QEP_TRIG_, QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_INIT_TRAN, QS_QEP_STATE_INIT, and QS_smObj_.
Dispatches an event to a HSM.
Processes one event at a time in Run-to-Completion fashion.
| me | is the pointer the state machine structure derived from QHsm. | |
| e | is a constant pointer the QEvent or a structure derived from QEvent. |
Definition at line 40 of file qhsm_dis.c.
References Q_ASSERT, Q_EXIT_SIG, Q_INIT_SIG, Q_RET_HANDLED, Q_RET_IGNORED, Q_RET_SUPER, Q_RET_TRAN, QEP_EMPTY_SIG_, QEP_ENTER_, QEP_EXIT_, QEP_MAX_NEST_DEPTH_, QEP_TRIG_, QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_DISPATCH, QS_QEP_IGNORED, QS_QEP_INTERN_TRAN, QS_QEP_STATE_EXIT, QS_QEP_STATE_INIT, QS_QEP_TRAN, QS_SIG_, and QS_smObj_.
Performs the second step of HSM initialization by triggering the top-most initial transition.
| me | pointer the state machine structure derived from QHsm | |
| e | constant pointer the QEvent or a structure derived from QEvent |
The following example illustrates how to initialize a HSM, and dispatch events to it:
#include "qep.h" /* QEP/C public interface */ #include "qcalc.h" /* QCalc HSM derived from QHsm */ static QCalc l_qcalc; /* an instance of QCalc HSM */ int main() { QCalc_ctor(&l_qcalc); /* QCalc HSM "constructor" invokes QHsm_ctor_() */ QHsm_init((QHsm *)&l_qcalc, (QEvent *)0); /* trigger initial transition */ for (;;) { /* event loop */ QEvent e; . . . /* wait for the next event and assign it to the event object e */ . . . QHsm_dispatch((QHsm *)&l_qcalc, (QEvent *)&e); /* dispatch e */ } return 0; }
Definition at line 40 of file qhsm_ini.c.
References Q_ALLEGE, Q_ASSERT, Q_INIT_SIG, Q_RET_TRAN, QEP_EMPTY_SIG_, QEP_ENTER_, QEP_MAX_NEST_DEPTH_, QEP_TRIG_, QHsm_top(), QS_BEGIN_, QS_END_, QS_FUN_, QS_INT_LOCK_KEY_, QS_OBJ_, QS_QEP_INIT_TRAN, QS_QEP_STATE_INIT, and QS_smObj_.
| uint8_t QHsm_isIn | ( | QHsm * | me, | |
| QStateHandler | state | |||
| ) |
Tests if a given state is part of the current active state configuratioin.
| me | is the pointer the state machine structure derived from QHsm. | |
| state | is a pointer to the state handler function, e.g., &QCalc_on. |
Definition at line 37 of file qhsm_in.c.
References Q_RET_IGNORED, QEP_EMPTY_SIG_, and QEP_TRIG_.
the top-state.
QHsm_top() is the ultimate root of state hierarchy in all HSMs derived from QHsm. This state handler always returns (QSTATE)0, which means that it "handles" all events.
Definition at line 37 of file qhsm_top.c.
References Q_IGNORED.
Referenced by QHsm_init().
1.6.3