RKH
|
Prev: Home
Next: Installation
The main objective of this section is to show and also illustrate the most important concepts to apply when dealing with RKH and the event-driven applications.
This section includes:
Prev: Quick reference
A state machine application is defined with the RKH_SMA_CREATE() macro and declared with the RKH_SMA_DCLR() macro. Frequently, each state machine is encapsulated inside a dedicated source file (.c file), from which the RKH_SMA_CREATE() macro is used, thus the structure definition is in fact entirely encapsulated in its module and is inaccessible to the rest of the application. However, as a general rule, the state machine application must be declared inside a header file (.h file) by means of RKH_SMA_DCLR() macro. We will develop one example of state machine creation to illustrate the use of this macro. Also, we will give our hierarchical state machine the name my
. If you wanted to create a "flat" state machine, you would use the FLAT parameter rather than the HCAL parameter.
This section includes:
Explanation
my
state machine application structure. Almost every state machine applications must also store other "extended-state" information. You supply this additional information by means of data members enlisted after the base structure member sm
. This illustrates how to derive an state machine application from RKH_SMA_T. Please note that the RKH_SMA_T member sm
is defined as the FIRST member of the derived struct. RKH_SMA_T is not intended to be instantiated directly, but rather serves as the base structure for derivation of state machines in the application code. turnon
with TURNON
my
state machine application structure. my
is the state machine application. Represents the top state of state diagram. 2
is the state machine application priority. my
state machine is defined as a hierarchical state machine. The available property options are enumerated in RKH_HPPTY_T enumeration in the rkh.h
file. S1
is the initial state. my_init()
function defines the topmost initial transition in the my
state machine. The function prototype is defined as RKH_TRN_ACT_T. This argument is (optional), thus it could be declared as NULL. The application code must trigger the initial transition explicitly by invoking rkh_sma_activate() function. turnon
is a 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.Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_INIT_EVT_EN. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
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 (composite and basic) are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_COMP_STATE() macro is used. We will develop one example of composite state definition to illustrate the use of this macro. We will give our composite state the name S1
.
This section includes:
Explanation
S1
is the state name. Represents a composite state structure. turn_on()
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. turn_off()
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. SA
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. 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. H
is the 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().Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
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 (composite and basic) are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_BASIC_STATE() macro is used. We will develop one example of basic state definition to illustrate the use of this macro. We will give our basic state the name S11
. As will demostrates the use of RKH_CREATE_BASIC_STATE() macro and its arguments is very similar to RKH_CREATE_COMP_STATE() macro.
Defining a basic state
Declaring a basic state
Explanation
S11
is the state name. Represents a substate structure. start_process()
defines the entry action to be executed unconditionally upon the entry to the S11
state. This argument is optional, thus it could be declared as NULL. The RKH_ENT_ACT_T defines the function prototype. stop_process()
defines the exit action, which is executed upon exit from the S11
state. This argument is optional, thus it could be declared as NULL. The RKH_EXT_ACT_T defines the function prototype. S1
is the parent state of S11
. 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. in_keyb()
defines the event preprocessor action. 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_EN_PPRO_HSM_ARG macro. Example: Customization
Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_PPRO_EN. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
A submachine state is a kind of a state that actually refers to another defined state machine. The diagram in following figure shows a fragment from a state machine diagram in which a submachine state (the SB
) is referenced.
In the above example, the transition triggered by event TWO
will terminate on entry point ENS12
of the SB
state machine. The ONE
transition implies taking of the default transition of the SB
and executes the act5()
action. The transition emanating from the EX1S12
exit point of the submachine will execute the act1()
behavior in addition to what is executed within the SB
state machine. Idem transition emanating from the EX2S12
. This transition must have been triggered within the SB
state machine. Finally, the transition emanating from the edge of the submachine state is triggered by event THREE
.
The following figure is an example of a state machine SB
defined with two exit points, EXPNT1
and EXPNT2
, and one entry point ENPNT
.
In the following figure the state machine shown above is referenced twice in a submachine state S12
and S2
.
This section includes:
A submachine state is defined with the RKH_CREATE_SUBMACHINE_STATE() macro and declared with the RKH_DCLR_SUBM_STATE macro. Frequently, each state machine and its states (composites, basic, and submachine states) are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_SUBMACHINE_STATE() macro is used. We will develop one example of submachine state definition to illustrate the usage and its related macros. We will give our submachine state the name S12
.
Explanation
S12
is the state name. Represents a submachine state structure. S1
is the parent state of S12
. 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. SB
is the defined submachine state machine, which is referenced by S12
submachine state.On the other hand, in RKH every submachine state is associated with a transition table, which is composed of a well-defined set of transitions. See Defining a state transition table for defining a state transition table.
Connection point references are sources/targets of transitions implying exits out of/entries into the submachine state machine referenced by a submachine state. In RKH every submachine state is associated with a exit point connection point reference table, which is composed of a well-defined set of exit point connection references. Thus, in RKH each row in a exit point table references an exit point pseudostate as defined in the submachine of the submachine state that has the exit point connection point defined. Note that each row number matches with the index number of the exit point pseudostate that it represent.
Explanation
S12's
exit point connection reference table. Each exit point connection reference table always begins with the macro RKH_CREATE_EX_CNNPNT_TABLE() and ends with the macro RKH_END_EX_CNNPNT_TABLE. As noted above, sandwiched between these macros are the exit point macros, RKH_EX_CNNPNT().EX1S12
, where EXPNT1
is the referenced exit point pseudostate, act1()
is the transition action function to be taken, and S13
is the transition target state. The place in the table matches with the EXPNT1's
index field.Connection point references are sources/targets of transitions implying exits out of/entries into the submachine state machine referenced by a submachine state.
A entry point connection reference is defined with the RKH_EN_CNNPNT() macro and declared with the RKH_DCLR_ENPNT macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_EN_CNNPNT() macro is used. We will develop one example of entry point connection definition to illustrate the use of this macro. We will give our entry connection the name ENS12
.
Explanation
ENS12
, where ENPNT
is the referenced entry point pseudostate, and S12
is the transition target state.A submachine is defined with the RKH_CREATE_REF_SUBMACHINE() macro and declared with the RKH_DCLR_REF_SUBM macro. Frequently, each state machine and its states (composites, basic, and submachine states) are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_REF_SUBMACHINE() macro is used. We will develop one example of submachine definition to illustrate the usage and its related macros. We will give our submachine the name SB
.
Explanation
SB
is the submachine name. Represents a submachine structure. SB1
is the default state of SB
submachine. At each level of nesting, a submachine can have a private initial transition that designates the active substate after the submachine is entered directly. Here the initial transition of state SB
designates the state SB1
as the initial active substate. A exit point pseudostate is defined with the RKH_CREATE_REF_EXPNT() macro and declared with the RKH_DCLR_REF_EXPNT macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_REF_EXPNT() macro is used. We will develop one example of exit point definition to illustrate the use of this macro. We will give our exit points the name EXPNT1
and EXPNT2
.
Explanation
EXPNT1
, where 0
is the index of the exit point connection table, and SB
is the containing submachine. See Declaring entry connection references for referencing a submachine exit point from a submachine state.A entry point pseudostate is defined with the RKH_CREATE_REF_ENPNT() macro and declared with the RKH_DCLR_REF_ENPNT macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_REF_ENPNT() macro is used. We will develop one example of entry point definition to illustrate the use of this macro. We will give our entry point the name ENPNT
.
Explanation
ENPNT
, where activate()
is the transition action to be taken, SB1
is the transition target state, and SB
is the containing submachine.Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN, RKH_CFG_SMA_PSEUDOSTATE_EN, and RKH_CFG_SMA_SUBMACHINE_EN. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
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 Transition table figure shows a demostrative example of that.
data
==
SYNC
expression guards the transition from being taken unless it is true. The store_data()
function is the action to be taken. Note that in RKH the guard condition is evaluated invoking to a function.Now, is time to represent IN_DATA's transition table by means of RKH framework:
Explanation
IN_DATA's
transition table. 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.RCV_DATA
is the triggering event, is_sync
is the guard function, and store_data()
is the action function to be taken.TOUT0
is the triggering event, drop_frame()
is the action function to be taken, and WAIT_SYNC
is the target state. Note that it is not guarded.As said above, the actions and guards in RKH framework are represented by functions. Thus, is_sync()
could be declared as:
Prev: Quick reference
Prev: Quick reference
A conditional pseudostate (also called juncton pseudostate) is defined with the RKH_CREATE_COND_STATE() macro and declared with the RKH_DCLR_COND_STATE macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_COND_STATE() macro is used. We will develop one example of conditional pseudostate (aka junction pseudostate) definition to illustrate the use of this macro. We will give our junction pseudostate the name C1
. As will demostrates the use of RKH_CREATE_COND_STATE() macro and its arguments is very similar to RKH_CREATE_BASIC_STATE() macro.
Defining a conditional pseudostate
Declaring a conditional pseudostate
Explanation
C1
is the pseudostate name. Represents a conditional pseudostate structure.Customization
Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN, RKH_CFG_SMA_PSEUDOSTATE_EN, RKH_CFG_SMA_CONDITIONAL_EN, RKH_SMA_MAX_TR_SEGS. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
A condition connector has one incoming transition and can have several outgoing transition segments called branches. Branches are labeled with guards that determine which one is to be actually taken. Since the condition connector is an OR connector, only one of the branches can 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. Branches cannot contain triggers, but in addition to a guard they may contain actions. A branch can enter another condition connector, thus providing for the nesting of branches. In RKH branches are defined by the macro RKH_BRANCH(). 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. Example:
Explanation
C1's
branch table. Each table type always begins with the macro RKH_CREATE_BRANCH_TABLE() and ends with the macro RKH_END_BRANCH_TABLE(). As noted above, sandwiched between these macros are the segment macros that actually comprise the condition connector.power_ok()
is the guard function, enable_process
is the action function to be taken, and S22 is the target state.abort()
function will be invoked, and S4
will be the next state.As said above, the actions and guards in RKH framework are represented by functions.
Prev: Quick reference
Prev: Quick reference
A shallow history pseudostate is defined with the RKH_CREATE_SHALLOW_HISTORY_STATE() macro and declared with the RKH_DCLR_SHIST_STATE macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_SHALLOW_HISTORY_STATE() macro is used. We will develop one example of shallow history pseudostate definition to illustrate the use of this macro. We will give our history pseudostate the name H1
. As will demostrates the use of RKH_CREATE_SHALLOW_HISTORY_STATE() macro and its arguments is very similar to RKH_CREATE_COND_STATE() macro.
Defining a shallow history pseudostate
Declaring a shallow history pseudostate
Explanation
H1
is the pseudostate name. Represents a shallow history pseudostate structure. 6
is the value of pseudostate ID. S1
is the parent state of H1
.Customization
Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file. Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN, RKH_CFG_SMA_PSEUDOSTATE_EN, RKH_SMA_MAX_TR_SEGS, RKH_EN_SHALLOW_HISTORY. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
A deep history pseudostate is defined with the RKH_CREATE_DEEP_HISTORY_STATE() macro and declared with the RKH_DCLR_DHIST_STATE macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_DEEP_HISTORY_STATE() macro is used. We will develop one example of deep history pseudostate definition to illustrate the use of this macro. We will give our history pseudostate the name H2
. As will demostrates the use of RKH_CREATE_DEEP_HISTORY_STATE() macro and its arguments is very similar to RKH_CREATE_SHALLOW_HISTORY_STATE() macro.
Defining a deep history pseudostate
Declaring a shallow history pseudostate
Explanation
H2
is the pseudostate name. Represents a deep history pseudostate structure. S21
is the parent state of H2
.Customization
Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file. Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN, RKH_CFG_SMA_PSEUDOSTATE_EN, RKH_SMA_MAX_TR_SEGS, RKH_EN_DEEP_HISTORY. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
A choice pseudostate is defined with the RKH_CREATE_CHOICE_STATE() macro and declared with the RKH_DCLR_CHOICE_STATE macro. Frequently, each state machine and its states and pseudostates are encapsulated inside a dedicated source file (.c file), from which the RKH_CREATE_CHOICE_STATE() macro is used. We will develop one example of choice pseudostate definition to illustrate the use of this macro. We will give our choice pseudostate the name CH
. As will demostrates the use of RKH_CREATE_CHOICE_STATE() macro and its arguments is very similar to RKH_CREATE_COND_STATE() macro.
Defining a choice pseudostate
Declaring a choice pseudostate
Explanation
CH
is the pseudostate name. Represents a choice pseudostate structure.Customization
Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file.
Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_SMA_HCAL_EN, RKH_CFG_SMA_PSEUDOSTATE_EN, RKH_CFG_SMA_CHOICE_EN, RKH_SMA_MAX_TR_SEGS. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
This section summarize the functions and its prototypes used by RKH framework. As mentioned before, the framework make use the callbacks, i.e. pointer to functions, in most of its data structures by means of RKH_SMA_CREATE(), RKH_CREATE_COMP_STATE(), RKH_CREATE_BASIC_STATE(), RKH_TRINT(), RKH_TRREG(), RKH_BRANCH(), RKH_CREATE_SHALLOW_HISTORY_STATE(), RKH_CREATE_DEEP_HISTORY_STATE(), and RKH_CREATE_CHOICE_STATE() macros. Obviously, the set of available functions and its configurations is mandatory to known for properly using the framework.
Initialization 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:
As said above, the application must explicitly trigger initial transitions in all state machines. The following listing shows the use of rkh_sma_activate() function, when it's is called the initial action is invoked and the state machine start. The rkh_sma_activate() is a platform-dependent function. All RKH ports must be defined in the RKH port file to a particular platform. However, only the ports to the external OS/RTOS usually need some code to bolt the framework to the external OS/RTOS.
The next listing shows an example of the initial action implementation.
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:
The next listing shows an example of the exit action implementation.
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:
The next listing shows an example of the entry action implementation.
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:
The next listing shows an example of the transition action implementation.
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.
The next listing shows an example of the event preprocessor action implementation.
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.
The next listing shows an example of the guard function implementation.
Prev: Quick reference
Prev: Quick reference
An event can have associated parameters, allowing the event instance to convey not only the occurrence of some interesting incident but also quantitative information regarding that occurrence. Implementing the single inheritance in C is very simply by literally embedding the base structure, RKH_EVT_T in this case, as the first member of the derived structure. For example, the structure MYEVT_T derived from the base structure RKH_EVT_T by embedding the RKH_EVT_T instance as the first member of MYEVT_T. See also, Using dynamic and static events section for more information.
Such nesting of structures always aligns the data member 'evt' at the beginning of every instance of the derived structure. In particular, this alignment lets you treat a pointer to the derived MYEVT_T structure as a pointer to the RKH_EVT_T base structure. Consequently, you can always safely pass a pointer to MYEVT_T to any C function that expects a pointer to RKH_EVT_T. (To be strictly correct in C, you should explicitly cast this pointer. In OOP such casting is called upcasting and is always safe.) Therefore, all functions designed for the RKH_EVT_T structure are automatically available to the MYEVT_T structure as well as other structures derived from RKH_EVT_T.
The RKH takes the 'e' member of RKH_EVT_T structure for triggering a state transition.
See also rkh_sma_put_fifo(), rkh_sma_put_lifo(), RKH_ALLOC_EVT(), RKH_SET_STATIC_EVENT(), and RKH_FWK_GC().
Prev: Quick reference
Prev: Quick reference
In RKH as other frameworks, the actual event instances are either constant events (or static events) statically allocated at compile time or dynamic events allocated at runtime from one of the event pools that the framework manages.
This section includes:
Before using dynamic events (or event with arguments) the application code must register the proper event pools, which stores the events as a fixed-sized memory block. Each event pool must be registered with the RKH framework, by means of the rkh_fwk_epool_register() function. This function initializes one event pool at a time and must be called exactly once for each event pool before the pool can be used.
The application code might initialize the event pools by making calls to the rkh_fwk_epool_register() function. However, for the simplicity of the internal implementation, the application code initialize event pools in the ascending order of the event size.
Explanation
DIAL_T
and SETUP_T
. OFFHOOK
event never changes, so it can be statically allocated just once. This event is declared as const, which means that it can be placed in ROM. The initializer list for this event consists of the signal OFFHOOK
followed by zero. This zero informs the RKH framework that this event is static and should never be recycled to an event pool. TIMEOUT( timerno )
event is an example of an event with changing parameters. In general, such an event cannot be allocated in ROM like the OFFHOOK
event because it can change. TIMEOUT( timerno )
with TIMEOUT
signal and establishes it as one static event. DIAL_T
and SETUP_T
with DIALED
and SET_CONFIG
signals. These events are represented like this: DIALED( dial, qty )
and SET_CONFIG( volume, baud_rate, name, iloop )
This macro returns a pointer to the event already cast to the required event type. volume
, baud_rate
, and iloop
parameters of the event are assigned.Just one another example that it could be used to easily debug an application with static events.
The RKH framework supports one type of asynchronous event exchange: the simple mechanism of direct event posting supported through the functions rkh_sma_post_fifo() and rkh_sma_post_lifo(), when the producer of an event directly posts the event to the event queue of the consumer SMA (active object).
eterm
event is sent directly to the manager
SMA.mye
of type MYEVT_T with the signal returned from the kbmap() function. mye
. mye
event is sent directly to the my
SMA.If the system make use of dynamic events facility after the processing, you must not forget to call the RKH garbage collector, because now RKH is no longer in charge of event processing and you are solely responsible for not leaking the event. The garbage collector actually recycles the event only when it determines that the event is no longer referenced. The following listing illustrates how and when to invoke RKH_FWK_GC() macro to recycle "dynamic" events.
e
is get from the SMA queue with the highest priority. e
is dispatched to the current SMA. e
is passed to the RKH garbage collector for recycling. As described above, the RKH_FWK_GC() macro actually recycles the wvent only when it determines that the event is no longer referenced.Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file. Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_FWK_DYN_EVT_EN, RKH_CFG_FWK_MAX_EVT_POOL, RKH_CFG_FWK_SIZEOF_EVT, RKH_CFG_FWK_SIZEOF_EVT_SIZE, RKH_CFGPORT_NATIVE_DYN_EVT_EN, RKH_DYNE_TYPE, RKH_DYNE_INIT, RKH_DYNE_GET_ESIZE, RKH_DYNE_GET, RKH_DYNE_PUT, RKH_DYNE_GET_NFREE, RKH_DYNE_GET_NMIN, RKH_DYNE_GET_PSIZE. See Configuration section for more information.
Prev: Quick reference
Prev: Quick reference
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.
The next listing shows an example of the event preprocessor action implementation.
Prev: Quick reference
Prev: Quick reference
Event deferral comes in very handy when an event arrives in a particularly inconvenient moment but can be deferred for some later time, when the system is in a much better position to handle the event. RKH supports very efficient event deferring and recalling mechanisms. This function is part of the event deferral mechanism. An SMA uses this function to defer an event e to the event queue q. RKH correctly accounts for another outstanding reference to the event and will not recycle the event at the end of the RTC step. Later, the SMA might recall one event at a time from the event queue by means of rkh_sma_recall(sma,q) function. Recalling an event means that it is removed from the deferred event queue q
and posted (LIFO) to the event queue of the sma
state machine application.
This section includes:
Explanation
qurc
queue to be used as deferred queue. pe
to the previously created event queue qurc
.Explanation
qurc
and posts (LIFO) to the event queue of the sma
state machine application.
Prev: Quick reference
Prev: Quick reference
The assertions (RKH_ASSERT()
macro) are used to check expressions that ought to be true as long as the program is running correctly. It is a convenient way to insert sanity checks.
A number of philosophies can be employed when deciding where to use an RKH_ASSERT()
macro. Broadly speaking, the assertions only serve the purposes of catching bugs and helping documentation. Helping to document the code means that the statements inside the assertion tell the reader something he might not already know.
Prev: Quick reference
Prev: Quick reference
Please refer to Tracing tool section.
Prev: Quick reference
Prev: Quick reference
The following listing shows an very simple example of the main() function implementation and demostrates how to use the RKH API.
my
state machine. RKH invokes the defined init action. term
event to my
state machine to terminate. After that, terminates the program. MYEVT_T
type (derived from RKH_EVT_T) to store the key pressed. mye
event is dispatched to my
state machine. Events with parameters, such as the MYEVT_T, require explicit casting from the generic base structure RKH_EVT_T to the specific derived structure MYEVT_T.
Prev: Quick reference
This section includes:
Explanation
tmSync
time event. tmSync
like a static time event with signal Sync
. It should be used like a transition's trigger to support the UML's time event 'after
SYNC_TIME'
: tmSync
timer as oneshot. When it expires the me
active object will receive an event with Sync
signal. The tmSync
will expire after SYNC_TIME
ticks.Explanation
tPwrOff
, and tKey
event timers. tPwrOff
event timer as oneshot timer, which posts the evPwrOff
signal to PowerMonitor
active object after TPWROFF_TIME
ticks. tKey
event timer as periodic timer, which posts the evKey
signal to PowerMonitor
active object after TKEYSTART_TIME
ticks initially and then after every TKEY_TIME
ticks. Each RKH application must have its own configuration file, called rkhcfg.h
. This file adapts and configures RKH by means of compiler definitions and macros allowing to restrict the resources consumed by RKH. Adjusting this definitions allows to reduce the ROM and RAM consumption, and to enhance the system performance in a substantial manner. The rkhcfg.h
shows the general layout of the configuration file. Use the following macros to reduce the memory taken by state machine structure: RKH_CFG_TMR_EN, RKH_CFG_TMR_SIZEOF_NTIMER, RKH_CFG_TMR_HOOK_EN, RKH_CFG_TMR_GET_INFO_EN. See Configuration section for more information.
Prev: Home