QP/C  6.0.0
qep_msm.c File Reference

QMsm implementation More...

#include "qep_port.h"
#include "qassert.h"
#include "qs_port.h"

Go to the source code of this file.

Macros

#define QEP_ACT_PTR_INC_(act_)   (++(act_))
 Internal QEP macro to increment the given action table act_. More...
 

Enumerations

enum  { QMSM_MAX_ENTRY_DEPTH_ = 4 }
 internal QEP constants More...
 

Functions

static QState QMsm_execTatbl_ (QMsm *const me, QMTranActTable const *tatbl)
 helper function to execute a transition-action table. More...
 
static void QMsm_exitToTranSource_ (QMsm *const me, QMState const *s, QMState const *ts)
 helper function to exit the current state up to the transition source More...
 
static QState QMsm_enterHistory_ (QMsm *const me, QMState const *const hist)
 helper function to execute a transition to history More...
 
void QMsm_ctor (QMsm *const me, QStateHandler initial)
 Protected "constructor" of QMsm. More...
 
void QMsm_init_ (QMsm *const me, QEvt const *const e)
 Implementation of the top-most initial transition in QMsm. More...
 
void QMsm_dispatch_ (QMsm *const me, QEvt const *const e)
 Implementation of disparching events to QMsm. More...
 
bool QMsm_isInState (QMsm const *const me, QMState const *const state)
 Tests if a given state is part of the current active state configuration in a MSM. More...
 
QMState const * QMsm_childStateObj_ (QMsm const *const me, QMState const *const parent)
 Helper function to obtain the current active child state of a parent. More...
 

Variables

static QMState const l_msm_top_s
 

Detailed Description

QMsm implementation

Definition in file qep_msm.c.

Macro Definition Documentation

◆ QEP_ACT_PTR_INC_

#define QEP_ACT_PTR_INC_ (   act_)    (++(act_))

Internal QEP macro to increment the given action table act_.

Note
Incrementing a pointer violates the MISRA-C 2004 Rule 17.4(req), pointer arithmetic other than array indexing. Encapsulating this violation in a macro allows to selectively suppress this specific deviation.

Definition at line 71 of file qep_msm.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

internal QEP constants

Enumerator
QMSM_MAX_ENTRY_DEPTH_ 

maximum depth of entry levels in a MSM for transition to history.

Definition at line 52 of file qep_msm.c.

Function Documentation

◆ QMsm_execTatbl_()

static QState QMsm_execTatbl_ ( QMsm *const  me,
QMTranActTable const *  tatbl 
)
static

helper function to execute a transition-action table.

Description
Helper function to execute transition sequence in a transition-action table.
Parameters
[in,out]mepointer (see Object Orientation)
[in]tatblpointer to the transition-action table
Returns
status of the last action from the transition-action table.
Note
This function is for internal use inside the QEP event processor and should not be called directly from the applications.
Precondition
the transition-action table pointer must not be NULL

Definition at line 352 of file qep_msm.c.

◆ QMsm_exitToTranSource_()

static void QMsm_exitToTranSource_ ( QMsm *const  me,
QMState const *  s,
QMState const *  ts 
)
static

helper function to exit the current state up to the transition source

Description
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]mepointer (see Object Orientation)
[in]spointer to the current state
[in]tspointer to the transition source state

Definition at line 428 of file qep_msm.c.

◆ QMsm_enterHistory_()

static QState QMsm_enterHistory_ ( QMsm *const  me,
QMState const *const  hist 
)
static

helper function to execute a transition to history

Description
Static helper function to execute the segment of transition to history after entering the composite state and
Parameters
[in,out]mepointer (see Object Orientation)
[in]histpointer to the history substate
Returns
#Q_RET_INIT, if an initial transition has been executed in the last entered state or Q_RET_NULL if no such transition was taken.

Definition at line 466 of file qep_msm.c.

◆ QMsm_ctor()

void QMsm_ctor ( QMsm *const  me,
QStateHandler  initial 
)

Protected "constructor" of QMsm.

Description
Performs the first step of QMsm initialization by assigning the initial pseudostate to the currently active state of the state machine.
Parameters
[in,out]mepointer (see Object Orientation)
[in]initialthe top-most initial transition for the MSM.
Note
Must be called only ONCE before QHSM_INIT().
QMsm inherits QHsm, so by the Object Orientation convention it should call the constructor of the superclass, i.e., QHsm_ctor(). However, this would pull in the QHsmVtbl, which in turn will pull in the code for QHsm_init_() and QHsm_dispatch_() implemetations. To avoid this code size penalty, in case QHsm is not used in a given project, the QMsm_ctor() performs direct intitialization of the Vtbl, which avoids pulling in the code for QMsm.
Usage
The following example illustrates how to invoke QMsm_ctor() in the "constructor" of a derived state machine:
void Calc_ctor(Calc * const me) {
/* 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 108 of file qep_msm.c.

◆ QMsm_init_()

void QMsm_init_ ( QMsm *const  me,
QEvt const *const  e 
)

Implementation of the top-most initial transition in QMsm.

Description
Executes the top-most initial transition in a MSM.
Parameters
[in,out]mepointer (see Object Orientation)
[in]epointer to the initialization event (might be NULL)
Note
Must be called only ONCE after the QMsm_ctor().
Precondition
the virtual pointer must be initialized, the top-most initial transition must be initialized, and the initial transition must not be taken yet.

Definition at line 129 of file qep_msm.c.

◆ QMsm_dispatch_()

void QMsm_dispatch_ ( QMsm *const  me,
QEvt const *const  e 
)

Implementation of disparching events to QMsm.

Description
Dispatches an event for processing to a meta state machine (MSM). The processing of an event represents one run-to-completion (RTC) step.
Parameters
[in,out]mepointer (see Object Orientation)
[in]epointer to the event to be dispatched to the MSM
Note
This function should be called only via the virtual table (see QHSM_DISPATCH()) and should NOT be called directly in the applications.
Precondition
current state must be initialized

Definition at line 180 of file qep_msm.c.

◆ QMsm_isInState()

bool QMsm_isInState ( QMsm const *const  me,
QMState const *const  state 
)

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

Description
Tests if a state machine derived from QMsm is-in a given state.
Note
For a MSM, to "be-in" a state means also to "be-in" a superstate of of the state.
Parameters
[in]mepointer (see Object Orientation)
[in]statepointer to the QMState object that corresponds to the tested state.
Returns
'true' if the MSM "is in" the state and 'false' otherwise

Definition at line 529 of file qep_msm.c.

◆ QMsm_childStateObj_()

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

Helper function to obtain the current active child state of a parent.

Description
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]mepointer (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
See also
QMsm_childStateObj()
Postcondition
the child must be confirmed

Definition at line 558 of file qep_msm.c.

Variable Documentation

◆ l_msm_top_s

QMState const l_msm_top_s
static
Initial value:
= {
(QMState const *)0,
}
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition: qep.h:227
State object for the QMsm class (QM State Machine).
Definition: qep.h:402
#define Q_ACTION_CAST(action_)
Perform cast to QActionHandler.
Definition: qep.h:236

Definition at line 57 of file qep_msm.c.