RKH
rkhsm.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH site: http://vortexmakes.com/que-es/
28  * RKH GitHub: https://github.com/vortexmakes/RKH
29  * RKH Sourceforge: https://sourceforge.net/projects/rkh-reactivesys/
30  * e-mail: lf@vortexmakes.com
31  * ---------------------------------------------------------------------------
32  */
33 
42 /* -------------------------- Development history -------------------------- */
43 /*
44  * 2017.04.14 LeFr v2.4.05 Initial version
45  */
46 
47 /* -------------------------------- Authors -------------------------------- */
48 /*
49  * LeFr Leandro Francucci lf@vortexmakes.com
50  */
51 
52 /* --------------------------------- Notes --------------------------------- */
53 /* --------------------------------- Module -------------------------------- */
54 #ifndef __RKHSM_H__
55 #define __RKHSM_H__
56 
57 /* ----------------------------- Include files ----------------------------- */
58 #include "rkhitl.h"
59 
60 /* ---------------------- External C language linkage ---------------------- */
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /* --------------------------------- Macros -------------------------------- */
66 #define RKH_SM_NAME(smName_) s_##smName_
67 #define RKH_SM_CONST_NAME(smName_) rs_##smName_
68 
81 #define ELSE rkh_sm_else
82 
152 #define RKH_CREATE_COMP_REGION_STATE(name, en, ex, parent, defchild, \
153  initialTrn, \
154  kindOfHistory, hDftTrnGuard, \
155  hDftTrnAction, hDftTarget, hRamMem) \
156  \
157  MKFINAL_INCOMP(name); \
158  MKHIST_INCOMP(name, kindOfHistory, hDftTrnGuard, hDftTrnAction, \
159  hDftTarget, hRamMem); \
160  \
161  extern RKHROM RKH_TR_T name##_trtbl[]; \
162  RKHROM RKH_SCMP_T name = \
163  { \
164  {MKBASE(RKH_COMPOSITE, name), MKST(en, ex, parent)}, \
165  MKCOMP(name, defchild, initialTrn, &name##Hist) \
166  }
167 
191 #define RKH_CREATE_COMP_STATE(name, en, ex, parent, defchild, history) \
192  \
193  extern RKHROM RKH_TR_T name##_trtbl[]; \
194  RKHROM RKH_SCMP_T name = \
195  { \
196  {MKBASE(RKH_COMPOSITE, name), MKST(en, ex, parent)}, \
197  MKCOMP(name, defchild, NULL, history) \
198  }
199 
212 #define RKH_CREATE_FINAL_STATE(name, parent) \
213  \
214  static RKHROM RKH_TR_T name##_trtbl[] = \
215  RKH_TRREG(RKH_ANY, NULL, NULL, NULL); \
216  RKHROM RKH_FINAL_T name = \
217  { \
218  {MKBASE(RKH_FINAL, name), MKST(NULL, NULL, parent)}, \
219  MKFINAL(name) \
220  }
221 
277 #define RKH_CREATE_BASIC_STATE(name, en, ex, parent, prepro) \
278  \
279  extern RKHROM RKH_TR_T name##_trtbl[]; \
280  \
281  RKHROM RKH_SBSC_T name = \
282  { \
283  {MKBASE(RKH_BASIC, name), MKST(en,ex,parent)}, \
284  MKBASIC(name,prepro) \
285  }
286 
313 #define RKH_CREATE_COND_STATE(name) \
314  \
315  extern RKHROM RKH_TR_T name##_trtbl[]; \
316  \
317  RKHROM RKH_SCOND_T name = \
318  { \
319  MKBASE(RKH_CONDITIONAL, name), \
320  name##_trtbl \
321  }
322 
349 #define RKH_CREATE_CHOICE_STATE(name) \
350  \
351  extern RKHROM RKH_TR_T name##_trtbl[]; \
352  \
353  RKHROM RKH_SCHOICE_T name = \
354  { \
355  MKBASE(RKH_CHOICE, name), \
356  name##_trtbl \
357  }
358 
393 #define RKH_CREATE_DEEP_HISTORY_STATE(name, parent, dftTrnGuard, \
394  dftTrnAction, dftTarget) \
395  \
396  static RKHROM RKH_ST_T *ram##name; \
397  MKHISTORY(name, parent, RKH_DHISTORY, dftTrnGuard, dftTrnAction, \
398  dftTarget, &ram##name)
399 
436 #define RKH_CREATE_SHALLOW_HISTORY_STATE(name, parent, dftTrnGuard, \
437  dftTrnAction, dftTarget) \
438  \
439  static RKHROM RKH_ST_T *ram##name; \
440  MKHISTORY(name, parent, RKH_SHISTORY, dftTrnGuard, dftTrnAction, \
441  dftTarget, &ram##name)
442 
493 #define RKH_CREATE_SUBMACHINE_STATE(name, en, ex, parent, sbm) \
494  \
495  extern RKHROM RKH_EXPCN_T name##_exptbl[]; \
496  extern RKHROM RKH_TR_T name##_trtbl[]; \
497  \
498  RKHROM RKH_SSBM_T name = \
499  { \
500  {MKBASE(RKH_SUBMACHINE, name), MKST(en,ex,parent)}, \
501  MKSBM(name,sbm) \
502  }
503 
529 #define RKH_CREATE_EX_CNNPNT_TABLE(name) \
530  RKHROM RKH_EXPCN_T name##_exptbl[]= \
531  {
532 
575 #define RKH_EX_CNNPNT(name, expnt, act, ts) \
576  {(RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts}
577 
599 #define RKH_END_EX_CNNPNT_TABLE };
600 
623 #define RKH_EN_CNNPNT(name, enpnt, subm) \
624  \
625  RKHROM RKH_SENP_T name = \
626  { \
627  MKBASE(RKH_ENPOINT, name), \
628  MKENP(enpnt,subm) \
629  }
630 
654 #define RKH_CREATE_REF_SUBMACHINE(name, defchild, iact) \
655  \
656  static RKHROM RKH_ST_T * rdyp_##name; \
657  \
658  RKHROM RKH_RSM_T name = \
659  { \
660  MKBASE(RKH_REF_SUBMACHINE, name), \
661  MKMCH(defchild,iact,name) \
662  }
663 
708 #define RKH_CREATE_REF_EXPNT(name, ix, subm) \
709  \
710  RKHROM RKH_SEXP_T name = \
711  { \
712  MKBASE(RKH_EXPOINT, name), \
713  ix, subm \
714  }
715 
745 #define RKH_CREATE_REF_ENPNT(name, act, ts, subm) \
746  \
747  RKHROM RKH_ENPCN_T name = \
748  { \
749  (RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts \
750  }
751 
777 #define RKH_CREATE_TRANS_TABLE(name) \
778  \
779  RKHROM RKH_TR_T name##_trtbl[]= \
780  {
781 
811 #define RKH_TRREG(evt_, guard_, effect_, target_) \
812  MKTRN(evt_, guard_, effect_, target_)
813 
835 #define RKH_TRINT(e, g, a) {e, (RKH_GUARD_T)g, (RKH_TRN_ACT_T)a, NULL}
836 
870 #define RKH_TRCOMPLETION(guard_, effect_, target_) \
871  {RKH_COMPLETION_EVENT, \
872  (RKH_GUARD_T)guard_, (RKH_TRN_ACT_T)effect_, target_}
873 
894 #define RKH_END_TRANS_TABLE {RKH_ANY, NULL, NULL, NULL}};
895 
920 #define RKH_CREATE_BRANCH_TABLE(name) \
921  \
922  RKH_CREATE_TRANS_TABLE(name)
923 
956 #define RKH_BRANCH(guard_, effect_, target_) \
957  MKTRN(0, guard_, effect_, target_)
958 
972 #define RKH_CREATE_HISTORY_STORAGE(compStateName) \
973  static RKHROM RKH_ST_T *ramHist_##compStateName
974 
986 #define RKH_GET_HISTORY_STORAGE(compStateName) \
987  &ramHist_##compStateName
988 
989 /*
990  * This macro is internal to RKH and the user application should
991  * not call it.
992  */
993 #define RKH_EBTBL {RKH_ANY, NULL, NULL, NULL}
994 
1013 #define RKH_END_BRANCH_TABLE RKH_EBTBL};
1014 
1019 #define RKH_ROOT RKH_NULL
1020 
1048 #define RKH_SM_DCLR(me_) \
1049  RKH_DCLR_PTR_TYPE(RKH_SM_T, me_)
1050 
1073 #define RKH_SM_DCLR_TYPE(type_, me_) \
1074  RKH_DCLR_PTR_TYPE(type_, me_)
1075 
1085 #define RKH_DCLR_COMP_STATE extern RKHROM RKH_SCMP_T
1086 #define RKH_DCLR_BASIC_STATE extern RKHROM RKH_SBSC_T
1087 #define RKH_DCLR_FINAL_STATE extern RKHROM RKH_FINAL_T
1088 #define RKH_DCLR_COND_STATE extern RKHROM RKH_SCOND_T
1089 #define RKH_DCLR_CHOICE_STATE extern RKHROM RKH_SCHOICE_T
1090 #define RKH_DCLR_DHIST_STATE extern RKHROM RKH_SHIST_T
1091 #define RKH_DCLR_SHIST_STATE extern RKHROM RKH_SHIST_T
1092 #define RKH_DCLR_SUBM_STATE extern RKHROM RKH_SSBM_T
1093 #define RKH_DCLR_REF_SUBM extern RKHROM RKH_RSM_T
1094 #define RKH_DCLR_ENPNT extern RKHROM RKH_SENP_T
1095 #define RKH_DCLR_REF_EXPNT extern RKHROM RKH_SEXP_T
1096 #define RKH_DCLR_REF_ENPNT extern RKHROM RKH_ENPCN_T
1105 #define RKH_DECLARE_TR_TBL(name) \
1106  extern RKHROM RKH_TR_T name##_trtbl[]
1107 
1131 #define RKH_DCLR_SM_GLOBAL(sm_t, sm, gob) \
1132  sm_t * const gob = &s_##sm;
1133 
1149 #define RKH_DCLR_SM_CONST_GLOBAL(smName) \
1150  extern RKHROM RKH_ROM_T RKH_SM_CONST_NAME(smName)
1151 
1276 #define RKH_INIT_BASIC_STATE(name, en, ex, parent, prepro) \
1277  { \
1278  { \
1279  MKBASE(RKH_BASIC, name), /* RKH_BASE_T */ \
1280  MKST(en, ex, parent) \
1281  }, /* RKH_ST_T */ \
1282  MKBASIC(name, prepro) \
1283  } /* RKH_SBSC_T */ \
1284 
1285 
1299 #define RKH_INIT_COMPOSITE_STATE(name, en, ex, parent, \
1300  defchild, history) \
1301  { \
1302  { \
1303  MKBASE(RKH_COMPOSITE, name), /* RKH_BASE_T */ \
1304  MKST(en, ex, parent) \
1305  }, /* RKH_ST_T */ \
1306  MKCOMP(name, defchild, history) \
1307  } /* RKH_SCMP_T */ \
1308 
1317 #define RKH_GFALSE RKH_FALSE
1318 #define RKH_GTRUE RKH_TRUE
1352 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1353  #define RKH_SM_CREATE(type, name, prio, ppty, initialState, \
1354  initialAction, initialEvt) \
1355  static RKH_SM_CONST_CREATE(name, prio, ppty, initialState, \
1356  initialAction, initialEvt); \
1357  static type s_##name = {MKSM(&RKH_SM_CONST_NAME(name), initialState)}
1358 #else
1359  #define RKH_SM_CREATE(type, name, prio, ppty, initialState, \
1360  initialAction, initialEvt) \
1361  static type RKH_SMA_NAME(name) = {MKSM(name, prio, ppty, initialState, \
1362  initialAction, initialEvt)}
1363 #endif
1364 
1396 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1397  #define RKH_SM_INIT(me_, nameSMConst_, prio_, ppty_, initialState_, \
1398  initialAction_, initialEvt_) \
1399  ((RKH_SM_T *)me_)->romrkh = \
1400  (RKHROM RKH_ROM_T *)(RKH_SM_GET_CONST_OBJ(nameSMConst_)); \
1401  ((RKH_SM_T *)me_)->state = \
1402  (RKHROM struct RKH_ST_T *) \
1403  ((RKH_SM_GET_CONST_OBJ(nameSMConst_))->istate)
1404 #else
1405  #define RKH_SM_INIT(me_, nameSMConst_, prio_, ppty_, initialState_, \
1406  initialAction_, initialEvt_) \
1407  MKRT_SM(me_, nameSMConst_, prio_, ppty_, initialState_, \
1408  initialAction_, initialEvt_)
1409 #endif
1410 
1441 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1442  #define RKH_SM_CONST_CREATE(name, prio, ppty, initialState, \
1443  initialAction, initialEvt) \
1444  RKHROM RKH_ROM_T RKH_SM_CONST_NAME(name) = \
1445  MKRRKH(name, \
1446  prio, \
1447  ppty, \
1448  initialState, \
1449  initialAction, \
1450  initialEvt)
1451 #else
1452  #define RKH_SM_CONST_CREATE(name, prio, ppty, initialState, \
1453  initialAction, initialEvt)
1454 #endif
1455 
1463 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1464  #define RKH_SM_GET_CONST(sm) \
1465  ((RKH_SM_T *)sm)->romrkh
1466 #else
1467  #define RKH_SM_GET_CONST(sm) \
1468  ((RKH_SM_T *)sm)
1469 #endif
1470 
1477 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1478  #define RKH_SM_GET_CONST_OBJ(sm) \
1479  &RKH_SM_CONST_NAME(sm)
1480 #else
1481  #define RKH_SM_GET_CONST_OBJ(sm) \
1482  ((RKH_SM_T *)sm)
1483 #endif
1484 
1485 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1486  #define RKH_SM_GET_OBJ(type, sm)
1487 #else
1488  #define RKH_SM_GET_OBJ(type, sm) \
1489  (type *)&RKH_SM_NAME(sm)
1490 #endif
1491 
1501 #define RKH_SM_DEF_PTR(sm) \
1502  RKH_SM_T *const sm = (RKH_SM_T *)&RKH_SM_NAME(sm)
1503 
1518 #define RKH_SM_DEF_PTR_TYPE(type, sm) \
1519  type *const sm = (type *)&RKH_SM_NAME(sm)
1520 
1530 #define RKH_GET_CSTATE_ID(me) \
1531  ((RKH_BASE_T *)(((RKH_SM_T *)me)->state))->id
1532 
1533 #if R_TRC_AO_NAME_EN == RKH_ENABLED
1543  #define RKH_GET_VERTEX_NAME(vx) \
1544  ((struct RKH_BASE_T *)(vx))->name
1545 #else
1546  #define RKH_GET_VERTEX_NAME(vx) noname
1547 #endif
1548 
1549 /* -------------------------------- Constants ------------------------------ */
1550 /* ------------------------------- Data types ------------------------------ */
1557 typedef enum RKH_RCODE_T
1558 {
1564 
1569 
1575 
1580 
1585 
1590 
1596  RKH_NUM_CODES
1597 } RKH_RCODE_T;
1598 
1605 typedef enum
1606 {
1612 
1621 
1625 
1652 #if RKH_CFG_SMA_ENT_ARG_SMA_EN == RKH_ENABLED
1653  #if RKH_CFG_SMA_ENT_ARG_STATE_EN == RKH_ENABLED
1654  typedef void (*RKH_ENT_ACT_T)(const RKH_SM_T *me,
1655  const RKH_ST_T *state);
1656  #else
1657  typedef void (*RKH_ENT_ACT_T)(const RKH_SM_T *me);
1658  #endif
1659 #else
1660  #if RKH_CFG_SMA_ENT_ARG_STATE_EN == RKH_ENABLED
1661  typedef void (*RKH_ENT_ACT_T)(const RKH_ST_T *state);
1662  #else
1663  typedef void (*RKH_ENT_ACT_T)(void);
1664  #endif
1665 #endif
1666 
1692 #if RKH_CFG_SMA_EXT_ARG_SMA_EN == RKH_ENABLED
1693  #if RKH_CFG_SMA_ENT_ARG_STATE_EN == RKH_ENABLED
1694  typedef void (*RKH_EXT_ACT_T)(const RKH_SM_T *me,
1695  const RKH_ST_T *state);
1696  #else
1697  typedef void (*RKH_EXT_ACT_T)(const RKH_SM_T *me);
1698  #endif
1699 #else
1700  #if RKH_CFG_SMA_ENT_ARG_STATE_EN == RKH_ENABLED
1701  typedef void (*RKH_EXT_ACT_T)(const RKH_ST_T *state);
1702  #else
1703  typedef void (*RKH_EXT_ACT_T)(void);
1704  #endif
1705 #endif
1706 
1725 #if RKH_CFG_SMA_PPRO_ARG_SMA_EN == RKH_ENABLED
1726  typedef RKH_SIG_T (*RKH_PPRO_T)(const RKH_SM_T *sma,
1727  RKH_EVT_T *pe);
1728 #else
1729  typedef RKH_SIG_T (*RKH_PPRO_T)(RKH_EVT_T *pe);
1730 #endif
1731 
1763 #if (RKH_CFG_SMA_ACT_ARG_EVT_EN == RKH_ENABLED && \
1764  RKH_CFG_SMA_ACT_ARG_SMA_EN == RKH_ENABLED)
1765  typedef void (*RKH_TRN_ACT_T)(const RKH_SM_T *me,
1766  RKH_EVT_T *pe);
1767 #elif (RKH_CFG_SMA_ACT_ARG_EVT_EN == RKH_ENABLED && \
1768  RKH_CFG_SMA_ACT_ARG_SMA_EN == RKH_DISABLED)
1769  typedef void (*RKH_TRN_ACT_T)(RKH_EVT_T *pe);
1770 #elif (RKH_CFG_SMA_ACT_ARG_EVT_EN == RKH_DISABLED && \
1771  RKH_CFG_SMA_ACT_ARG_SMA_EN == RKH_ENABLED)
1772  typedef void (*RKH_TRN_ACT_T)(const RKH_SM_T *me);
1773 #else
1774  typedef void (*RKH_TRN_ACT_T)(void);
1775 #endif
1776 
1801 #if (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_ENABLED && \
1802  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_ENABLED)
1803 
1804  typedef rbool_t (*RKH_GUARD_T)(const RKH_SM_T *me,
1805  RKH_EVT_T *pe);
1806 #elif (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_ENABLED && \
1807  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_DISABLED)
1808  typedef rbool_t (*RKH_GUARD_T)(RKH_EVT_T *pe);
1809 #elif (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_DISABLED && \
1810  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_ENABLED)
1811  typedef rbool_t (*RKH_GUARD_T)(const RKH_SM_T *me);
1812 #else
1813  typedef rbool_t (*RKH_GUARD_T)(void);
1814 #endif
1815 
1816 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1829 {
1837  rui8_t prio;
1838 
1846  rui8_t ppty;
1847 
1856 #if R_TRC_AO_NAME_EN == RKH_ENABLED
1857  const char *name;
1858 #endif
1859 
1867  RKHROM RKH_ST_T *istate;
1868 
1877 
1886 #if RKH_CFG_SMA_INIT_EVT_EN == RKH_ENABLED
1888 #endif
1889 };
1890 #endif
1891 
1903 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1904 struct RKH_SM_T
1905 {
1911 
1916  RKHROM RKH_ST_T *state;
1917 };
1918 #else
1919 struct RKH_SM_T
1920 {
1928  rui8_t prio;
1929 
1937  rui8_t ppty;
1938 
1947 #if R_TRC_AO_NAME_EN == RKH_ENABLED
1948  const char *name;
1949 #endif
1950 
1958  RKHROM RKH_ST_T *istate;
1959 
1967  RKH_TRN_ACT_T iaction;
1968 
1977 #if RKH_CFG_SMA_INIT_EVT_EN == RKH_ENABLED
1978  const RKH_EVT_T *ievent;
1979 #endif
1980 
1985  RKHROM RKH_ST_T *state;
1986 };
1987 #endif
1988 
1994 {
2009  ruint type;
2010 
2019 #if R_TRC_AO_NAME_EN == RKH_ENABLED
2020  const char *name;
2021 #endif
2022 };
2023 
2032 struct RKH_TR_T
2033 {
2039 
2045 
2051 
2056  RKHROM void *target;
2057 };
2058 
2064 struct RKH_ST_T
2065 {
2071 
2072 #if RKH_CFG_SMA_HCAL_EN == RKH_ENABLED
2078 
2084 
2089  RKHROM RKH_ST_T *parent;
2090 #endif
2091 };
2092 
2098 {
2099  RKH_ST_T st;
2100 
2105  RKHROM RKH_TR_T *trtbl;
2106 
2145 #if RKH_CFG_SMA_PPRO_EN == RKH_ENABLED
2147 #endif
2148 };
2149 
2155 {
2156  RKH_ST_T st;
2157 
2162  RKHROM RKH_TR_T *trtbl;
2163 
2202 #if RKH_CFG_SMA_PPRO_EN == RKH_ENABLED
2204 #endif
2205 
2206 #if RKH_CFG_SMA_HCAL_EN == RKH_ENABLED
2211  RKHROM void *defchild;
2212 
2218 
2223 #if defined(RKH_HISTORY_ENABLED)
2225 #endif
2226 #endif
2227 };
2228 
2234 {
2240 
2245  RKHROM RKH_TR_T *trtbl;
2246 
2251 #if RKH_CFG_SMA_PPRO_EN == RKH_ENABLED
2253 #endif
2254 };
2255 
2260 #if defined(RKH_SUBMACHINE_ENABLED)
2262 {
2268 
2273  RKHROM void *target;
2274 };
2275 
2281 {
2287 
2292  RKHROM void *target;
2293 };
2294 
2354 {
2355  RKH_ST_T st;
2356 
2361  RKHROM RKH_TR_T *trtbl;
2362 
2368 
2373  RKHROM RKH_RSM_T *sbm;
2374 };
2375 
2381 {
2387 
2392  RKHROM void *defchild;
2393 
2402 
2408  RKHROM RKH_ST_T * *dyp;
2409 };
2410 
2423 {
2429 
2435 
2440  RKHROM RKH_ST_T *parent;
2441 };
2442 
2454 {
2460 
2465  rui8_t ix;
2466 
2472 };
2473 #endif
2474 
2479 #if defined(RKH_CHOICE_OR_CONDITIONAL_ENABLED)
2481 {
2487 
2492  RKHROM RKH_TR_T *trtbl;
2493 };
2494 #endif
2495 
2500 #if defined(RKH_CHOICE_ENABLED)
2502 {
2508 
2513  RKHROM RKH_TR_T *trtbl;
2514 };
2515 #endif
2516 
2524 {
2530 
2535  RKHROM RKH_ST_T *parent;
2536 
2542  RKHROM RKH_ST_T **target;
2543 
2548  RKHROM RKH_TR_T trn;
2549 };
2550 
2551 /* -------------------------- External variables --------------------------- */
2552 /* -------------------------- Function prototypes -------------------------- */
2562 
2620 
2634 
2644 
2645 #if (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_ENABLED && \
2646  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_ENABLED)
2647 rbool_t rkh_sm_else(const RKH_SM_T *sma, RKH_EVT_T *pe);
2648 #elif (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_ENABLED && \
2649  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_DISABLED)
2650 rbool_t rkh_sm_else(RKH_EVT_T *pe);
2651 #elif (RKH_CFG_SMA_GRD_ARG_EVT_EN == RKH_DISABLED && \
2652  RKH_CFG_SMA_GRD_ARG_SMA_EN == RKH_ENABLED)
2653 rbool_t rkh_sm_else(const RKH_SM_T *sma);
2654 #else
2655 rbool_t rkh_sm_else(void);
2656 #endif
2657 
2658 /* -------------------- External C language linkage end -------------------- */
2659 #ifdef __cplusplus
2660 }
2661 #endif
2662 
2663 /* ------------------------------ Module end ------------------------------- */
2664 #endif
2665 
2666 /* ------------------------------ End of file ------------------------------ */
ruint rkh_sm_dispatch(RKH_SM_T *me, RKH_EVT_T *e)
Executes a state machine in a run-to-completation (RTC) model.
RKH_HPPTY_T
State machine properties.
Definition: rkhsm.h:1606
void rkh_sm_ctor(RKH_SM_T *me)
Initializes the attributes of the state machine instance.
RKH_RCODE_T
Return codes from rkh_sm_dispatch() function.
Definition: rkhsm.h:1558
void rkh_sm_init(RKH_SM_T *me)
Inits a previously created state machine calling its initializing action.
void rkh_sm_clear_history(RKHROM RKH_SHIST_T *h)
Erase the history of a state. It can be a shallow or deep history.
@ FLAT
Definition: rkhsm.h:1620
@ RKH_NUM_HPPTY
Definition: rkhsm.h:1623
@ HCAL
Definition: rkhsm.h:1611
@ RKH_UNKN_STATE
Definition: rkhsm.h:1584
@ RKH_EVT_NFOUND
Definition: rkhsm.h:1568
@ RKH_CND_NFOUND
Definition: rkhsm.h:1574
@ RKH_EX_HLEVEL
Definition: rkhsm.h:1589
@ RKH_EVT_PROC
Definition: rkhsm.h:1563
@ RKH_EX_TSEG
Definition: rkhsm.h:1595
@ RKH_GRD_FALSE
Definition: rkhsm.h:1579
rui8_t RKH_SIG_T
Definition: rkhevt.h:100
RKH engine interface.This header file is directly included in RKH interface file, rkh....
void(* RKH_EXT_ACT_T)(const RKH_SM_T *me)
Exit action.
Definition: rkhsm.h:1697
void(* RKH_ENT_ACT_T)(const RKH_SM_T *me)
Entry action.
Definition: rkhsm.h:1657
RKH_SIG_T(* RKH_PPRO_T)(const RKH_SM_T *sma, RKH_EVT_T *pe)
Event preprocessor.
Definition: rkhsm.h:1726
rbool_t(* RKH_GUARD_T)(const RKH_SM_T *me, RKH_EVT_T *pe)
Guard.
Definition: rkhsm.h:1804
void(* RKH_TRN_ACT_T)(const RKH_SM_T *me, RKH_EVT_T *pe)
Transition action.
Definition: rkhsm.h:1765
Maintains the basic information of a state.
Definition: rkhsm.h:1994
ruint type
State type.
Definition: rkhsm.h:2009
const char * name
Name of state or pseudostate.
Definition: rkhsm.h:2020
Describes the entry point connection.
Definition: rkhsm.h:2281
RKHROM void * target
Points to target state.
Definition: rkhsm.h:2292
RKH_TRN_ACT_T action
Points to transition action.
Definition: rkhsm.h:2286
Represents events without parameters.
Definition: rkhevt.h:170
Describes the exit point connection.
Definition: rkhsm.h:2262
RKHROM void * target
Points to target state.
Definition: rkhsm.h:2273
RKH_TRN_ACT_T action
Points to transition action.
Definition: rkhsm.h:2267
Describes a final state.
Definition: rkhsm.h:2234
RKH_ST_T st
Definition: rkhsm.h:2239
RKH_PPRO_T prepro
Definition: rkhsm.h:2252
RKHROM RKH_TR_T * trtbl
Definition: rkhsm.h:2245
Constant parameters of state machine.
Definition: rkhsm.h:1829
RKH_TRN_ACT_T iaction
Points to initializing action (optional).
Definition: rkhsm.h:1876
rui8_t ppty
State machine properties.
Definition: rkhsm.h:1846
const RKH_EVT_T * ievent
Pointer to an event that will be passed to state machine application when it starts....
Definition: rkhsm.h:1887
const char * name
Name of State Machine Application (a.k.a Active Object).
Definition: rkhsm.h:1857
RKHROM RKH_ST_T * istate
Points to initial state.
Definition: rkhsm.h:1867
rui8_t prio
SMA (a.k.a Active Object) priority.
Definition: rkhsm.h:1837
Describes a (referenced) submachine state machine.
Definition: rkhsm.h:2381
RKH_TRN_ACT_T iaction
Points to initializing action (optional).
Definition: rkhsm.h:2401
RKHROM RKH_ST_T ** dyp
Points to RAM memory location which stores the dynamic parent.
Definition: rkhsm.h:2408
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2386
RKHROM void * defchild
Points to state's default child.
Definition: rkhsm.h:2392
Describes a basic state.
Definition: rkhsm.h:2098
RKH_PPRO_T prepro
Points to event preprocessor.
Definition: rkhsm.h:2146
RKHROM RKH_TR_T * trtbl
Points to state transition table.
Definition: rkhsm.h:2105
Describes the choice pseudostate.
Definition: rkhsm.h:2502
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2507
RKHROM RKH_TR_T * trtbl
Points to branch table.
Definition: rkhsm.h:2513
Describes a composite state.
Definition: rkhsm.h:2155
RKH_PPRO_T prepro
Points to event preprocessor.
Definition: rkhsm.h:2203
RKHROM RKH_SHIST_T * history
Points to state's history.
Definition: rkhsm.h:2224
RKHROM void * defchild
Points to state's default child.
Definition: rkhsm.h:2211
RKHROM RKH_TR_T * trtbl
Points to state transition table.
Definition: rkhsm.h:2162
RKH_TRN_ACT_T initialAction
Points to state's initial action.
Definition: rkhsm.h:2217
Describes the conditional pseudostate.
Definition: rkhsm.h:2481
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2486
RKHROM RKH_TR_T * trtbl
Points to branch table.
Definition: rkhsm.h:2492
Describes the entry point pseudostate.
Definition: rkhsm.h:2423
RKHROM RKH_ENPCN_T * enpcn
Points to entry point connection.
Definition: rkhsm.h:2434
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2428
RKHROM RKH_ST_T * parent
Points to state's parent (submachine state).
Definition: rkhsm.h:2440
Describes the exit point pseudostate.
Definition: rkhsm.h:2454
rui8_t ix
Index of exit point table.
Definition: rkhsm.h:2465
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2459
RKHROM RKH_RSM_T * parent
Points to state's parent (referenced submachine).
Definition: rkhsm.h:2471
Describes the history pseudostate.
Definition: rkhsm.h:2524
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2529
RKHROM RKH_TR_T trn
History default transition.
Definition: rkhsm.h:2548
RKHROM RKH_ST_T * parent
Points to state's parent.
Definition: rkhsm.h:2535
RKHROM RKH_ST_T ** target
Points to RAM memory location which stores the state's history.
Definition: rkhsm.h:2542
Describes the state machine.
Definition: rkhsm.h:1905
RKHROM RKH_ROM_T * romrkh
Points to constant parameters of state machine.
Definition: rkhsm.h:1910
RKHROM RKH_ST_T * state
Points to current stable state (simple or final state).
Definition: rkhsm.h:1916
Describes a submachine state.
Definition: rkhsm.h:2354
RKHROM RKH_EXPCN_T * exptbl
Points to state transition table.
Definition: rkhsm.h:2367
RKHROM RKH_TR_T * trtbl
Points to state transition table.
Definition: rkhsm.h:2361
RKHROM RKH_RSM_T * sbm
Points to submachine object.
Definition: rkhsm.h:2373
Describes the common properties of regular states (basic, composite, and submachine).
Definition: rkhsm.h:2065
RKH_EXT_ACT_T exit
Points to exit action.
Definition: rkhsm.h:2083
RKH_BASE_T base
Maintains the basic information of state.
Definition: rkhsm.h:2070
RKH_ENT_ACT_T enter
Points to entry action.
Definition: rkhsm.h:2077
RKHROM RKH_ST_T * parent
Points to state's parent.
Definition: rkhsm.h:2089
Describes the state transition.
Definition: rkhsm.h:2033
RKHROM void * target
Points to target state.
Definition: rkhsm.h:2056
RKH_GUARD_T guard
Points to guard function.
Definition: rkhsm.h:2044
RKH_TRN_ACT_T action
Points to transition action.
Definition: rkhsm.h:2050
RKH_SIG_T event
Triggering event.
Definition: rkhsm.h:2038