RKH
|
Files | |
file | rkh.h |
RKH framwwork platform - independent interface. | |
file | rkhsm.h |
Specifies the interface of the state-machine manager. | |
Data Structures | |
struct | RKH_SM_T |
Describes the state machine. More... | |
Macros | |
#define | RKH_CREATE_COMP_REGION_STATE(name, en, ex, parent, defchild, initialTrn, kindOfHistory, hDftTrnGuard, hDftTrnAction, hDftTarget, hRamMem) |
This macro creates a composite state with a single region, including its own initial pseudostate, history (shallow and deep type) pseudostate, as well as its own final state. More... | |
#define | RKH_CREATE_COMP_STATE(name, en, ex, parent, defchild, history) |
This macro creates a composite state. More... | |
#define | RKH_CREATE_FINAL_STATE(name, parent) |
This macro creates a final state. More... | |
#define | RKH_CREATE_BASIC_STATE(name, en, ex, parent, prepro) |
This macro creates a basic state. More... | |
#define | RKH_CREATE_COND_STATE(name) |
This macro creates a conditional pseudostate (a.k.a. junction). More... | |
#define | RKH_CREATE_CHOICE_STATE(name) |
This macro creates a choice pseudostate. More... | |
#define | RKH_CREATE_DEEP_HISTORY_STATE(name, parent, dftTrnGuard, dftTrnAction, dftTarget) |
More... | |
#define | RKH_CREATE_SHALLOW_HISTORY_STATE(name, parent, dftTrnGuard, dftTrnAction, dftTarget) |
More... | |
#define | RKH_CREATE_SUBMACHINE_STATE(name, en, ex, parent, sbm) |
This macro creates a submachine state. More... | |
#define | RKH_CREATE_EX_CNNPNT_TABLE(name) |
This macro creates a exit point connection point reference table. More... | |
#define | RKH_CREATE_REF_SUBMACHINE(name, defchild, iact) |
This macro creates a submachine state machine, which is to be inserted in place of the (submachine) state. More... | |
#define | RKH_CREATE_REF_EXPNT(name, ix, subm) |
This macro creates an exit point. More... | |
#define | RKH_CREATE_REF_ENPNT(name, act, ts, subm) |
This macro creates a entry point. More... | |
#define | RKH_CREATE_TRANS_TABLE(name) |
This macro creates a state transition table. More... | |
#define | RKH_CREATE_BRANCH_TABLE(name) |
More... | |
#define | RKH_CREATE_HISTORY_STORAGE(compStateName) static RKHROM RKH_ST_T *ramHist_##compStateName |
Define a RAM storage to mantain the last visited state of a composite state (history pseudostate). More... | |
Enumerations | |
enum | RKH_RCODE_T { RKH_EVT_PROC , RKH_EVT_NFOUND , RKH_CND_NFOUND , RKH_GRD_FALSE , RKH_UNKN_STATE , RKH_EX_HLEVEL , RKH_EX_TSEG , RKH_NUM_CODES } |
Return codes from rkh_sm_dispatch() function. More... | |
enum | RKH_HPPTY_T { HCAL , FLAT , RKH_NUM_HPPTY } |
State machine properties. More... | |
Functions | |
void | rkh_sm_init (RKH_SM_T *me) |
Inits a previously created state machine calling its initializing action. More... | |
ruint | rkh_sm_dispatch (RKH_SM_T *me, RKH_EVT_T *e) |
Executes a state machine in a run-to-completation (RTC) model. More... | |
void | rkh_sm_ctor (RKH_SM_T *me) |
Initializes the attributes of the state machine instance. More... | |
void | rkh_sm_clear_history (RKHROM RKH_SHIST_T *h) |
Erase the history of a state. It can be a shallow or deep history. More... | |
#define RKH_CREATE_COMP_REGION_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
defchild, | |||
initialTrn, | |||
kindOfHistory, | |||
hDftTrnGuard, | |||
hDftTrnAction, | |||
hDftTarget, | |||
hRamMem | |||
) |
This macro creates a composite state with a single region, including its own initial pseudostate, history (shallow and deep type) pseudostate, as well as its own final state.
The names of history pseudostate and final state are internally conformed as "<nameOfCompositeState>Hist" and "<nameOfCompositeState>Final" respectively. Thus, use these names as target vertex in a transition.
Shallow history means that history applies to the current nesting context only states nested more deeply are not affected by the presence of a history pseudostates in a higher context. Deep history applies downwards to all levels of nesting.
[in] | name | state name. Represents a composite state structure. |
[in] | en | pointer to state entry action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | ex | pointer to state exit action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | parent | pointer to parent state. |
[in] | defchild | pointer to default child state or pseudostate. |
[in] | initialTrn | pointer to initial transition action of the composite state's region. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by UML. |
[in] | kindOfHistory | Kind of history pseudostate. It could be defined either shallow history (RKH_SHISTORY), deep history (RKH_DHISTORY) or without history (RKH_NO_HISTORY). When it is defined as RKH_NO_HISTORY each of parameters related to history default transition are ignored. The name of this history pseudostate is automatically generated from the name of composite state parent as "<composite_state_name>Hist". |
[in] | hDftTrnGuard | Pointer to guard function associated to history default transition. This argument is optional, thus it could be declared as NULL. |
[in] | hDftTrnAction | Pointer to effect action function associated to history default transition. This argument is optional, thus it could be declared as NULL. |
[in] | hDftTarget | Pointer to target vertex of history default transition. If a default history transition is defined (the target parameter is not NULL) originating from the History Pseudostate, it will be taken. Otherwise, default State entry is applied. |
[in] | hRamMem | Pointer to a RAM location which maintains the last visited state of this region. If composite state don't include the history pseudostate then this parameter should be passed as NULL. Please, use RKH_CREATE_HISTORY_STORAGE() macro to create the history RAM location. |
#define RKH_CREATE_COMP_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
defchild, | |||
history | |||
) |
This macro creates a composite state.
[in] | name | state name. Represents a composite state structure. |
[in] | en | pointer to state entry action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | ex | pointer to state exit action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | parent | pointer to parent state. |
[in] | defchild | pointer to default child state or pseudostate. |
[in] | history | pointer history pseudostate. This argument is optional, thus it could be declared as NULL. |
#define RKH_CREATE_FINAL_STATE | ( | name, | |
parent | |||
) |
This macro creates a final state.
[in] | name | state name. Represents a composite state structure. |
[in] | parent | pointer to parent state. |
#define RKH_CREATE_BASIC_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
prepro | |||
) |
This macro creates a basic state.
[in] | name | state name. Represents a basic state structure. |
[in] | en | pointer to state entry action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | ex | pointer to state exit action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | parent | pointer to parent state. |
[in] | prepro | pointer to input preprocessor function. This function could be called "Moore" action. This argument is optional, thus it could be declared as NULL. Aditionally, by means of single inheritance in C it could be used as state's abstract data. Moreover, implementing the single inheritance in C is very simply by literally embedding the base type, RKH_PPRO_T in this case, as the first member of the derived structure. See prepro member of RKH_SBSC_T structure for more information. |
#define RKH_CREATE_COND_STATE | ( | name | ) |
This macro creates a conditional pseudostate (a.k.a. junction).
The conditional pseudostates are semantic-free vertices that are used to chain together multiple transitions. They are used to construct compound transition paths between states. For example, a junction can be used to converge multiple incoming transitions into a single outgoing transition representing a shared transition path (this is known as a merge). Conversely, they can be used to split an incoming transition into multiple outgoing transition segments with different guard conditions. This realizes a static conditional branch. (In the latter case, outgoing transitions whose guard conditions evaluate to false are disabled. A predefined guard denoted "ELSE" may be defined for at most one outgoing transition. This transition is enabled if all the guards labeling the other transitions are false.) Static conditional branches are distinct from dynamic conditional branches that are realized by choice vertices.
[in] | name | pseudostate name. Represents a conditional pseudostate structure. |
#define RKH_CREATE_CHOICE_STATE | ( | name | ) |
This macro creates a choice pseudostate.
Choice pseudostate which, when reached, result in the dynamic evaluation of the guards of its outgoing transitions. This realizes a dynamic conditional branch. It allows splitting of transitions into multiple outgoing paths such that the decision on which path to take may be a function of the results of prior actions performed in the same run-to-completion step. If more than one of the guards evaluates to true, an arbitrary one is selected. If none of the guards evaluates to true, then the model is considered ill-formed. To avoid this, it is recommended to define one outgoing transition with the predefined "ELSE" guard for every choice pseudostate. Also, branches cannot contain triggers, but in addition to a guard they may contain actions. A branch can enter another choice connector, thus providing for the nesting of branches.
[in] | name | pseudostate name. Represents a choice pseudostate structure. |
#define RKH_CREATE_DEEP_HISTORY_STATE | ( | name, | |
parent, | |||
dftTrnGuard, | |||
dftTrnAction, | |||
dftTarget | |||
) |
Deep history applies downwards to all levels of nesting.
[in] | name | pseudostate name. Represents a deep history pseudostate structure. |
[in] | parent | pointer to parent state. |
[in] | dftTrnGuard | pointer to guard function. This argument is optional, thus it could be declared as NULL. |
[in] | dftTrnAction | pointer to action function. This argument is optional, thus it could be declared as NULL. |
[in] | dftTarget | pointer to target state. If a default history Transition is defined (the target parameter is not NULL) originating from the History Pseudostate, it will be taken. Otherwise, default State entry is applied. |
#define RKH_CREATE_SHALLOW_HISTORY_STATE | ( | name, | |
parent, | |||
dftTrnGuard, | |||
dftTrnAction, | |||
dftTarget | |||
) |
Shallow history means that history applies to the current nesting context only states nested more deeply are not affected by the presence of a history pseudostates in a higher context.
[in] | name | pseudostate name. Represents a shallow history pseudostate structure. |
[in] | parent | pointer to parent state. |
[in] | dftTrnGuard | pointer to guard function. This argument is optional, thus it could be declared as NULL. |
[in] | dftTrnAction | pointer to action function. This argument is optional, thus it could be declared as NULL. |
[in] | dftTarget | pointer to target state. If a default history Transition is defined (the target parameter is not NULL) originating from the History Pseudostate, it will be taken. Otherwise, default State entry is applied. |
#define RKH_CREATE_SUBMACHINE_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
sbm | |||
) |
This macro creates a submachine state.
A submachine state is a kind of a state that actually refers to another defined state machine. A submachine state is logically equivalent to the insertion of the referenced state machine as a composite state in the place of the submachine state. Consequently, every entrance to a submachine state is equivalent to the corresponding entrance to the inserted (referenced) composite state. In particular, it can be entered thruough its initial pseudostate (as any other composite state), or through one of its entry points.
Similary, every exit from a submachine state is equivalent to the corresponding exit from the inserted composite state. It can be exited through one of its exit points. When it is exited through its exit point the effect of the transition targeting the exit point is executed first, followed by the exit behavior of the composite state.
The purpose od defining submachine states is to decompose and localize repetitive parts because the same state machine can be referenced from more than one submachine state.
[in] | name | submachine state name. Represents a submachine state structure. |
[in] | en | pointer to state entry action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | ex | pointer to state exit action. This argument is optional, thus it could be declared as NULL. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. |
[in] | parent | pointer to parent state. |
[in] | sbm | pointer to referenced submachine state machine. |
#define RKH_CREATE_EX_CNNPNT_TABLE | ( | name | ) |
This macro creates a exit point connection point reference table.
[in] | name | submachine state name |
#define RKH_CREATE_REF_SUBMACHINE | ( | name, | |
defchild, | |||
iact | |||
) |
This macro creates a submachine state machine, which is to be inserted in place of the (submachine) state.
[in] | name | submachine name. Represents a submachine structure. |
[in] | defchild | pointer to default child state. |
[in] | iact | pointer to initialization action (optional). The function prototype is defined as RKH_TRN_ACT_T. This argument is optional, thus it could be declared as NULL. |
#define RKH_CREATE_REF_EXPNT | ( | name, | |
ix, | |||
subm | |||
) |
This macro creates an exit point.
An exit pseudostate is used to join an internal transition terminating on that exit point to an external transition emanating from that exit point. The main purpose of such entry and exit points is to execute the state entry and exit actions respectively in between the actions that are associated with the joined transitions.
[in] | name | entry point name. |
[in] | ix | index of exit point connection table. Note that each row number matches with the index number of the exit point pseudostate that it represent. |
[in] | subm | pointer to submachine state machine. |
#define RKH_CREATE_REF_ENPNT | ( | name, | |
act, | |||
ts, | |||
subm | |||
) |
This macro creates a entry point.
An entry pseudostate is used to join an external transition terminating on that entry point to an internal transition emanating from that entry point. The main purpose of such entry and exit points is to execute the state entry and exit actions respectively in between the actions that are associated with the joined transitions.
[in] | name | entry point name. |
[in] | act | pointer to transition action function. This argument is optional, thus it could be declared as NULL. |
[in] | ts | pointer to target state. |
[in] | subm | pointer to submachine state machine. |
#define RKH_CREATE_TRANS_TABLE | ( | name | ) |
This macro creates a state transition table.
[in] | name | state name. |
#define RKH_CREATE_BRANCH_TABLE | ( | name | ) |
This macro creates a branch table.
[in] | name | conditional pseudostate name. |
#define RKH_CREATE_HISTORY_STORAGE | ( | compStateName | ) | static RKHROM RKH_ST_T *ramHist_##compStateName |
Define a RAM storage to mantain the last visited state of a composite state (history pseudostate).
Frequently, it's used before of RKH_CREATE_COMP_REGION_STATE() macro to define the dynamic storage of a history pseudostate.
[in] | compStateName | pointer to the composite state that contains this history pseudostate. |
enum RKH_RCODE_T |
Return codes from rkh_sm_dispatch() function.
enum RKH_HPPTY_T |
State machine properties.
Enumerator | |
---|---|
HCAL | Used as state machine property. This macro enables state nesting in a particular state machine. |
FLAT | Used as state machine property. This macro disables state nesting in a particular state machine. When FLAT is used in RKH_SMA_CREATE() macro some important features of RKH are not included: state nesting, composite state, history (shallow and deep) pseudostate, entry action, and exit action. |
RKH_NUM_HPPTY | Number of state machines properties |
void rkh_sm_init | ( | RKH_SM_T * | me | ) |
Inits a previously created state machine calling its initializing action.
[in] | me | pointer to previously created state machine. |
Executes a state machine in a run-to-completation (RTC) model.
In this model, before the system handles a new event it can store it until the previous event has completed processing. This model is called run to completion or RTC. Thus, the system processes events in discrete, indivisible RTC steps. An RTC step is the period of time in which events are accepted and acted upon. Processing an event always completes within a single model step, including exiting the source state, executing any associated actions, and entering the target state. The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. Specifically, the implemented transition sequence is as follows:
Here now are the details of the main part of this algorithm (rkh_sm_dispatch()), in which an event is processed by the statechart.
[in] | me | pointer to previously created state machine application. |
[in] | e | pointer to arrived event. It's used as state-machine's input alphabet. |
void rkh_sm_ctor | ( | RKH_SM_T * | me | ) |
Initializes the attributes of the state machine instance.
[in] | me | pointer to previously created state machine. |
void rkh_sm_clear_history | ( | RKHROM RKH_SHIST_T * | h | ) |
Erase the history of a state. It can be a shallow or deep history.
[in] | h | pointer to history pseudostate. |