40Q_DEFINE_THIS_MODULE(
"qep_msm")
43#define QMSM_MAX_NEST_DEPTH_ ((size_t)6U)
48static struct QMState const l_msm_top_s = {
58#define QS_STATE_ACT_(rec_, state_) \
60 QS_BEGIN_PRE((rec_), qsId) \
67#define QS_TOP_INIT_(rec_, trg_) \
69 QS_BEGIN_PRE((rec_), qsId) \
77#define QS_TRAN_SEG_(rec_, src_, trg_) \
79 QS_BEGIN_PRE((rec_), qsId) \
87#define QS_TRAN0_(rec_, trg_) \
89 QS_BEGIN_PRE((rec_), qsId) \
98#define QS_TRAN_END_(rec_, src_, trg_) \
100 QS_BEGIN_PRE((rec_), qsId) \
102 QS_SIG_PRE(e->sig); \
110#define QS_STATE_ACT_(rec_, state_) ((void)0)
111#define QS_TOP_INIT_(rec_, trg_) ((void)0)
112#define QS_TRAN_SEG_(rec_, src_, trg_) ((void)0)
113#define QS_TRAN0_(rec_, trg_) ((void)0)
114#define QS_TRAN_END_(rec_, src_, trg_) ((void)0)
122static QState QMsm_execTatbl_(
125 uint_fast8_t
const qsId);
127static void QMsm_exitToTranSource_(
129 QMState const *
const curr_state,
130 QMState const *
const tran_source,
131 uint_fast8_t
const qsId);
133static QState QMsm_enterHistory_(
136 uint_fast8_t
const qsId);
150 me->super.
vptr = &vtable;
151 me->super.
state.obj = &l_msm_top_s;
152 me->super.
temp.fun = initial;
159 void const *
const e,
160 uint_fast8_t
const qsId)
183 me->
state.obj->stateHandler, me->
temp.tatbl->target->stateHandler);
191 }
while (r == Q_RET_TRAN_INIT);
205 QEvt const *
const e,
206 uint_fast8_t
const qsId)
228 r = (*s->stateHandler)(me, e);
229 if (r >= Q_RET_HANDLED) {
233 if (r == Q_RET_UNHANDLED) {
252 else if (r == Q_RET_HANDLED) {
255 else if ((r == Q_RET_TRAN) || (r == Q_RET_TRAN_HIST)) {
260 if (r == Q_RET_TRAN) {
262 QMsm_exitToTranSource_(me, t, s, qsId);
270 s->stateHandler, hist->stateHandler);
274 QMsm_exitToTranSource_(me, t, s, qsId);
282 while (r == Q_RET_TRAN_INIT) {
291 QS_TRAN_END_(
QS_QEP_TRAN, ts->stateHandler, s->stateHandler);
308 uint_fast8_t
const qsId)
324 if (r == Q_RET_ENTRY) {
327 else if (r == Q_RET_EXIT) {
330 else if (r == Q_RET_TRAN_INIT) {
332 tatbl->target->stateHandler,
333 me->
temp.tatbl->target->stateHandler);
342 me->
state.obj = tatbl->target;
348static void QMsm_exitToTranSource_(
350 QMState const *
const curr_state,
351 QMState const *
const tran_source,
352 uint_fast8_t
const qsId)
364 while (s != tran_source) {
367 (void)(*s->exitAction)(me);
379 uint_fast8_t
const qsId)
389 while (s != me->
state.obj) {
404 (void)(*path[ip]->entryAction)(me);
408 me->
state.obj = hist;
413 r = (*hist->initAction)(me);
415 hist->stateHandler, me->
temp.tatbl->target->stateHandler);
422QMState const * QMsm_topQMState(
void) {
429 bool inState =
false;
432 if (s->stateHandler == stateHndl) {
445 QMsm const *
const me,
446 QMState const *
const parentHndl)
450 bool isFound =
false;
452 if (s == parentHndl) {
472 return me->super.
state.obj;
478 return me->
state.obj->stateHandler;
#define QMSM_MAX_NEST_DEPTH_
Maximum depth of nesting levels in a QMsm state machines \clearpage .
#define Q_UNUSED_PAR(par_)
Helper macro to mark unused parameters of functions.
QState(*) QActionHandler(void *const me)
Pointer to an action-handler function.
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
#define Q_ACTION_CAST(action_)
Perform cast to QActionHandler.
#define Q_EVT_CAST(class_)
Perform downcast of an event onto a subclass of QEvt class_.
QState(*) QStateHandler(void *const me, QEvt const *const e)
Pointer to a state-handler function.
uint_fast8_t QState
Type returned from state-handler functions.
QP/C Framework in C internal (package-scope) interface.
#define QP_DIS_UPDATE(T_, org_)
Update Duplicate Inverse Storage integer variable.
#define QP_DIS_VERIFY(T_, org_, dis_)
Verify integer variable against its Duplicate Inverse Storage.
#define QS_CRIT_STAT
Internal QS macro for defining the critical section status \clearpage .
@ QS_QEP_STATE_INIT
an initial transition was taken in a state
@ QS_QEP_TRAN_HIST
a tran. to history was taken
@ QS_QEP_STATE_EXIT
a state was exited
@ QS_QEP_INIT_TRAN
the top-most initial transition was taken
@ QS_QEP_INTERN_TRAN
an internal transition was taken
@ QS_QEP_STATE_ENTRY
a state was entered
@ QS_QEP_UNHANDLED
an event was un-handled due to a guard
@ QS_QEP_TRAN
a regular transition was taken
@ QS_QEP_DISPATCH
an event was dispatched (begin of RTC step)
@ QS_QEP_IGNORED
an event was ignored (silently discarded)
#define QS_CRIT_EXIT()
Internal macro for exiting a critical section \clearpage .
#define QS_CRIT_ENTRY()
Internal macro for entering a critical section \clearpage .
QS (QP/Spy software tracing) internal (package-scope) interface. \clearpage .
#define QS_OBJ_PRE(obj_)
Output pre-formatted object pointer element.
#define QS_SIG_PRE(sig_)
Output pre-formatted event signal data element.
#define QS_FUN_PRE(fun_)
Output pre-formatted function pointer element.
#define QS_END_PRE()
Pre-formatted QS trace record end.
#define QS_BEGIN_PRE(rec_, qsId_)
Pre-formatted QS trace record begin.
QP Functional Safety (FuSa) Subsystem (fault detection).
#define Q_REQUIRE_LOCAL(id_, expr_)
Assertion for checking a precondition (local critical section).
#define Q_ERROR_LOCAL(id_)
Assertion with user-specified ID for a wrong path through the code (local critical section).
#define Q_ENSURE_LOCAL(id_, expr_)
Assertion for checking a postcondition (local critical section).
#define Q_ASSERT_LOCAL(id_, expr_)
General-purpose assertion with user-specified ID number (local critical section).
#define Q_INVARIANT_LOCAL(id_, expr_)
Assertion for checking a postcondition (local critical section).
Abstract State Machine class (state machine interface).
struct QAsmVtable const * vptr
Virtual pointer inherited by all QAsm subclasses (see also [SAS_QP_TECH_20]).
union QAsmAttr state
Current state (pointer to the current state-handler function).
union QAsmAttr temp
Temporary storage for target/act-table etc..
Virtual table for the QAsm class.
uint32_t sig
Event signal (see Event Signal).
State object for the QMsm class (QM State Machine).
Transition-Action Table for the QMsm State Machine \clearpage .
Hierarchical State Machine class (QMsm-style implementation strategy).
static QState QMsm_enterHistory_(QAsm *const me, QMState const *const hist, uint_fast8_t const qsId)
Enter history of a composite state.
void QMsm_init_(QAsm *const me, void const *const e, uint_fast8_t const qsId)
Implementation of the top-most initial transition in QMsm.
static QState QMsm_execTatbl_(QAsm *const me, QMTranActTable const *const tatbl, uint_fast8_t const qsId)
Execute transition-action table.
bool QMsm_isIn_(QAsm *const me, QStateHandler const stateHndl)
Tests if a given state is part of the current active state configuration.
QMState const * QMsm_childStateObj(QMsm const *const me, QMState const *const parentHndl)
Obtain the current active child state of a given parent in QMsm.
void QMsm_dispatch_(QAsm *const me, QEvt const *const e, uint_fast8_t const qsId)
Implementation of dispatching events to a QMsm.
QStateHandler QMsm_getStateHandler_(QAsm const *const me)
Implementation of getting the state handler in an QMsm subclass.
void QMsm_ctor(QMsm *const me, QStateHandler const initial)
Constructor of QMsm.
QMState const * QMsm_stateObj(QMsm const *const me)
Obtain the current state from a MSM (read only).