51Q_DEFINE_THIS_MODULE(
"qep_hsm")
54static
QP::QEvt const l_reservedEvt_[4] {
63static constexpr std::int_fast8_t QHSM_MAX_NEST_DEPTH_ {6};
68#define QHSM_RESERVED_EVT_(state_, sig_) \
69 ((*(state_))(this, &l_reservedEvt_[(sig_)]))
72#define QS_STATE_ENTRY_(state_, qsId_) \
75 QS_BEGIN_PRE(QS_QEP_STATE_ENTRY, (qsId_)) \
83#define QS_STATE_EXIT_(state_, qsId_) \
86 QS_BEGIN_PRE(QS_QEP_STATE_EXIT, (qsId_)) \
99#if (QP_VERSION < 730U) || (QP_VERSION != ((QP_RELEASE^4294967295U)%0x2710U))
100#error qpcpp version 7.3.0 or higher required
119 m_temp.fun = initial;
124 void const *
const e,
125 std::uint_fast8_t
const qsId)
135 if ((QS::priv_.flags & 0x01U) == 0U) {
136 QS::priv_.flags |= 0x01U;
178 std::int_fast8_t ip = 0;
183 while ((
m_temp.
fun != t) && (ip < (QHSM_MAX_NEST_DEPTH_ - 1))) {
202 QS_STATE_ENTRY_(path[ip], qsId);
246 QEvt const *
const e,
247 std::uint_fast8_t
const qsId)
277 std::int_fast8_t ip = QHSM_MAX_NEST_DEPTH_;
325 ip = QHSM_MAX_NEST_DEPTH_;
326 for (; (t != s) && (ip > 0); t =
m_temp.
fun) {
329 QS_STATE_EXIT_(t, qsId);
331 static_cast<void>(QHSM_RESERVED_EVT_(t,
Q_EMPTY_SIG));
343 for (; ip >= 0; --ip) {
348 QS_STATE_ENTRY_(path[ip], qsId);
374 while ((
m_temp.
fun != t) && (ip < (QHSM_MAX_NEST_DEPTH_ - 1))) {
395 QS_STATE_ENTRY_(path[ip], qsId);
454 m_state.uint ==
static_cast<std::uintptr_t
>(~m_temp.uint));
457 bool inState =
false;
461 std::int_fast8_t lbound = QHSM_MAX_NEST_DEPTH_ + 1;
463 for (; (r != Q_RET_IGNORED) && (lbound > 0); --lbound) {
469 r = QHSM_RESERVED_EVT_(s, Q_EMPTY_SIG);
479 m_temp.uint = ~m_state.uint;
488 bool isFound =
false;
493 std::int_fast8_t lbound = QHSM_MAX_NEST_DEPTH_;
496 if (m_temp.fun == parent) {
502 r = QHSM_RESERVED_EVT_(m_temp.fun, Q_EMPTY_SIG);
505 }
while ((r != Q_RET_IGNORED)
509 m_temp.uint = ~m_state.uint;
527 std::uint_fast8_t
const qsId)
533 std::int_fast8_t ip = -1;
542 QS_STATE_EXIT_(s, qsId);
548 static_cast<void>(QHSM_RESERVED_EVT_(t,
Q_EMPTY_SIG));
558 static_cast<void>(QHSM_RESERVED_EVT_(s,
Q_EMPTY_SIG));
564 QS_STATE_EXIT_(s, qsId);
573 QS_STATE_EXIT_(s, qsId);
579 std::int_fast8_t iq = 0;
588 && (ip < (QHSM_MAX_NEST_DEPTH_ - 1)))
614 QS_STATE_EXIT_(s, qsId);
638 std::int_fast8_t lbound = QHSM_MAX_NEST_DEPTH_;
644 QS_STATE_EXIT_(t, qsId);
Abstract State Machine class (state machine interface)
@ Q_RET_HANDLED
event handled (internal transition)
@ Q_RET_IGNORED
event silently ignored (bubbled up to top)
@ Q_RET_UNHANDLED
event unhandled due to a guard
@ Q_RET_TRAN
regular transition
@ Q_RET_TRAN_HIST
transition to history of a given state
@ Q_RET_SUPER
event passed to superstate to handle
QAsmAttr m_temp
Temporary storage for target/act-table etc.
static QState top(void *const me, QEvt const *const e) noexcept
Top state handler that ignores all events.
QAsmAttr m_state
Current state (pointer to the current state-handler function)
@ Q_EXIT_SIG
signal for exit actions
@ Q_INIT_SIG
signal for nested initial transitions
@ Q_ENTRY_SIG
signal for entry actions
@ Q_EMPTY_SIG
signal to execute the default case
QSignal sig
Signal of the event (see Event Signal)
bool verify_() const noexcept
Internal function to verify the internal integrity of the event instance (QP FuSa Subsystem)
std::int_fast8_t hsm_tran(QStateHandler *const path, std::uint_fast8_t const qsId)
QStateHandler childState(QStateHandler const parent) noexcept
void dispatch(QEvt const *const e, std::uint_fast8_t const qsId) override
Virtual function to dispatch an event to the state machine.
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.
QHsm(QStateHandler const initial) noexcept
bool isIn(QStateHandler const state) noexcept override
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.
std::uint16_t QSignal
The signal of event QP::QEvt.
#define Q_EVT_CAST(subclass_)
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
#define Q_STATE_CAST(handler_)
Internal (package scope) QP/C++ interface.
#define QS_FUN_DICTIONARY(fun_)
#define QS_BEGIN_PRE(rec_, qsId_)
QS/C++ port to a 32-bit CPU, generic C++ compiler.
QP Functional Safety (FuSa) Subsystem.
#define Q_ASSERT_INCRIT(id_, expr_)
#define Q_INVARIANT_INCRIT(id_, expr_)
#define Q_ENSURE_INCRIT(id_, expr_)
#define Q_REQUIRE_INCRIT(id_, expr_)