RKH
|
Specifies the interface of the state-machine manager. More...
#include "rkhitl.h"
Go to the source code of this file.
Data Structures | |
struct | RKH_ROM_T |
Constant parameters of state machine. More... | |
struct | RKH_SM_T |
Describes the state machine. More... | |
struct | RKH_BASE_T |
Maintains the basic information of a state. More... | |
struct | RKH_TR_T |
Describes the state transition. More... | |
struct | RKH_ST_T |
Describes the common properties of regular states (basic, composite, and submachine). More... | |
struct | RKH_SBSC_T |
Describes a basic state. More... | |
struct | RKH_SCMP_T |
Describes a composite state. More... | |
struct | RKH_FINAL_T |
Describes a final state. More... | |
struct | RKH_EXPCN_T |
Describes the exit point connection. More... | |
struct | RKH_ENPCN_T |
Describes the entry point connection. More... | |
struct | RKH_SSBM_T |
Describes a submachine state. More... | |
struct | RKH_RSM_T |
Describes a (referenced) submachine state machine. More... | |
struct | RKH_SENP_T |
Describes the entry point pseudostate. More... | |
struct | RKH_SEXP_T |
Describes the exit point pseudostate. More... | |
struct | RKH_SCOND_T |
Describes the conditional pseudostate. More... | |
struct | RKH_SCHOICE_T |
Describes the choice pseudostate. More... | |
struct | RKH_SHIST_T |
Describes the history pseudostate. More... | |
Macros | |
#define | ELSE rkh_sm_else |
Each condition connector can have one special branch with a guard labeled ELSE, which is taken if all the guards on the other branches are false. 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. 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_EX_CNNPNT(name, expnt, act, ts) {(RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts} |
This macro creates an exit point connection point reference. More... | |
#define | RKH_END_EX_CNNPNT_TABLE }; |
This macro is used to terminate a exit point connection reference table. More... | |
#define | RKH_EN_CNNPNT(name, enpnt, subm) |
This macro creates an entry point connection point reference. 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_TRREG(evt_, guard_, effect_, target_) MKTRN(evt_, guard_, effect_, target_) |
This macro defines a regular state transition. More... | |
#define | RKH_TRINT(e, g, a) {e, (RKH_GUARD_T)g, (RKH_TRN_ACT_T)a, NULL} |
This macro defines an internal state transition. Internal transitions are simple reactions to events that never lead to change of state and consequently never cause execution of exit actions, entry actions, or initial transitions. More... | |
#define | RKH_TRCOMPLETION(guard_, effect_, target_) |
This macro defines a completion transition. More... | |
#define | RKH_END_TRANS_TABLE {RKH_ANY, NULL, NULL, NULL}}; |
This macro is used to terminate a state transition table. This table have the general structure shown below: More... | |
#define | RKH_CREATE_BRANCH_TABLE(name) |
More... | |
#define | RKH_BRANCH(guard_, effect_, target_) MKTRN(0, guard_, effect_, target_) |
This macro defines a branch in the branch table. 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... | |
#define | RKH_GET_HISTORY_STORAGE(compStateName) &ramHist_##compStateName |
Return the history storage address of a composite state. More... | |
#define | RKH_END_BRANCH_TABLE RKH_EBTBL}; |
This macro is used to terminate a state transition table. This table have the general structure shown below: More... | |
#define | RKH_ROOT RKH_NULL |
This macro indicates the root state of a state machine. | |
#define | RKH_SM_DCLR(me_) RKH_DCLR_PTR_TYPE(RKH_SM_T, me_) |
This macro declares an opaque pointer to previously created state machine to be used as a global object. More... | |
#define | RKH_SM_DCLR_TYPE(type_, me_) RKH_DCLR_PTR_TYPE(type_, me_) |
This macro declares a typed pointer to previously created state machine to be used as a global and public object. More... | |
#define | RKH_DECLARE_TR_TBL(name) extern RKHROM RKH_TR_T name##_trtbl[] |
Declares a state transition table. More... | |
#define | RKH_DCLR_SM_GLOBAL(sm_t, sm, gob) sm_t * const gob = &s_##sm; |
Declares a previously created SM to be used as a global object. More... | |
#define | RKH_DCLR_SM_CONST_GLOBAL(smName) extern RKHROM RKH_ROM_T RKH_SM_CONST_NAME(smName) |
Declares a previously created constant part (in ROM) of a state machine to be used as a global object. More... | |
#define | RKH_INIT_BASIC_STATE(name, en, ex, parent, prepro) |
Initializes the parameters (attibutes) of a basic state object. More... | |
#define | RKH_INIT_COMPOSITE_STATE(name, en, ex, parent, defchild, history) |
Initializes the parameters (attibutes) of a composite state object. More... | |
#define | RKH_GFALSE RKH_FALSE |
This values are retrived by guard functions. More... | |
#define | RKH_GTRUE RKH_TRUE |
More... | |
#define | RKH_SM_CREATE(type, name, prio, ppty, initialState, initialAction, initialEvt) |
Use it to allocate a state machine regardless of an active object. More... | |
#define | RKH_SM_INIT(me_, nameSMConst_, prio_, ppty_, initialState_, initialAction_, initialEvt_) |
Initialize (at runtime) a previously created state machine object. More... | |
#define | RKH_SM_CONST_CREATE(name, prio, ppty, initialState, initialAction, initialEvt) |
Allocates and then initializes the constant part (in ROM) of the state machine. More... | |
#define | RKH_SM_GET_CONST(sm) ((RKH_SM_T *)sm)->romrkh |
Return the address of the constant part from a previously created and initializated state machine. More... | |
#define | RKH_SM_GET_CONST_OBJ(sm) &RKH_SM_CONST_NAME(sm) |
Return the address of the constant part of a state machine. More... | |
#define | RKH_SM_DEF_PTR(sm) RKH_SM_T *const sm = (RKH_SM_T *)&RKH_SM_NAME(sm) |
Declare an opaque pointer pointing to a previously created state machine. More... | |
#define | RKH_SM_DEF_PTR_TYPE(type, sm) type *const sm = (type *)&RKH_SM_NAME(sm) |
Declare a pointer of specified type pointing to a previously created state machine. More... | |
#define | RKH_GET_CSTATE_ID(me) ((RKH_BASE_T *)(((RKH_SM_T *)me)->state))->id |
This macro retrieves the state ID of SMA. More... | |
#define | RKH_GET_VERTEX_NAME(vx) ((struct RKH_BASE_T *)(vx))->name |
This macro retrieves the name of a vertex. More... | |
#define | RKH_DCLR_COMP_STATE extern RKHROM RKH_SCMP_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_BASIC_STATE extern RKHROM RKH_SBSC_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_FINAL_STATE extern RKHROM RKH_FINAL_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_COND_STATE extern RKHROM RKH_SCOND_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_CHOICE_STATE extern RKHROM RKH_SCHOICE_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_DHIST_STATE extern RKHROM RKH_SHIST_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_SHIST_STATE extern RKHROM RKH_SHIST_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_SUBM_STATE extern RKHROM RKH_SSBM_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_REF_SUBM extern RKHROM RKH_RSM_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_ENPNT extern RKHROM RKH_SENP_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_REF_EXPNT extern RKHROM RKH_SEXP_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
#define | RKH_DCLR_REF_ENPNT extern RKHROM RKH_ENPCN_T |
Declares a previously created state/pseudostate to be used as a global object. More... | |
Typedefs | |
typedef void(* | RKH_ENT_ACT_T) (const RKH_SM_T *me) |
Entry action. More... | |
typedef void(* | RKH_EXT_ACT_T) (const RKH_SM_T *me) |
Exit action. More... | |
typedef RKH_SIG_T(* | RKH_PPRO_T) (const RKH_SM_T *sma, RKH_EVT_T *pe) |
Event preprocessor. More... | |
typedef void(* | RKH_TRN_ACT_T) (const RKH_SM_T *me, RKH_EVT_T *pe) |
Transition action. More... | |
typedef rbool_t(* | RKH_GUARD_T) (const RKH_SM_T *me, RKH_EVT_T *pe) |
Guard. 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... | |
Specifies the interface of the state-machine manager.
Definition in file rkhsm.h.
#define ELSE rkh_sm_else |
Each condition connector can have one special branch with a guard labeled ELSE, which is taken if all the guards on the other branches are false.
A guard function takes the state machine pointer and the event pointer as arguments. These arguments are optional, thus they could be eliminated in compile-time by means of RKH_EN_GRD_EVT_ARG and RKH_EN_GRD_HSM_ARG preprocessor directives.
#define RKH_EX_CNNPNT | ( | name, | |
expnt, | |||
act, | |||
ts | |||
) | {(RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts} |
This macro creates an exit point connection point reference.
Connection point references are sources/targets of transitions implying exits out of/entries into the submachine state machine referenced by a submachine state.
An exit point connection point reference as the source of a transition implies that the source of the transition is the exit point pseudostate as defined in the submachine of the submachine state that has the exit point connection point defined.
A connection point reference to an exit point has the same notation as an exit point pseudostate.
[in] | name | exit point connection point reference name. |
[in] | expnt | referenced exit point. |
[in] | act | pointer to transition action function. This argument is optional, thus it could be declared as NULL. |
[in] | ts | pointer to target state. |
#define RKH_END_EX_CNNPNT_TABLE }; |
This macro is used to terminate a exit point connection reference table.
#define RKH_EN_CNNPNT | ( | name, | |
enpnt, | |||
subm | |||
) |
This macro creates an entry point connection point reference.
Connection point references are sources/targets of transitions implying exits out of/entries into the submachine state machine referenced by a submachine state.
An entry point connection point reference as the target of a transition implies that the target of the transition is the entry point pseudostate as defined in the submachine of the submachine state.
A connection point reference to an entry point has the same notation as an entry point pseudostate.
[in] | name | entry point connection point reference name. |
[in] | enpnt | referenced entry point. |
[in] | subm | pointer to submachine state. |
#define RKH_TRREG | ( | evt_, | |
guard_, | |||
effect_, | |||
target_ | |||
) | MKTRN(evt_, guard_, effect_, target_) |
This macro defines a regular state transition.
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.
[in] | evt_ | triggering event. |
[in] | guard_ | pointer to guard function. This argument is optional, thus it could be declared as NULL. |
[in] | effect_ | pointer to action function. This argument is optional, thus it could be declared as NULL. |
[in] | target_ | pointer to target state. |
#define RKH_TRINT | ( | e, | |
g, | |||
a | |||
) | {e, (RKH_GUARD_T)g, (RKH_TRN_ACT_T)a, NULL} |
This macro defines an internal state transition. Internal transitions are simple reactions to events that never lead to change of state and consequently never cause execution of exit actions, entry actions, or initial transitions.
[in] | e | triggering event. |
[in] | g | pointer to guard function. |
[in] | a | pointer to action function. |
#define RKH_TRCOMPLETION | ( | guard_, | |
effect_, | |||
target_ | |||
) |
This macro defines a completion transition.
A special kind of transition is a completion transition, which has an implicit trigger. The event that enables this trigger is called a completion event and it signifies that all behaviors associated with the source state of the completion transition have completed execution. In case of simple states, a completion event is generated when the associated entry behavior have completed executing. If no such behaviors are defined, the completion event is generated upon entry into the state. For composite state, a completion event is generated under the following circumstances:
[in] | guard_ | pointer to guard function. This argument is optional, thus it could be declared as NULL. |
[in] | effect_ | pointer to effect function. This argument is optional, thus it could be declared as NULL. |
[in] | target_ | pointer to target vertex (state or pseudostate). |
#define RKH_END_TRANS_TABLE {RKH_ANY, NULL, NULL, NULL}}; |
This macro is used to terminate a state transition table. This table have the general structure shown below:
Each transition table always begins with the macro RKH_CREATE_TRANS_TABLE() and ends with the macro RKH_END_TRANS_TABLE(). As noted above, sandwiched between these macros are the transitions macros that actually represent behavior of state.
#define RKH_BRANCH | ( | guard_, | |
effect_, | |||
target_ | |||
) | MKTRN(0, guard_, effect_, target_) |
This macro defines a branch in the branch table.
Each condition connector can have one special branch with a guard labeled rkh_sm_else, which is taken if all the guards on the other branches are false. The general syntax of an expression labelling a branch in a statechart is "[c]/a" where c is a condition that guards the transition from being taken unless it is true, and a is an action that is carried out if and when the transition is taken. All of these parts are optional.
[in] | guard_ | branch guard function. Branches are labeled with guards that determine which one is to be actually taken. Use ELSE macro when if all the guards on the other branches are false. |
[in] | effect_ | pointer to transition action. This argument is optional, thus it could be declared as NULL. |
[in] | target_ | pointer to target state. |
#define RKH_GET_HISTORY_STORAGE | ( | compStateName | ) | &ramHist_##compStateName |
Return the history storage address of a composite state.
Frequently, it's used in the hRamMem parameter 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. |
#define RKH_END_BRANCH_TABLE RKH_EBTBL}; |
This macro is used to terminate a state transition table. This table have the general structure shown below:
Each branch table always begins with the macro RKH_CREATE_BRANCH_TABLE() and ends with the macro RKH_END_BRANCH_TABLE().
#define RKH_SM_DCLR | ( | me_ | ) | RKH_DCLR_PTR_TYPE(RKH_SM_T, me_) |
This macro declares an opaque pointer to previously created state machine to be used as a global object.
This global pointer represent the state machine in the application. The state machine pointers are "opaque" because they cannot access the whole state machine structure, but only the part inherited from the RKH_SM_T structure. The power of an "opaque" pointer is that it allows to completely hide the definition of the state machine structure and make it inaccessible to the rest of the application.
[in] | me_ | Pointer to previously created state machine. |
#define RKH_SM_DCLR_TYPE | ( | type_, | |
me_ | |||
) | RKH_DCLR_PTR_TYPE(type_, me_) |
This macro declares a typed pointer to previously created state machine to be used as a global and public object.
[in] | type_ | Data type of the state machine, derived from RKH_SM_T. |
[in] | me_ | Pointer to previously created state machine. |
#define RKH_DCLR_COMP_STATE extern RKHROM RKH_SCMP_T |
#define RKH_DCLR_BASIC_STATE extern RKHROM RKH_SBSC_T |
#define RKH_DCLR_FINAL_STATE extern RKHROM RKH_FINAL_T |
#define RKH_DCLR_COND_STATE extern RKHROM RKH_SCOND_T |
#define RKH_DCLR_CHOICE_STATE extern RKHROM RKH_SCHOICE_T |
#define RKH_DCLR_DHIST_STATE extern RKHROM RKH_SHIST_T |
#define RKH_DCLR_SHIST_STATE extern RKHROM RKH_SHIST_T |
#define RKH_DCLR_SUBM_STATE extern RKHROM RKH_SSBM_T |
#define RKH_DCLR_REF_SUBM extern RKHROM RKH_RSM_T |
#define RKH_DCLR_ENPNT extern RKHROM RKH_SENP_T |
#define RKH_DCLR_REF_EXPNT extern RKHROM RKH_SEXP_T |
#define RKH_DCLR_REF_ENPNT extern RKHROM RKH_ENPCN_T |
#define RKH_DECLARE_TR_TBL | ( | name | ) | extern RKHROM RKH_TR_T name##_trtbl[] |
#define RKH_DCLR_SM_GLOBAL | ( | sm_t, | |
sm, | |||
gob | |||
) | sm_t * const gob = &s_##sm; |
Declares a previously created SM to be used as a global object.
[in] | sm_t | data type of SM. |
[in] | sm | name of previously created SM. |
[in] | gob | name of global object. |
#define RKH_DCLR_SM_CONST_GLOBAL | ( | smName | ) | extern RKHROM RKH_ROM_T RKH_SM_CONST_NAME(smName) |
Declares a previously created constant part (in ROM) of a state machine to be used as a global object.
[in] | smName | name of previously created SM. |
#define RKH_INIT_BASIC_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
prepro | |||
) |
Initializes the parameters (attibutes) of a basic state object.
By means of single inheritance in C it could be used to associate data to a basic state. Moreover, implementing the single inheritance in C is very simply by literally embedding the base type, RKH_SBSC_T in this case, as the first member of the derived structure. The following listing shows an example:
(1) Defines MENU_ST_T as a derived structure from the basic state structure. It could be used to associate data to a basic state objects.
(2) Implementing the single inheritance in C is very simply by literally embedding the base type, RKH_SBSC_T in this case, as the first member of the derived structure.
(3) Private members of MENU_ST_T derived structure.
(4) Defines a simple macro to instantiate the derived state object. It is not strictly necessary.
(4) Declares the transtion table by means of RKH_DECLARE_TR_TBL() macro provided by the framework.
(6) Instantiates the derived state structure.
(7) Initializes the base structure, basic state in this case, using the RKH_INIT_BASIC_STATE() macro provided by the framework.
(8) Initializes the private member of derived state.
(9) Invokes the BLINKY_BASIC_STATE() macro to instantiate the derived state object, menu_cfg. Note that the "Menu 1" string is associated to the state machine context, menu_cfg state in this case.
(10) Lastly, on the transtion action mc_title(), or any other action, is used the state data after casting the active object state to derived state object.
The following listing shows another example for derived state structure, which access to RAM from ROM object (state structure).
(1) Defines NUM_STATE_T as a derived structure from the basic state structure.
(2) Implementing the single inheritance in C is very simply by literally embedding the base type, RKH_SBSC_T in this case, as the first member of the derived structure.
(3) Private members of NUM_STATE_T derived structure. It allows to acccess to RAM locations from this object (NUM_STATE_ST) allocated in ROM.
(4) Defines a simple macro to instantiate the derived state object.
(5) Initializes the private member of derived state.
(6,7)Invokes the NUM_BASIC_STATE() macro to instantiate the derived state object, num. Note that the variable xy is allocated in RAM but it is access to read and write from ROM object.
#define RKH_INIT_COMPOSITE_STATE | ( | name, | |
en, | |||
ex, | |||
parent, | |||
defchild, | |||
history | |||
) |
Initializes the parameters (attibutes) of a composite state object.
By means of single inheritance in C it could be used to associate data to a basic state. Moreover, implementing the single inheritance in C is very simply by literally embedding the base type, RKH_SCMP_T in this case, as the first member of the derived structure.
#define RKH_GFALSE RKH_FALSE |
#define RKH_SM_CREATE | ( | type, | |
name, | |||
prio, | |||
ppty, | |||
initialState, | |||
initialAction, | |||
initialEvt | |||
) |
Use it to allocate a state machine regardless of an active object.
[in] | type | Data type of the SMA. Could be derived from RKH_SMA_T. |
[in] | name | Name of state machine application. Also, it represents the top state of state diagram. |
[in] | prio | State machine application priority. A unique priority number must be assigned to each SMA from 0 to RKH_LOWEST_PRIO. The lower the number, the higher the priority. |
[in] | ppty | State machine properties. The available properties are enumerated in RKH_HPPTY_T enumeration in the rkh.h file. |
[in] | initialState | Pointer to initial state. This state could be defined either composite or basic (not pseudo-state). |
[in] | initialAction | 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. |
[in] | initialEvt | Pointer to an event that will be passed to state machine application when it starts. Could be used to pass arguments to the state machine like an argc/argv. This argument is optional, thus it could be declared as NULL or eliminated in compile-time with RKH_CFG_SMA_INIT_EVT_EN = 0. |
#define RKH_SM_INIT | ( | me_, | |
nameSMConst_, | |||
prio_, | |||
ppty_, | |||
initialState_, | |||
initialAction_, | |||
initialEvt_ | |||
) |
Initialize (at runtime) a previously created state machine object.
[in] | me_ | Name of state machine. Also, it represents the top state of state diagram. |
[in] | nameSMConst_ | Describe it |
[in] | prio_ | State machine application priority. A unique priority number must be assigned to each SMA from 0 to RKH_LOWEST_PRIO. The lower the number, the higher the priority. |
[in] | ppty_ | State machine properties. The available properties are enumerated in RKH_HPPTY_T enumeration in the rkh.h file. |
[in] | initialState_ | Pointer to initial state. This state could be defined either composite or basic (not pseudo-state). |
[in] | initialAction_ | 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. |
[in] | initialEvt_ | Pointer to an event that will be passed to state machine application when it starts. Could be used to pass arguments to the state machine like an argc/argv. This argument is optional, thus it could be declared as NULL or eliminated in compile-time with RKH_CFG_SMA_INIT_EVT_EN = 0. |
#define RKH_SM_CONST_CREATE | ( | name, | |
prio, | |||
ppty, | |||
initialState, | |||
initialAction, | |||
initialEvt | |||
) |
Allocates and then initializes the constant part (in ROM) of the state machine.
[in] | name | Name of state machine application. Also, it represents the top state of state diagram. |
[in] | prio | State machine application priority. A unique priority number must be assigned to each SMA from 0 to RKH_LOWEST_PRIO. The lower the number, the higher the priority. |
[in] | ppty | State machine properties. The available properties are enumerated in RKH_HPPTY_T enumeration in the rkh.h file. |
[in] | initialState | Pointer to initial state. This state could be defined either composite or basic (not pseudo-state). |
[in] | initialAction | 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. |
[in] | initialEvt | Pointer to an event that will be passed to state machine application when it starts. Could be used to pass arguments to the state machine like an argc/argv. This argument is optional, thus it could be declared as NULL or eliminated in compile-time with RKH_CFG_SMA_INIT_EVT_EN = 0. |
#define RKH_SM_GET_CONST | ( | sm | ) | ((RKH_SM_T *)sm)->romrkh |
#define RKH_SM_GET_CONST_OBJ | ( | sm | ) | &RKH_SM_CONST_NAME(sm) |
Declare an opaque pointer pointing to a previously created state machine.
[in] | sm | Name of state machine. |
#define RKH_SM_DEF_PTR_TYPE | ( | type, | |
sm | |||
) | type *const sm = (type *)&RKH_SM_NAME(sm) |
Declare a pointer of specified type pointing to a previously created state machine.
The pointer could be used to hide (opaque) or to publish the internals of the class of the state machine.
[in] | type | Data type of the state machine. Could be derived from RKH_SM_T. |
[in] | sm | Name of state machine. |
#define RKH_GET_CSTATE_ID | ( | me | ) | ((RKH_BASE_T *)(((RKH_SM_T *)me)->state))->id |
#define RKH_GET_VERTEX_NAME | ( | vx | ) | ((struct RKH_BASE_T *)(vx))->name |
typedef void(* RKH_ENT_ACT_T) (const RKH_SM_T *me) |
Entry action.
The actions that are always executed when a state is entered should be specified as entry actions. UML statecharts provide optional entry and exit actions, which are associated with states rather than transitions, as in a Moore automaton. An entry function takes the state machine pointer as argument. This argument is optional, thus it could be eliminated in compile-time by means of RKH_CFG_SMA_ENT_ARG_SMA_EN.
The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. Specifically, the implemented transition sequence is as follows:
typedef void(* RKH_EXT_ACT_T) (const RKH_SM_T *me) |
Exit action.
The actions that are always execute when a state is exited should be exit actions. UML statecharts provide optional entry and exit actions, which are associated with states rather than transitions, as in a Moore automaton. An exit function takes the state machine pointer as argument. This argument is optional, thus it could be eliminated in compile-time by means of RKH_CFG_SMA_EXT_ARG_SMA_EN.
The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. Specifically, the implemented transition sequence is as follows:
Event preprocessor.
Before sending the arrived event to state machine, it can be previously processed using the event preprocessor function. The RKH framework provides optional event preprocessor action, which are associated with states rather than transitions, as in a Moore automaton. This action takes the state machine pointer and the event pointer as arguments. This argument is optional, thus it could be eliminated in compile-time by means of RKH_CFG_SMA_PPRO_ARG_SMA_EN.
Transition action.
Transition actions are small atomic behaviors executed at specified points in a state machine. This actions are assumed to take an insignificant amount of time to execute and are noninterruptible. UML statecharts are extended state machines with characteristics of both Mealy and Moore automata. In statecharts, actions generally depend on both the state of the system and the triggering event, as in a Mealy automaton. Additionally, UML statecharts provide optional entry and exit actions, which are associated with states rather than transitions, as in a Moore automaton. An action function takes the state machine pointer and the event pointer as arguments. These arguments are optional, thus they could be eliminated in compile-time by means of RKH_CFG_SMA_ACT_ARG_EVT_EN and RKH_CFG_SMA_ACT_ARG_SMA_EN.
The RKH implementation preserves the transition sequence imposed by Harel's Statechart and UML. Specifically, the implemented transition sequence is as follows:
Guard.
A guard is a boolean condition that returns a true (RKH_GTRUE) or false (RKH_GFALSE) value that controls whether or not a transition is taken following the receipt of a triggering event. A transition with a guard is only take if the triggering event occurs and the guard evaluates to true. As long as the guard evaluated to false, the triggering event would be discarded and the transition would not be taken. Each condition connector can have one special branch with a guard labeled rkh_sm_else, which is taken if all the guards on the other branches are false. A guard function takes the state machine pointer and the event pointer as arguments. These arguments are optional, thus they could be eliminated in compile-time by means of RKH_CFG_SMA_GRD_ARG_EVT_EN and RKH_CFG_SMA_GRD_ARG_SMA_EN.