RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
  1. Instantiating the composite states
rkh_bunner.jpg


Prev: Instantiating the state machine
Next: Declaring the basic states

A superstate or composite state is defined with the RKH_CREATE_COMP_STATE() macro and declared with the RKH_DCLR_COMP_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_COMP_STATE() macro is used.

The Figure 3 highlights the state "S1" and its relevant aspects. Also, shows its implementation using the RKH framework.


is1.png
Figure 3 - composite state "S1"


Defining the composite state "S1"

(1) // my.c: state-machine's module
(4) set_y_0,
(5) dummy_exit,
(6) RKH_ROOT,
(7) &S11,
(8) &DH);

Declaring the composite state "S1"

// my.h: state-machine's header file

Explanation

  • (1) Frequently, each state machine and its states are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_COMP_STATE() macro is used.
  • (2) S1 is the state name. Represents a composite state structure.
  • (4) set_y_0() defines the entry action to be executed unconditionally upon the entry to the S1 state. This argument is optional, thus it could be declared as NULL. The RKH_ENT_ACT_T defines the function prototype.
  • (5) dummy_exit() defines the exit action, which is executed upon exit from the S1 state. This argument is optional, thus it could be declared as NULL. The RKH_EXT_ACT_T defines the function prototype.
  • (6) RKH_ROOT is the parent state of S1. 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) S11 is the default state of S1 state machine. At each level of nesting, a superstate can have a private initial transition that designates the active substate after the superstate is entered directly. Here the initial transition of state S1 designates the state S11 as the initial active substate.
  • (8) DH is the deep history pseudostate. This argument is optional, thus it could be declared as NULL. See RKH_CREATE_SHALLOW_HISTORY_STATE() macro and RKH_CREATE_DEEP_HISTORY_STATE().

In RKH every state is associated with a transition table, which is composed of a well-defined set of transitions. The general syntax of an expression labelling a transition in a statechart is "i[c]/a" where i is the input that triggers the transition, c is a condition that guards the transition from being taken unless it is true when i occurs, and a is an action that is carried out if and when the transition is taken. All of these parts are optional. Thus, in RKH each row in a table represents a transition, which is well-defined by an event, a guard, an action, and target state (or pseudostate). The Figure 3 shows the transition table of "S1".

The following figures, Figure 5, and Figure 6 highlights the composite states "S3", and "S11". Also, shows its implementation using the RKH framework.


is3.png
Figure 5 - composite state "S3"


is11.png
Figure 6 - composite state "S11"



Prev: Instantiating the state machine
Next: Declaring the basic states