50 #include "qs_dummy.hpp"
57#if (QP_VERSION < 700U) || (QP_VERSION != ((QP_RELEASE^4294967295U) % 0x3E8U))
58#error qpcpp version 7.0.0 or higher required
71Q_DEFINE_THIS_MODULE(
"qep_hsm")
81static
QP::QEvt const l_reservedEvt_[4] {
108 return (*state)(me, &l_reservedEvt_[sig]);
117static inline void hsm_state_entry_(
120 std::uint_fast8_t
const qs_id)
148static inline bool hsm_state_exit_(
151 std::uint_fast8_t
const qs_id)
185 m_temp.fun = initial;
190 void const *
const e,
191 std::uint_fast8_t
const qs_id)
224 std::int_fast8_t ip = 0;
238 hsm_state_entry_(
this, path[ip], qs_id);
270 QEvt const *
const e,
271 std::uint_fast8_t
const qs_id)
325 if (hsm_state_exit_(
this, t, qs_id)) {
327 static_cast<void>(hsm_reservedEvt_(
this, t,
Q_EMPTY_SIG));
331 std::int_fast8_t ip =
hsm_tran(path, qs_id);
347 for (; ip >= 0; --ip) {
348 hsm_state_entry_(
this, path[ip], qs_id);
383 hsm_state_entry_(
this, path[ip], qs_id);
431 QEvt const *
const e)
noexcept
435 return Q_RET_IGNORED;
443 bool inState =
false;
449 if (m_temp.fun == s) {
454 r = hsm_reservedEvt_(
this, m_temp.fun, Q_EMPTY_SIG);
456 }
while (r != Q_RET_IGNORED);
457 m_temp.fun = m_state.fun;
465 bool isFound =
false;
468 m_temp.fun = m_state.fun;
472 if (m_temp.fun == parent) {
478 r = hsm_reservedEvt_(
this, m_temp.fun, Q_EMPTY_SIG);
480 }
while (r != Q_RET_IGNORED);
481 m_temp.fun = m_state.fun;
496 std::uint_fast8_t
const qs_id)
502 std::int_fast8_t ip = -1;
509 static_cast<void>(hsm_state_exit_(
this, s, qs_id));
514 static_cast<void>(hsm_reservedEvt_(
this, t,
Q_EMPTY_SIG));
523 static_cast<void>(hsm_reservedEvt_(
this, s,
Q_EMPTY_SIG));
528 static_cast<void>(hsm_state_exit_(
this, s, qs_id));
535 static_cast<void>(hsm_state_exit_(
this, s, qs_id));
540 std::int_fast8_t iq = 0;
571 static_cast<void>(hsm_state_exit_(
this, s, qs_id));
598 if (hsm_state_exit_(
this, t, qs_id)) {
QSignal sig
signal of the event instance RQP002
Hierarchical State Machine abstract base class (ABC)
static constexpr std::int_fast8_t MAX_NEST_DEPTH_
Maximum nesting depth of states in HSM.
bool isIn(QStateHandler const s) noexcept
Tests if a given state is part of the current active state configuration.
QStateHandler childState(QStateHandler const parent) noexcept
Obtain the current active child state of a given parent.
ReservedSig
Reserved signals by the HSM-style state machine implementation strategy.
@ Q_EXIT_SIG
signal for exit actions
@ Q_ENTRY_SIG
signal for entry actions
@ Q_INIT_SIG
signal for nested initial transitions
@ Q_EMPTY_SIG
signal to execute the default case
std::int_fast8_t hsm_tran(QStateHandler(&path)[MAX_NEST_DEPTH_], std::uint_fast8_t const qs_id)
QHsmAttr m_temp
temporary: transition chain, target state, etc.
static QState top(void *const me, QEvt const *const e) noexcept
The top-state handler.
QHsm(QStateHandler const initial) noexcept
protected constructor of QHsm
QHsmAttr m_state
current active state (the state-variable)
virtual void dispatch(QEvt const *const e, std::uint_fast8_t const qs_id)
Dispatches an event to QP::QHsm.
@ Q_RET_IGNORED
event silently ignored (bubbled up to top)
@ 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
@ Q_RET_HANDLED
event handled (internal transition)
@ Q_RET_UNHANDLED
event unhandled due to a guard
virtual void init(void const *const e, std::uint_fast8_t const qs_id)
Executes the top-most initial transition in QP::QHsm.
QStx priv_
the only instance of the QS-TX object (Singleton)
std::uint8_t flags
flags for internal use
QState(*)(void *const me, QEvt const *const e) QStateHandler
Pointer to state-handler function.
QStateHandler fun
pointer to a state handler function
std::uint16_t QSignal
QSignal represents the signal of an event.
std::uint_fast8_t QState
Type returned from state-handler functions.
@ 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 unhandled 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
Customizable and memory-efficient Design by Contract (DbC) for embedded systems.
#define Q_ENSURE_ID(id_, expr_)
#define Q_REQUIRE_ID(id_, expr_)
#define Q_ASSERT_ID(id_, expr_)
#define Q_EVT_CAST(subclass_)
Perform downcast of an event onto a subclass of QEvt class_
#define Q_UNUSED_PAR(par_)
Helper macro to clearly mark unused parameters of functions.
#define Q_STATE_CAST(handler_)
Macro to perform casting to QStateHandler.
QEP/C++ sample port with all configurable options.
#define QS_CRIT_STAT_
This is an internal macro for defining the critical section status type.
#define QS_TIME_PRE_()
Output time stamp to a QS record (used in predefined and application-specific trace records)
#define QS_FUN_DICTIONARY(fun_)
Output function dictionary record.
Internal (package scope) QS/C++ interface.
#define QS_BEGIN_PRE_(rec_, qs_id_)
Internal QS macro to begin a predefined QS record with critical section.
#define QS_OBJ_PRE_(obj_)
Internal QS macro to output object pointer data element.
#define QS_FUN_PRE_(fun_)
Internal QS macro to output an unformatted function pointer data element.
#define QS_END_PRE_()
Internal QS macro to end a predefined QS record with critical section.
QS/C++ sample port with all configurable options.