RKH
Loading...
Searching...
No Matches
3. Declaring the basic states


Prev: Instantiating the composite states
Next: Declaring the pseudostates

A basic state (also called substate) is defined with the RKH_CREATE_BASIC_STATE() macro and declared with the RKH_DCLR_BASIC_STATE() macro. Frequently, each state machine and its states (superstates and substates) are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_BASIC_STATE() macro is used. As will demostrates the use of RKH_CREATE_BASIC_STATE() macro and its arguments is very similar to RKH_CREATE_COMP_STATE() macro.

The Figure 7 highlights the basic states "S2". Also, shows its implementation using the RKH framework.


Figure 7 - basic state "S2"

Defining the basic state "S2"

(1) // my.c: state-machine's module
(4) NULL,
(5) NULL,
(6) RKH_ROOT,
(7) NULL);
#define RKH_CREATE_BASIC_STATE(name, en, ex, parent, prepro)
This macro creates a basic state.
Definition rkhsm.h:278
#define RKH_ROOT
This macro indicates the root state of a state machine.
Definition rkhsm.h:1020

Declaring the basic state "S2"

// my.h: state-machine's header file
#define RKH_DCLR_BASIC_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition rkhsm.h:1087

Explanation

  • (1) Frequently, each state machine and its states are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_BASIC_STATE() macro is used.
  • (2) S2 is the state name. Represents a substate structure.
  • (4) the entry action is unused, therefore it is declared as NULL.
  • (5) the exit action is unused, therefore it is declared as NULL.
  • (6) RKH_ROOT is the parent state of S2. If a state has no explicit superstate means that it is implicitly nested in the "top" state, and the parent state is defined by means of RKH_ROOT macro. The "top" state is a UML concept that denotes the ultimate root of the state hierarchy in a hierarchical state machine.
  • (7) the event preprocessor action is unused, therefore it is declared as NULL. Before sending the arrived event to state machine, it can be previously processed using the event preprocessor function. An action function takes the state machine pointer and the event pointer as arguments. The first parameter is optional in compile-time according to RKH_CFG_SMA_PPRO_ARG_SMA_EN macro. Example:
    static RKH_SIG_T
    in_keyb(RKH_EVT_T *pe)
    {
    if (pe->e >= 0 && pe->e <= 9)
    {
    return DECIMAL;
    }
    if (pe->e == '.')
    {
    return POINT;
    }
    else
    {
    return pe->e;
    }
    }
    rui8_t RKH_SIG_T
    Definition rkhevt.h:106
    Represents events without parameters.
    Definition rkhevt.h:170
    RKH_SIG_T e
    Signal of the event instance.
    Definition rkhevt.h:175
  • (7)


The following figures, Figure 8, Figure 9, and Figure 10 highlights the basic states "S111", "S112", "S31", "S32", and "S12" respectively. Also, shows its implementation using the RKH framework.


Figure 8 - basic states "S111", and "S112"


Figure 9 - basic state "S12"


Figure 10 - basic states "S31", and "S32"


Prev: Instantiating the composite states
Next: Declaring the pseudostates