42Q_DEFINE_THIS_MODULE(
"qep_hsm")
46static constexpr std::int_fast8_t QHSM_MAX_NEST_DEPTH_ {6};
51static QP::QEvt const l_reservedEvt_[4] {
66#define QHSM_RESERVED_EVT_(state_, sig_) \
67 ((*(state_))(this, &l_reservedEvt_[(sig_)]))
71#define QS_STATE_ACT_(rec_, state_) \
73 QS_BEGIN_PRE((rec_), qsId) \
80#define QS_TOP_INIT_(rec_, trg_) \
82 QS_BEGIN_PRE((rec_), qsId) \
90#define QS_TRAN_SEG_(rec_, src_, trg_) \
92 QS_BEGIN_PRE((rec_), qsId) \
100#define QS_TRAN_ACT_(rec_, state_) \
102 QS_BEGIN_PRE((rec_), qsId) \
103 QS_SIG_PRE(e->sig); \
105 QS_FUN_PRE(state_); \
110#define QS_TRAN0_(rec_, trg_) \
112 QS_BEGIN_PRE((rec_), qsId) \
114 QS_SIG_PRE(e->sig); \
121#define QS_TRAN_END_(rec_, src_, trg_) \
123 QS_BEGIN_PRE((rec_), qsId) \
125 QS_SIG_PRE(e->sig); \
133#define QS_STATE_ACT_(rec_, state_) (static_cast<void>(0))
134#define QS_TOP_INIT_(rec_, trg_) (static_cast<void>(0))
135#define QS_TRAN_SEG_(rec_, src_, trg_) (static_cast<void>(0))
136#define QS_TRAN_ACT_(rec_, state_) (static_cast<void>(0))
137#define QS_TRAN0_(rec_, trg_) (static_cast<void>(0))
138#define QS_TRAN_END_(rec_, src_, trg_) (static_cast<void>(0))
155 void const *
const e,
156 std::uint_fast8_t
const qsId)
164 if ((QS::priv_.flags & 0x01U) == 0U) {
165 QS::priv_.flags |= 0x01U;
192 QS_TRAN_SEG_(QS_QEP_STATE_INIT, t,
m_temp.fun);
199 std::int_fast8_t ip = 1;
200 for (; (
m_temp.fun != t) && (ip < QHSM_MAX_NEST_DEPTH_); ++ip) {
213 QS_TOP_INIT_(QS_QEP_INIT_TRAN, t);
223 QEvt const *
const e,
224 std::uint_fast8_t
const qsId)
240 QS_TRAN0_(QS_QEP_DISPATCH, s);
246 std::int_fast8_t ip = QHSM_MAX_NEST_DEPTH_;
248 for (; ip > 0; --ip) {
253 QS_TRAN_ACT_(QS_QEP_UNHANDLED, s);
267 QS_TRAN_SEG_(QS_QEP_TRAN_HIST, s,
m_temp.fun);
280 QS_STATE_ACT_(QS_QEP_STATE_EXIT, t);
282 static_cast<void>(QHSM_RESERVED_EVT_(t,
Q_EMPTY_SIG));
295 QS_TRAN_END_(QS_QEP_TRAN, s, t);
299 QS_TRAN0_(QS_QEP_INTERN_TRAN, s);
302 QS_TRAN0_(QS_QEP_IGNORED,
m_state.fun);
311 bool inState =
false;
317 if (s == stateHndl) {
330 bool isFound =
false;
338 if (
m_temp.fun == parentHndl) {
359 std::uint_fast8_t
const qsId)
367 std::int_fast8_t ip = 0;
374 QS_STATE_ACT_(QS_QEP_STATE_EXIT, s);
380 static_cast<void>(QHSM_RESERVED_EVT_(t,
Q_EMPTY_SIG));
390 static_cast<void>(QHSM_RESERVED_EVT_(s,
Q_EMPTY_SIG));
396 QS_STATE_ACT_(QS_QEP_STATE_EXIT, s);
401 else if (
m_temp.fun == path[0]) {
404 QS_STATE_ACT_(QS_QEP_STATE_EXIT, s);
421 std::uint_fast8_t
const qsId)
429 std::int_fast8_t iq = 0;
430 std::int_fast8_t ip = 1;
438 while ((r ==
Q_RET_SUPER) && (ip < (QHSM_MAX_NEST_DEPTH_ - 1))) {
457 static_cast<void>(QHSM_RESERVED_EVT_(s,
Q_EXIT_SIG));
460 QS_STATE_ACT_(QS_QEP_STATE_EXIT, s);
485 QS_STATE_ACT_(QS_QEP_STATE_EXIT, t);
487 static_cast<void>(QHSM_RESERVED_EVT_(t,
Q_EMPTY_SIG));
509 std::int_fast8_t
const depth,
510 std::uint_fast8_t
const qsId)
522 std::int_fast8_t ip = depth;
525 for (; ip >= 0; --ip) {
530 QS_STATE_ACT_(QS_QEP_STATE_ENTRY, path[ip]);
539 QS_TRAN_SEG_(QS_QEP_STATE_INIT, t,
m_temp.fun);
548 while ((
m_temp.fun != t) && (ip < (QHSM_MAX_NEST_DEPTH_ - 1))) {
552 static_cast<void>(QHSM_RESERVED_EVT_(
567 QS_STATE_ACT_(QS_QEP_STATE_ENTRY, path[ip]);
QAsm() noexcept
Constructor of the QP::QAsm base class.
static constexpr QState Q_RET_UNHANDLED
static constexpr QState Q_RET_TRAN
QAsmAttr m_temp
Temporary storage for target/act-table etc.
static constexpr QState Q_RET_IGNORED
static constexpr QState Q_RET_SUPER
static QState top(void *const me, QEvt const *const e) noexcept
Top state handler that ignores all events.
static constexpr QState Q_RET_TRAN_HIST
static constexpr QSignal Q_INIT_SIG
QAsmAttr m_state
Current state (pointer to the current state-handler function)
static constexpr QSignal Q_ENTRY_SIG
static constexpr QSignal Q_EXIT_SIG
static constexpr QSignal Q_EMPTY_SIG
static constexpr QState Q_RET_HANDLED
std::int_fast8_t tran_complex_(QStateHandler *const path, 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.
std::int_fast8_t tran_simple_(QStateHandler *const path, std::uint_fast8_t const qsId)
QStateHandler childState(QStateHandler const parentHndl) noexcept
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
void enter_target_(QStateHandler *const path, std::int_fast8_t const depth, std::uint_fast8_t const qsId)
bool isIn(QStateHandler const stateHndl) 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_)
QS/C++ dummy public interface.
#define QS_FUN_DICTIONARY(fun_)
QP Functional Safety (FuSa) Subsystem.
#define Q_ASSERT_INCRIT(id_, expr_)
General-purpose assertion with user-specified ID number (in critical section)
#define Q_INVARIANT_INCRIT(id_, expr_)
#define Q_REQUIRE_INCRIT(id_, expr_)
Assertion for checking a precondition (in critical section)