QP/C  8.0.0
Real-Time Embedded Framework
Loading...
Searching...
No Matches
QMsm Class Reference

Hierarchical State Machine class (QMsm-style state machine implementation strategy) More...

#include "qp.h"

Inheritance diagram for QMsm:
QAsm

Public Member Functions

QMState const * QMsm_childStateObj (QMsm const *const me, QMState const *const parent)
 Obtain the current active child state of a given parent in QMsm.
 

Static Public Member Functions

static QStateHandler QMsm_getStateHandler_ (QAsm *const me)
 Implementation of getting the state handler in a QMsm subclass.
 
static QMState const * QMsm_stateObj (QMsm const *const me)
 Obtain the current state from a MSM (read only)
 

Public Attributes

QAsm super
 

Protected Member Functions

void QMsm_ctor (QMsm *const me, QStateHandler const initial)
 Constructor of QMsm.
 
- Protected Member Functions inherited from QAsm
void QAsm_ctor (QAsm *const me)
 Constructor of the QAsm base class.
 
QState QHsm_top (QHsm const *const me, QEvt const *const e)
 

Private Member Functions

void QMsm_init_ (QAsm *const me, void const *const e, uint_fast8_t const qsId)
 Implementation of the top-most initial transition in QMsm.
 
void QMsm_dispatch_ (QAsm *const me, QEvt const *const e, uint_fast8_t const qsId)
 Implementation of dispatching events to a QMsm.
 
bool QMsm_isIn_ (QAsm *const me, QStateHandler const state)
 Tests if a given state is part of the current active state configuration.
 
QState QMsm_execTatbl_ (QAsm *const me, QMTranActTable const *const tatbl, uint_fast8_t const qsId)
 Execute transition-action table.
 
void QMsm_exitToTranSource_ (QAsm *const me, QMState const *const cs, QMState const *const ts, uint_fast8_t const qsId)
 Exit the current state up to the explicit transition source.
 
QState QMsm_enterHistory_ (QAsm *const me, QMState const *const hist, uint_fast8_t const qsId)
 Enter history of a composite state.
 

Additional Inherited Members

- Protected Attributes inherited from QAsm
struct QAsmVtable const * vptr
 Virtual pointer inherited by all QAsm subclasses (see also Object Orientation)
 
union QAsmAttr state
 Current state (pointer to the current state-handler function)
 
union QAsmAttr temp
 Temporary storage for target/act-table etc.
 

Detailed Description

Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Details
QMsm (QM State Machine) provides a more efficient state machine implementation strategy than QHsm, but requires the use of the QM modeling tool, but are the fastest and need the least run-time support (the smallest event-processor taking up the least code space).
Note
QMsm is not intended to be instantiated directly, but rather serves as the abstract base class for derivation of state machines in the application code.
Backward Traceability
  • SRS_QP_SM_21 : QP/C Framework should provide a State Machine Implementation Strategy optimized for "automatic code generation"
  • SDS_QP_QEP : QEP Event Processor
  • SDS_QP_QMsm : QMsm State machine class.
Usage
The following example illustrates how to derive a state machine class from QMsm. Please note that the QMsm member super is defined as the first member of the derived struct. Also, note that the derived class constructor calls the constructor of the base class QMsm_ctor().
typedef struct {
QMsm super; // <=== inherit QMsm
// private state histories
QStateHandler hist_doorClosed;
QStateHandler hist_heating;
} ToasterOven;
void ToasterOven_ctor(ToastOven * const me) {
QMsm_ctor(&me->super, Q_STATE_CAST(&ToasterOven_initial));
. . .
}
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition qp.h:519
QState(* QStateHandler)(void *const me, QEvt const *const e)
Pointer to a state-handler function.
Definition qp.h:215
Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Definition qp.h:355
QAsm super
Definition qp.h:357
void QMsm_ctor(QMsm *const me, QStateHandler const initial)
Constructor of QMsm.
Definition qep_msm.c:86

Definition at line 355 of file qp.h.

Member Function Documentation

◆ QMsm_ctor()

void QMsm_ctor ( QMsm *const me,
QStateHandler const initial )
protected

Constructor of QMsm.

Details
Performs the first step of QMsm initialization by assigning the initial pseudostate to the currently active state of the state machine.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]initialthe top-most initial transition for the MSM.
Note
Must be called only ONCE before QASM_INIT().
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)
Usage
The following example illustrates how to invoke QMsm_ctor() in the "constructor" of a derived state machine:
void Calc_ctor(Calc const me) {
// call superclass' ctor
QMsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial));
me->operand1 = 0.0;
me->operand2 = 0.0;
me->len = 0U;
me->opKey = 0U;
}

Definition at line 86 of file qep_msm.c.

◆ QMsm_init_()

void QMsm_init_ ( QAsm *const me,
void const *const e,
uint_fast8_t const qsId )
private

Implementation of the top-most initial transition in QMsm.

Details
Synchronously executes the top-most initial transition in a state machine.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]epointer to an extra parameter (might be NULL)
[in]qsIdQS-id of this state machine (for QS local filter)
Precondition qep_msm:200
  • the virtual pointer must be initialized,
  • the top-most initial transition must be initialized,
  • the initial transition must not be taken yet.
Note
This function should be called only via the virtual table (see QASM_INIT()) and should NOT be called directly in the applications.
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 105 of file qep_msm.c.

◆ QMsm_dispatch_()

void QMsm_dispatch_ ( QAsm *const me,
QEvt const *const e,
uint_fast8_t const qsId )
private

Implementation of dispatching events to a QMsm.

Details
Synchronously dispatches an event for processing to a state machine. The processing of an event represents one run-to-completion (RTC) step.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]epointer to the event to be dispatched to the MSM
[in]qsIdQS-id of this state machine (for QS local filter)
Precondition qep_msm:302
  • current state must be initialized
  • check the internal integrity (Software Self-Monitoring (SSM))
Note
This function should be called only via the virtual table (see QASM_DISPATCH()) and should NOT be called directly in the applications.
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 169 of file qep_msm.c.

◆ QMsm_getStateHandler_()

static QStateHandler QMsm_getStateHandler_ ( QAsm *const me)
inlinestatic

Implementation of getting the state handler in a QMsm subclass.

Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
Note
This function is only called internally via the virtual table
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 386 of file qp.h.

◆ QMsm_isIn_()

bool QMsm_isIn_ ( QAsm *const me,
QStateHandler const state )
private

Tests if a given state is part of the current active state configuration.

Details
Please note that for a MSM, to "be in a state" means also to be in a superstate of of the state.
Parameters
[in]mecurrent instance pointer (see Object Orientation)
[in]statepointer to the state-handler function to be tested
Returns
'true' if the MSM "is in" the state and 'false' otherwise
Note
This function should be called only via the virtual table (see QASM_IS_IN()) and should NOT be called directly in the applications.
Attention
This function must be called only on a state machine that is in the "stable state configuration". Among others, this means that the state machine cannot call it in the middle of its own transition. Also, this function does NOT work when the state machine is directly or indirectly in a submachine state.
Backward Traceability
  • SRS_QP_SM_25 : All State Machine Implementation Strategies provided by QP/C Framework might supply a method for checking if a state machine is in a given state
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 344 of file qep_msm.c.

◆ QMsm_stateObj()

static QMState const * QMsm_stateObj ( QMsm const *const me)
inlinestatic

Obtain the current state from a MSM (read only)

Parameters
[in]mecurrent instance pointer (see Object Orientation)
Returns
the current state object
Note
This function is used in QM for auto-generating code for state history (deep history)
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 397 of file qp.h.

◆ QMsm_childStateObj()

QMState const * QMsm_childStateObj ( QMsm const *const me,
QMState const *const parent )

Obtain the current active child state of a given parent in QMsm.

Details
Finds the child state of the given parent, such that this child state is an ancestor of the currently active state. The main purpose of this function is to support **shallow history*transitions in state machines derived from QMsm.
Parameters
[in]mecurrent instance pointer (see Object Orientation)
[in]parentpointer to the state-handler object
Returns
the child of a given parent state, which is an ancestor of the currently active state. For the corner case when the currently active state is the given parent state, function returns the parent state.
Postcondition qep_msm:890
  • the child must be found
Note
This function is used in QM for auto-generating code for state history (shallow history)
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 372 of file qep_msm.c.

◆ QMsm_execTatbl_()

QState QMsm_execTatbl_ ( QAsm *const me,
QMTranActTable const *const tatbl,
uint_fast8_t const qsId )
private

Execute transition-action table.

Details
Helper function to execute transition sequence in a transition-action table.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]tatblpointer to the transition-action table
[in]qsIdQS-id of this state machine (for QS local filter)
Returns
status of the last action from the transition-action table.
Precondition qep_msm:400
  • provided state table cannot be NULL
Note
This function is for internal use inside the QEP event processor and should **not* be called directly from the applications.
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 426 of file qep_msm.c.

◆ QMsm_exitToTranSource_()

void QMsm_exitToTranSource_ ( QAsm *const me,
QMState const *const cs,
QMState const *const ts,
uint_fast8_t const qsId )
private

Exit the current state up to the explicit transition source.

Details
Static helper function to exit the current state configuration to the transition source, which in a hierarchical state machine might be a superstate of the current state.
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]cspointer to the current state
[in]tspointer to the transition source state
[in]qsIdQS-id of this state machine (for QS local filter)
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 491 of file qep_msm.c.

◆ QMsm_enterHistory_()

QState QMsm_enterHistory_ ( QAsm *const me,
QMState const *const hist,
uint_fast8_t const qsId )
private

Enter history of a composite state.

Details
Static helper function to execute the segment of transition to history after entering the composite state and
Parameters
[in,out]mecurrent instance pointer (see Object Orientation)
[in]histpointer to the history substate
[in]qsIdQS-id of this state machine (for QS local filter)
Returns
Q_RET_TRAN_INIT, if an initial transition has been executed in the last entered state or Q_RET_NULL if no such transition was taken.
Backward Traceability
  • QMsm : Hierarchical State Machine class (QMsm-style state machine implementation strategy)

Definition at line 531 of file qep_msm.c.

Member Data Documentation

◆ super

QAsm QMsm::super

Definition at line 357 of file qp.h.


The documentation for this class was generated from the following files: