37 #include "qs_dummy.hpp"
43Q_DEFINE_THIS_MODULE(
"qep_msm")
46static constexpr std::int_fast8_t QMSM_MAX_NEST_DEPTH_ {6};
63#define QS_STATE_ACT_(rec_, state_) \
65 QS_BEGIN_PRE((rec_), qsId) \
72#define QS_TOP_INIT_(rec_, trg_) \
74 QS_BEGIN_PRE((rec_), qsId) \
82#define QS_TRAN_SEG_(rec_, src_, trg_) \
84 QS_BEGIN_PRE((rec_), qsId) \
92#define QS_TRAN0_(rec_, trg_) \
94 QS_BEGIN_PRE((rec_), qsId) \
103#define QS_TRAN_END_(rec_, src_, trg_) \
105 QS_BEGIN_PRE((rec_), qsId) \
107 QS_SIG_PRE(e->sig); \
115#define QS_STATE_ACT_(rec_, state_) (static_cast<void>(0))
116#define QS_TOP_INIT_(rec_, trg_) (static_cast<void>(0))
117#define QS_TRAN_SEG_(rec_, src_, trg_) (static_cast<void>(0))
118#define QS_TRAN0_(rec_, trg_) (static_cast<void>(0))
119#define QS_TRAN_END_(rec_, src_, trg_) (static_cast<void>(0))
131 m_state.obj = &l_msm_top_s;
132 m_temp.fun = initial;
137 void const *
const e,
138 std::uint_fast8_t
const qsId)
161 m_state.obj->stateHandler,
m_temp.tatbl->target->stateHandler);
181 QEvt const *
const e,
182 std::uint_fast8_t
const qsId)
196 QMState
const *s =
m_state.obj;
197 QMState
const *
const t = s;
204 r = (*s->stateHandler)(
this, e);
220 }
while (s !=
nullptr);
232 QMState
const *
const ts = s;
236 struct QMTranActTable const *
const tatbl =
m_temp.tatbl;
241 QMState
const *
const hist =
m_state.obj;
245 s->stateHandler, hist->stateHandler);
248 struct QMTranActTable const *
const tatbl =
m_temp.tatbl;
265 QS_TRAN_END_(
QS_QEP_TRAN, ts->stateHandler, s->stateHandler);
279 QMTranActTable
const *
const tatbl,
280 std::uint_fast8_t
const qsId)
292 while (*a !=
nullptr) {
304 tatbl->target->stateHandler,
305 m_temp.tatbl->target->stateHandler);
319 QMState
const *
const curr_state,
320 QMState
const *
const tran_source,
321 std::uint_fast8_t
const qsId)
332 QMState
const *s = curr_state;
333 while (s != tran_source) {
334 if (s->exitAction !=
nullptr) {
336 static_cast<void>((*s->exitAction)(
this));
345 QMState
const *
const hist,
346 std::uint_fast8_t
const qsId)
353 std::array<QMState const *, QMSM_MAX_NEST_DEPTH_> path;
354 QMState
const *s = hist;
355 std::int_fast8_t i = -1;
357 if (s->entryAction !=
nullptr) {
368 for (; i >= 0; --i) {
370 static_cast<void>((*path[i]->entryAction)(
this));
378 if (hist->initAction !=
nullptr) {
379 r = (*hist->initAction)(
this);
381 hist->stateHandler,
m_temp.tatbl->target->stateHandler);
393 bool inState =
false;
394 QMState
const *s =
m_state.obj;
395 while (s !=
nullptr) {
396 if (s->stateHandler == stateHndl) {
410 QMState
const *s =
m_state.obj;
411 QMState
const *child = s;
412 bool isFound =
false;
413 while (s !=
nullptr) {
414 if (s == parentHndl) {
433 return m_state.obj->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
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
Obtain the current active child state of a given parent in QP::QMsm.
void exitToTranSource_(QMState const *const curr_state, QMState const *const tran_source, std::uint_fast8_t const qsId)
Exit the current state up to the explicit transition source.
QState execTatbl_(QMTranActTable const *const tatbl, std::uint_fast8_t const qsId)
Execute transition-action table.
static QMState const * topQMState() noexcept
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
QState enterHistory_(QMState const *const hist, std::uint_fast8_t const qsId)
Enter history of a composite state.
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
Tests if a given state is part of the current active state configuration.
QMsm(QStateHandler const initial) noexcept
Constructor of QP::QMsm.
QStateHandler getStateHandler() const noexcept override
Obtain the current active state from a MSM (read only).
QP/C++ Framework namespace.
@ QS_QEP_DISPATCH
an event was dispatched (begin of RTC step)
@ QS_QEP_STATE_ENTRY
a state was entered
@ QS_QEP_STATE_EXIT
a state was exited
@ QS_QEP_TRAN_HIST
a tran. to history was taken
@ QS_QEP_IGNORED
an event was ignored (silently discarded)
@ QS_QEP_UNHANDLED
an event was un-handled due to a guard
@ QS_QEP_STATE_INIT
an initial transition was taken in a state
@ QS_QEP_TRAN
a regular transition was taken
@ QS_QEP_INIT_TRAN
the top-most initial transition was taken
@ QS_QEP_INTERN_TRAN
an internal transition was taken
QState(*)(void *const me) QActionHandler
Pointer to an action-handler function.
static T_ dis_update(T_ const org)
Internal function template to calculate the Duplicate Inverse Storage (DIS).
static bool dis_verify(T_ const org, T_ const dis)
Internal function template to verify the Duplicate Inverse Storage (DIS).
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_)
Perform downcast of an event onto a subclass of QP::QEvt class_.
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
QP Framework in C++ internal (package-scope) interface
#define QS_CRIT_STAT
Internal QS macro for defining the critical section status.
#define QS_CRIT_EXIT()
Internal macro for exiting a critical section.
#define QS_CRIT_ENTRY()
Internal macro for entering a critical section.
QS (QP/Spy software tracing) internal (package-scope) interface.
#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.
#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).
State object for the QP::QMsm class (QM State Machine).