RKH
"my.c"
/* -------------------------- Development history -------------------------- */
/*
* 2016.12.06 LeFr v2.4.05 Initial version
*/
/* -------------------------------- Authors -------------------------------- */
/*
* LeFr Leandro Francucci lf@vortexmakes.com
*/
/* --------------------------------- Notes --------------------------------- */
/* ----------------------------- Include files ----------------------------- */
#include "rkh.h"
#include "my.h"
/* ----------------------------- Local macros ------------------------------ */
/* ......................... Declares active object ........................ */
typedef struct MySm MySm;
/* ................... Declares states and pseudostates .................... */
RKH_DCLR_BASIC_STATE S2,S31,S32,S111,S112,S12;
/* ........................ Declares initial action ........................ */
void my_init(const RKH_SMA_T *me, RKH_EVT_T *pe);
/* ........................ Declares effect actions ........................ */
void set_x1(const RKH_SMA_T *me, RKH_EVT_T *pe);
void set_y_2(const RKH_SMA_T *me, RKH_EVT_T *pe);
void set_y_1(const RKH_SMA_T *me, RKH_EVT_T *pe);
void dummy_act(const RKH_SMA_T *me, RKH_EVT_T *pe);
void show_data(const RKH_SMA_T *me, RKH_EVT_T *pe);
void terminate(const RKH_SMA_T *me, RKH_EVT_T *pe);
/* ......................... Declares entry actions ........................ */
void set_x_1(const RKH_SMA_T *me);
void set_x_2(const RKH_SMA_T *me);
void set_x_3(const RKH_SMA_T *me);
void set_y_0(const RKH_SMA_T *me);
/* ......................... Declares exit actions ......................... */
void dummy_exit(const RKH_SMA_T *me);
/* ............................ Declares guards ............................ */
rbool_t y_0(const RKH_SMA_T *me, RKH_EVT_T *pe);
rbool_t y_1(const RKH_SMA_T *me, RKH_EVT_T *pe);
rbool_t y_2(const RKH_SMA_T *me, RKH_EVT_T *pe);
rbool_t x1(const RKH_SMA_T *me, RKH_EVT_T *pe);
rbool_t x2_or_x3(const RKH_SMA_T *me, RKH_EVT_T *pe);
/* ........................ States and pseudostates ........................ */
RKH_CREATE_BASIC_STATE(S2, NULL, NULL, RKH_ROOT, NULL);
RKH_TRINT(FOUR, NULL, dummy_act),
RKH_TRINT(SIX, NULL, show_data),
RKH_TRINT(TERM, NULL, terminate),
RKH_TRREG(ONE, x1, dummy_act, &S1),
RKH_TRREG(TWO, NULL, NULL, &S2),
RKH_TRREG(THREE, NULL, dummy_act, &C2),
RKH_CREATE_COMP_STATE(S1, set_y_0, dummy_exit, RKH_ROOT, &S11, &DH);
RKH_TRINT(SIX, NULL, show_data),
RKH_TRINT(TERM, NULL, terminate),
RKH_TRREG(TWO, NULL, set_y_2, &S2),
RKH_TRREG(THREE, NULL, NULL, &S3),
RKH_TRREG(FIVE, NULL, NULL, &S12),
RKH_CREATE_BASIC_STATE(S12, set_x_3, NULL, &S1, NULL);
RKH_TRREG(FOUR, NULL, set_y_1, &S2),
RKH_CREATE_COMP_STATE(S11, NULL, NULL, &S1, &S111, &H);
RKH_TRREG(TWO, NULL, NULL, &S112),
RKH_TRREG(FOUR, NULL, NULL, &S12),
RKH_CREATE_BASIC_STATE(S111, set_x_1, NULL, &S11, NULL);
RKH_TRREG(ONE, NULL, NULL, &S112),
RKH_CREATE_BASIC_STATE(S112, set_x_2, NULL, &S11, NULL);
RKH_TRREG(ONE, NULL, NULL, &S111),
RKH_TRREG(TWO, NULL, NULL, &S11),
RKH_TRREG(THREE, NULL, set_x1, &CH),
RKH_CREATE_SHALLOW_HISTORY_STATE(H, &S11, NULL, NULL, NULL);
RKH_CREATE_DEEP_HISTORY_STATE(DH, &S1, NULL, NULL, NULL);
RKH_CREATE_COMP_STATE(S3, NULL, NULL, RKH_ROOT, &S31, NULL);
RKH_TRINT(SIX, NULL, show_data),
RKH_TRINT(TERM, NULL, terminate),
RKH_TRREG(TWO, NULL, NULL, &C1),
RKH_TRREG(THREE, NULL, NULL, &S3),
RKH_CREATE_BASIC_STATE(S31, NULL, NULL, &S3, NULL);
RKH_TRREG(ONE, NULL, NULL, &S32),
RKH_CREATE_BASIC_STATE(S32, NULL, NULL, &S3, NULL);
RKH_TRREG(ONE, NULL, NULL, &S31),
RKH_TRREG(THREE, NULL, NULL, &S2),
RKH_BRANCH(x1, dummy_act, &S3),
RKH_BRANCH(ELSE, dummy_act, &S32),
RKH_BRANCH(y_1, NULL, &H),
RKH_BRANCH(y_2, dummy_act, &DH),
RKH_BRANCH(y_0, NULL, &S1),
RKH_BRANCH(x1, dummy_act, &S3),
RKH_BRANCH(x2_or_x3, dummy_act, &CH),
RKH_BRANCH(ELSE, NULL, &S2),
/* ............................. Active object ............................. */
struct MySm
{
RKH_SMA_T sma; /* base structure */
rui8_t x; /* private member */
rui8_t y; /* private member */
}; /* SMA derived from RKH_SMA_T structure */
RKH_SMA_CREATE(MySm, my, 0, HCAL, &S1, my_init, NULL);
/* ------------------------------- Constants ------------------------------- */
/* ---------------------------- Local data types --------------------------- */
/* ---------------------------- Global variables --------------------------- */
/* ---------------------------- Local variables ---------------------------- */
/* ----------------------- Local function prototypes ----------------------- */
/* ---------------------------- Local functions ---------------------------- */
/* ............................ Initial action ............................. */
void
my_init(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
MySm *realMe = ((MySm *)(me));
RKH_TR_FWK_OBJ(&my->equeue);
realMe->x = realMe->y = 0;
}
/* ............................ Effect actions ............................. */
void
set_x1(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
((MySm *)(me))->x = 1;
}
void
set_y_2(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
((MySm *)(me))->y = 2;
}
void
set_y_1(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
((MySm *)(me))->y = 1;
}
void
dummy_act(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)me;
(void)pe;
}
void
show_data(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)me;
(void)pe;
}
void
terminate(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)me;
(void)pe;
}
/* ............................. Entry actions ............................. */
void
set_x_1(const RKH_SMA_T *me)
{
((MySm *)(me))->x = 1;
}
void
set_x_2(const RKH_SMA_T *me)
{
((MySm *)(me))->x = 2;
}
void
set_x_3(const RKH_SMA_T *me)
{
((MySm *)(me))->x = 3;
}
void
set_y_0(const RKH_SMA_T *me)
{
((MySm *)(me))->y = 0;
}
/* ............................. Exit actions .............................. */
void
dummy_exit(const RKH_SMA_T *me)
{
(void)me;
}
/* ................................ Guards ................................. */
rbool_t
y_0(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
return ((MySm *)(me))->y == 0 ? RKH_GTRUE : RKH_GFALSE;
}
rbool_t
y_1(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
return ((MySm *)(me))->y == 1 ? RKH_GTRUE : RKH_GFALSE;
}
rbool_t
y_2(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
return ((MySm *)(me))->y == 2 ? RKH_GTRUE : RKH_GFALSE;
}
rbool_t
x1(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
return ((MySm *)(me))->x == 1 ? RKH_GTRUE : RKH_GFALSE;
}
rbool_t
x2_or_x3(const RKH_SMA_T *me, RKH_EVT_T *pe)
{
(void)pe;
return (((MySm *)(me))->x == 2 || ((MySm *)(me))->x == 3) ?
}
/* ---------------------------- Global functions --------------------------- */
/* ------------------------------ End of file ------------------------------ */
void rkh_fwk_exit(void)
Exit the RKH framework.
#define RKH_CREATE_COMP_STATE(name, en, ex, parent, defchild, history)
This macro creates a composite state.
Definition: rkhsm.h:191
#define RKH_CREATE_BASIC_STATE(name, en, ex, parent, prepro)
This macro creates a basic state.
Definition: rkhsm.h:277
#define RKH_CREATE_COND_STATE(name)
This macro creates a conditional pseudostate (a.k.a. junction).
Definition: rkhsm.h:313
#define RKH_CREATE_BRANCH_TABLE(name)
Definition: rkhsm.h:920
#define RKH_CREATE_DEEP_HISTORY_STATE(name, parent, dftTrnGuard, dftTrnAction, dftTarget)
Definition: rkhsm.h:393
#define RKH_CREATE_SHALLOW_HISTORY_STATE(name, parent, dftTrnGuard, dftTrnAction, dftTarget)
Definition: rkhsm.h:436
#define RKH_CREATE_CHOICE_STATE(name)
This macro creates a choice pseudostate.
Definition: rkhsm.h:349
#define RKH_CREATE_TRANS_TABLE(name)
This macro creates a state transition table.
Definition: rkhsm.h:777
@ HCAL
Definition: rkhsm.h:1611
#define RKH_TR_FWK_OBJ(obj_)
Entry symbol table for memory object.
#define RKH_TR_FWK_SIG(stateObj_)
Entry symbol table for event signal.
RKH framwwork platform - independent interface.
#define RKH_DCLR_DHIST_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1090
#define RKH_DCLR_CHOICE_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1089
#define ELSE
Each condition connector can have one special branch with a guard labeled ELSE, which is taken if all...
Definition: rkhsm.h:81
#define RKH_END_TRANS_TABLE
This macro is used to terminate a state transition table. This table have the general structure shown...
Definition: rkhsm.h:894
#define RKH_END_BRANCH_TABLE
This macro is used to terminate a state transition table. This table have the general structure shown...
Definition: rkhsm.h:1013
#define RKH_DCLR_BASIC_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1086
#define RKH_TRREG(evt_, guard_, effect_, target_)
This macro defines a regular state transition.
Definition: rkhsm.h:811
#define RKH_BRANCH(guard_, effect_, target_)
This macro defines a branch in the branch table.
Definition: rkhsm.h:956
#define RKH_GFALSE
This values are retrived by guard functions.
Definition: rkhsm.h:1317
#define RKH_GTRUE
Definition: rkhsm.h:1318
#define RKH_DCLR_SHIST_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1091
#define RKH_DCLR_COMP_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1085
#define RKH_TRINT(e, g, a)
This macro defines an internal state transition. Internal transitions are simple reactions to events ...
Definition: rkhsm.h:835
#define RKH_DCLR_COND_STATE
Declares a previously created state/pseudostate to be used as a global object.
Definition: rkhsm.h:1088
#define RKH_ROOT
This macro indicates the root state of a state machine.
Definition: rkhsm.h:1019
#define RKH_SMA_DEF_PTR(me_)
Declare a opaque pointer pointing to an previously created active object.
Definition: rkhsma.h:390
#define RKH_SMA_CREATE(type, name, prio, ppty, initialState, initialAction, initialEvt)
Declare and allocate a SMA (active object) derived from RKH_SMA_T. Also, initializes and assigns a st...
Definition: rkhsma.h:348
Represents events without parameters.
Definition: rkhevt.h:170
Describes the SMA (active object in UML).
Definition: rkhsma.h:772