42Q_DEFINE_THIS_MODULE(
"qep_msm")
45static constexpr std::int_fast8_t QMSM_MAX_ENTRY_DEPTH_ {4};
62#define QS_STATE_ACT_(rec_, state_) \
64 QS_BEGIN_PRE((rec_), qsId) \
71#define QS_TOP_INIT_(rec_, trg_) \
73 QS_BEGIN_PRE((rec_), qsId) \
81#define QS_TRAN_SEG_(rec_, src_, trg_) \
83 QS_BEGIN_PRE((rec_), qsId) \
91#define QS_TRAN0_(rec_, trg_) \
93 QS_BEGIN_PRE((rec_), qsId) \
102#define QS_TRAN_END_(rec_, src_, trg_) \
104 QS_BEGIN_PRE((rec_), qsId) \
106 QS_SIG_PRE(e->sig); \
114#define QS_STATE_ACT_(rec_, state_) (static_cast<void>(0))
115#define QS_TOP_INIT_(rec_, trg_) (static_cast<void>(0))
116#define QS_TRAN_SEG_(rec_, src_, trg_) (static_cast<void>(0))
117#define QS_TRAN0_(rec_, trg_) (static_cast<void>(0))
118#define QS_TRAN_END_(rec_, src_, trg_) (static_cast<void>(0))
130 m_state.obj = &l_msm_top_s;
131 m_temp.fun = initial;
136 void const *
const e,
137 std::uint_fast8_t
const qsId)
147 && (
m_state.obj == &l_msm_top_s));
158 QS_TRAN_SEG_(QS_QEP_STATE_INIT,
159 m_state.obj->stateHandler,
m_temp.tatbl->target->stateHandler);
170 QS_TOP_INIT_(QS_QEP_INIT_TRAN,
m_state.obj->stateHandler);
175 QEvt const *
const e,
176 std::uint_fast8_t
const qsId)
182 QMState
const *s =
m_state.obj;
183 QMState
const *t = s;
192 QS_TRAN0_(QS_QEP_DISPATCH, s->stateHandler);
196 while (t !=
nullptr) {
197 r = (*t->stateHandler)(
this, e);
223 QMState
const *
const ts = t;
227 QMState
const *
const hist =
m_state.obj;
230 QS_TRAN_SEG_(QS_QEP_TRAN_HIST,
231 t->stateHandler, hist->stateHandler);
234 QMTranActTable
const *
const tatbl =
m_temp.tatbl;
244 QMTranActTable
const *
const tatbl =
m_temp.tatbl;
252 QS_TRAN_END_(QS_QEP_TRAN, ts->stateHandler, s->stateHandler);
261 QS_TRAN0_(QS_QEP_INTERN_TRAN, t->stateHandler);
263 else if (t ==
nullptr) {
264 QS_TRAN0_(QS_QEP_IGNORED, s->stateHandler);
274 bool inState =
false;
276 QMState
const *s =
m_state.obj;
277 while (s !=
nullptr) {
278 if (s->stateHandler == stateHndl) {
292 QMState
const *s =
m_state.obj;
293 QMState
const *child = s;
294 bool isFound =
false;
296 while (s !=
nullptr) {
297 if (s == parentHndl) {
318 QMTranActTable
const *
const tatbl,
319 std::uint_fast8_t
const qsId)
334 while (*a !=
nullptr) {
339 QS_STATE_ACT_(QS_QEP_STATE_ENTRY,
m_temp.obj->stateHandler);
342 QS_STATE_ACT_(QS_QEP_STATE_EXIT,
m_temp.obj->stateHandler);
345 QS_TRAN_SEG_(QS_QEP_STATE_INIT,
346 tatbl->target->stateHandler,
347 m_temp.tatbl->target->stateHandler);
366 QMState
const *
const cs,
367 QMState
const *
const ts,
368 std::uint_fast8_t
const qsId)
376 QMState
const *s = cs;
379 if (s->exitAction !=
nullptr) {
381 static_cast<void>((*s->exitAction)(
this));
383 QS_STATE_ACT_(QS_QEP_STATE_EXIT,
m_temp.obj->stateHandler);
391 QMState
const *
const hist,
392 std::uint_fast8_t
const qsId)
399 QMState
const *epath[QMSM_MAX_ENTRY_DEPTH_];
400 QMState
const *s = hist;
401 std::int_fast8_t i = 0;
402 while ((s !=
m_state.obj) && (i < QMSM_MAX_ENTRY_DEPTH_)) {
403 if (s->entryAction !=
nullptr) {
416 for (i = i - 1; i >= 0; --i) {
418 static_cast<void>((*epath[i]->entryAction)(
this));
420 QS_STATE_ACT_(QS_QEP_STATE_ENTRY, epath[i]->stateHandler);
427 if (hist->initAction !=
nullptr) {
428 r = (*hist->initAction)(
this);
430 QS_TRAN_SEG_(QS_QEP_STATE_INIT,
431 hist->stateHandler,
m_temp.tatbl->target->stateHandler);
Abstract State Machine class (state machine interface)
static constexpr QState Q_RET_UNHANDLED
static constexpr QState Q_RET_TRAN
static constexpr QState Q_RET_ENTRY
static constexpr QState Q_RET_NULL
QAsmAttr m_temp
Temporary storage for target/act-table etc.
static constexpr QState Q_RET_SUPER
static constexpr QState Q_RET_TRAN_INIT
static constexpr QState Q_RET_TRAN_HIST
static constexpr QState Q_RET_EXIT
QAsmAttr m_state
Current state (pointer to the current state-handler function)
static constexpr QState Q_RET_HANDLED
QMState const * childStateObj(QMState const *const parentHndl) const noexcept
QState execTatbl_(QMTranActTable const *const tatbl, std::uint_fast8_t const qsId)
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
void exitToTranSource_(QMState const *const cs, QMState const *const ts, std::uint_fast8_t const qsId)
QState enterHistory_(QMState const *const hist, std::uint_fast8_t const qsId)
void init(void const *const e, std::uint_fast8_t const qsId) override
Virtual function to take the top-most initial transition in the state machine.
bool isIn(QStateHandler const stateHndl) noexcept override
QMsm(QStateHandler const initial) noexcept
QMState const * topQMState() const noexcept
QState(*)(void *const me) QActionHandler
Pointer to an action-handler function.
std::uint_fast8_t QState
Type returned from state-handler functions.
QState(*)(void *const me, QEvt const *const e) QStateHandler
Pointer to a state-handler function.
#define Q_EVT_CAST(subclass_)
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
QS/C++ dummy public interface.
#define QS_BEGIN_PRE(rec_, qsId_)
QP Functional Safety (FuSa) Subsystem.
#define Q_ASSERT_INCRIT(id_, expr_)
General-purpose assertion with user-specified ID number (in critical section)
#define Q_REQUIRE_INCRIT(id_, expr_)
Assertion for checking a precondition (in critical section)
State object for the QP::QMsm class (QM State Machine)