34#include "qep_port.hpp"
36 #include "qs_port.hpp"
39 #include "qs_dummy.hpp"
46#define QEP_TRIG_(state_, sig_) \
47 ((*(state_))(this, &QEP_reservedEvt_[sig_]))
50#define QEP_EXIT_(state_) do { \
51 if (QEP_TRIG_(state_, Q_EXIT_SIG) == Q_RET_HANDLED) { \
52 QS_BEGIN_PRE_(QS_QEP_STATE_EXIT, qs_id) \
54 QS_FUN_PRE_(state_); \
60#define QEP_ENTER_(state_) do { \
61 if (QEP_TRIG_(state_, Q_ENTRY_SIG) == Q_RET_HANDLED) { \
62 QS_BEGIN_PRE_(QS_QEP_STATE_ENTRY, qs_id) \
64 QS_FUN_PRE_(state_); \
86static QP::QEvt const QEP_reservedEvt_[4] {
118 m_temp.fun = initial;
140void QHsm::init(
void const *
const e, std::uint_fast8_t
const qs_id) {
141 static_cast<void>(qs_id);
165 std::int_fast8_t ip = 0;
229 static_cast<void>(me);
230 static_cast<void>(e);
231 return Q_RET_IGNORED;
305 static_cast<void>(
QEP_TRIG_(t, QEP_EMPTY_SIG_));
309 std::int_fast8_t ip =
hsm_tran(path, qs_id);
325 for (; ip >= 0; --ip) {
401 static_cast<void>(qs_id);
420 std::uint_fast8_t
const qs_id)
422 std::int_fast8_t ip = -1;
434 static_cast<void>(
QEP_TRIG_(t, QEP_EMPTY_SIG_));
443 static_cast<void>(
QEP_TRIG_(s, QEP_EMPTY_SIG_));
458 std::int_fast8_t iq = 0;
545 static_cast<void>(qs_id);
577 bool inState =
false;
583 if (m_temp.fun == s) {
588 r =
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
590 }
while (r != Q_RET_IGNORED);
591 m_temp.fun = m_state.fun;
620 bool isFound =
false;
623 m_temp.fun = m_state.fun;
627 if (m_temp.fun == parent) {
633 r =
QEP_TRIG_(m_temp.fun, QEP_EMPTY_SIG_);
635 }
while (r != Q_RET_IGNORED);
636 m_temp.fun = m_state.fun;
642 static_cast<void>(isFound);
static constexpr QState Q_RET_HANDLED
event handled (internal transition)
static constexpr QState Q_RET_SUPER
event passed to the superstate to handle
static constexpr QState Q_RET_UNHANDLED
event unhandled due to a guard evaluating to 'false'
virtual void dispatch(QEvt const *const e, std::uint_fast8_t const qs_id)
Dispatches an event to QHsm.
static constexpr QState Q_RET_IGNORED
event silently ignored (bubbled up to top)
@ Q_INIT_SIG
signal for nested initial transitions
@ Q_EXIT_SIG
signal for exit actions
static QState top(void *const me, QEvt const *const e) noexcept
the top-state.
virtual QStateHandler getStateHandler() noexcept
Get the current state handler of the HSM.
virtual ~QHsm()
virtual destructor
virtual void init(void const *const e, std::uint_fast8_t const qs_id)
executes the top-most initial transition in QP::QHsm
static constexpr QState Q_RET_TRAN
regular transition taken
QStateHandler childState(QStateHandler const parent) noexcept
Obtain the current active child state of a given parent.
QHsmAttr m_state
current active state (state-variable)
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.
static constexpr QState Q_RET_TRAN_HIST
transition to history of a given state
QHsmAttr m_temp
temporary: transition chain, target state, etc.
std::int_fast8_t hsm_tran(QStateHandler(&path)[MAX_NEST_DEPTH_], std::uint_fast8_t const qs_id)
internal helper function to take a transition in QP::QHsm
QHsm(QStateHandler const initial) noexcept
Protected constructor of QHsm.
namespace associated with the QP/C++ framework
std::uint_fast8_t QState
Type returned from state-handler functions.
@ QS_QEP_STATE_INIT
an initial transition was taken in a state
@ QS_QEP_TRAN_HIST
a tran to history was taken
@ QS_QEP_STATE_EXIT
a state was exited
@ QS_QEP_INIT_TRAN
the top-most initial transition was taken
@ QS_QEP_INTERN_TRAN
an internal transition was taken
@ QS_QEP_UNHANDLED
an event was unhandled due to a guard
@ QS_QEP_TRAN
a regular transition was taken
@ QS_QEP_DISPATCH
an event was dispatched (begin of RTC step)
@ QS_QEP_IGNORED
an event was ignored (silently discarded)
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.
Customizable and memory-efficient assertions for embedded systems.
#define Q_DEFINE_THIS_MODULE(name_)
#define Q_ASSERT_ID(id_, test_)
#define Q_ENSURE_ID(id_, test_)
#define Q_REQUIRE_ID(id_, test_)
#define Q_STATE_CAST(handler_)
Macro to perform casting to QStateHandler.
#define Q_EVT_CAST(class_)
Perform downcast of an event onto a subclass of QEvt class_.
#define QEP_ENTER_(state_)
helper macro to trigger entry action in an HSM
#define QEP_EXIT_(state_)
helper macro to trigger exit action in an HSM
#define QEP_TRIG_(state_, sig_)
helper macro to trigger internal event in an HSM
#define QS_CRIT_STAT_
This is an internal macro for defining the critical section status type.
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.
QSignal sig
signal of the event instance