RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rkh.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 web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
84 /* -------------------------- Development history -------------------------- */
85 /*
86  * 2015.10.24 LeFr v2.4.05 Initial version
87  */
88 
89 /* -------------------------------- Authors -------------------------------- */
90 /*
91  * LeFr Leandro Francucci francuccilea@gmail.com
92  */
93 
94 /* --------------------------------- Notes --------------------------------- */
95 /*
96  * (1) This header file must be included in all modules (*.c) that use RKH.
97  */
98 
99 /* --------------------------------- Module -------------------------------- */
100 #ifndef __RKH_H__
101 #define __RKH_H__
102 
103 /* ----------------------------- Include files ----------------------------- */
104 #include "rkhitl.h"
105 #include "rkhrq.h"
106 #include "rkhmp.h"
107 #include "rkhtim.h"
108 #include "rkhassert.h"
109 #include "rkhtrc.h"
110 
111 /* ---------------------- External C language linkage ---------------------- */
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 /* --------------------------------- Macros -------------------------------- */
125 #define RKH_MODULE_VERSION(__fname, __version) \
126  static RKHROM char *const m_version = # __version;
127 
132 #define RKH_MODULE_GET_VERSION() \
133  ((const char *)m_version);
134 
143 #define RKH_MODULE_DESC(__fname, __desc) \
144  static RKHROM char *const m_desc = __desc;
145 
150 #define RKH_MODULE_GET_DESC() \
151  ((const char *)m_desc)
152 
153 #if RKH_CFGPORT_NATIVE_DYN_EVT_EN == RKH_ENABLED && \
154  RKH_EN_DOXYGEN == RKH_DISABLED
155  #define RKH_DYNE_TYPE RKH_MP_T
156  #define RKH_DYNE_INIT(mp, sstart, ssize, esize) \
157  rkh_mp_init((mp),sstart,(rui16_t)ssize,(RKH_MPBS_T)esize)
158  #define RKH_DYNE_GET_ESIZE(mp) ((mp)->bsize)
159  #define RKH_DYNE_GET(mp, e) ((e) = (RKH_EVT_T *)rkh_mp_get((mp)))
160  #define RKH_DYNE_PUT(mp, e) (rkh_mp_put((mp), e))
161 #else
162  #define RKH_DYNE_TYPE rui8_t
163  #define RKH_DYNE_INIT(mp, sstart, ssize, esize) (void)0
164  #define RKH_DYNE_GET_ESIZE(mp) (void)0
165  #define RKH_DYNE_GET(mp, e) (void)0
166  #define RKH_DYNE_PUT(mp, e) (void)0
167 #endif
168 
178 #define RKH_UPCAST(BaseType_, me_) ((BaseType_ *)me_)
179 
186 #define RKH_DOWNCAST(DerivedType_, me_) ((DerivedType_ *)me_)
187 
188 /* -------------------------------- Constants ------------------------------ */
189 #ifndef NULL
190 #define NULL (void *)0
191 #endif
192 
193 /* ------------------------------- Data types ------------------------------ */
200 typedef enum RKH_RCODE_T
201 {
207 
212 
218 
223 
228 
233 
239  RKH_NUM_CODES
240 } RKH_RCODE_T;
241 
248 typedef enum
249 {
255 
264 
267 } RKH_HPPTY_T;
268 
269 /* -------------------------- External variables --------------------------- */
280 
286 extern RKHROM rui8_t rkh_maptbl[8];
287 
293 extern RKHROM rui8_t rkh_unmaptbl[256];
294 
299 extern RKHROM char rkh_version[];
300 
305 extern RKHROM char noname[];
306 
311 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
313 #endif
314 
327 #define ELSE rkh_else
328 
392 #define RKH_CREATE_COMP_REGION_STATE(name, en, ex, parent, defchild, \
393  initialTrn, \
394  kindOfHistory, hDftTrnGuard, \
395  hDftTrnAction, hDftTarget, hRamMem) \
396  \
397  MKFINAL_INCOMP(name); \
398  MKHIST_INCOMP(name, kindOfHistory, hDftTrnGuard, hDftTrnAction, \
399  hDftTarget, hRamMem); \
400  \
401  extern RKHROM RKH_TR_T name##_trtbl[]; \
402  RKHROM RKH_SCMP_T name = \
403  { \
404  {MKBASE(RKH_COMPOSITE, name), MKST(en, ex, parent)}, \
405  MKCOMP(name, defchild, initialTrn, &name##Hist) \
406  }
407 
431 #define RKH_CREATE_COMP_STATE(name, en, ex, parent, defchild, history) \
432  \
433  extern RKHROM RKH_TR_T name##_trtbl[]; \
434  RKHROM RKH_SCMP_T name = \
435  { \
436  {MKBASE(RKH_COMPOSITE, name), MKST(en, ex, parent)}, \
437  MKCOMP(name, defchild, NULL, history) \
438  }
439 
452 #define RKH_CREATE_FINAL_STATE(name, parent) \
453  \
454  static RKHROM RKH_TR_T name##_trtbl[] = \
455  RKH_TRREG(RKH_ANY, NULL, NULL, NULL); \
456  RKHROM RKH_FINAL_T name = \
457  { \
458  {MKBASE(RKH_FINAL, name), MKST(NULL, NULL, parent)}, \
459  MKFINAL(name) \
460  }
461 
517 #define RKH_CREATE_BASIC_STATE(name, en, ex, parent, prepro) \
518  \
519  extern RKHROM RKH_TR_T name##_trtbl[]; \
520  \
521  RKHROM RKH_SBSC_T name = \
522  { \
523  {MKBASE(RKH_BASIC, name), MKST(en,ex,parent)}, \
524  MKBASIC(name,prepro) \
525  }
526 
553 #define RKH_CREATE_COND_STATE(name) \
554  \
555  extern RKHROM RKH_TR_T name##_trtbl[]; \
556  \
557  RKHROM RKH_SCOND_T name = \
558  { \
559  MKBASE(RKH_CONDITIONAL, name), \
560  name##_trtbl \
561  }
562 
589 #define RKH_CREATE_CHOICE_STATE(name) \
590  \
591  extern RKHROM RKH_TR_T name##_trtbl[]; \
592  \
593  RKHROM RKH_SCHOICE_T name = \
594  { \
595  MKBASE(RKH_CHOICE, name), \
596  name##_trtbl \
597  }
598 
633 #define RKH_CREATE_DEEP_HISTORY_STATE(name, parent, dftTrnGuard, \
634  dftTrnAction, dftTarget) \
635  \
636  static RKHROM RKH_ST_T *ram##name; \
637  MKHISTORY(name, parent, RKH_DHISTORY, dftTrnGuard, dftTrnAction, \
638  dftTarget, &ram##name)
639 
676 #define RKH_CREATE_SHALLOW_HISTORY_STATE(name, parent, dftTrnGuard, \
677  dftTrnAction, dftTarget) \
678  \
679  static RKHROM RKH_ST_T *ram##name; \
680  MKHISTORY(name, parent, RKH_SHISTORY, dftTrnGuard, dftTrnAction, \
681  dftTarget, &ram##name)
682 
733 #define RKH_CREATE_SUBMACHINE_STATE(name, en, ex, parent, sbm) \
734  \
735  extern RKHROM RKH_EXPCN_T name##_exptbl[]; \
736  extern RKHROM RKH_TR_T name##_trtbl[]; \
737  \
738  RKHROM RKH_SSBM_T name = \
739  { \
740  {MKBASE(RKH_SUBMACHINE, name), MKST(en,ex,parent)}, \
741  MKSBM(name,sbm) \
742  }
743 
769 #define RKH_CREATE_EX_CNNPNT_TABLE(name) \
770  RKHROM RKH_EXPCN_T name##_exptbl[]= \
771  {
772 
815 #define RKH_EX_CNNPNT(name, expnt, act, ts) \
816  {(RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts}
817 
839 #define RKH_END_EX_CNNPNT_TABLE };
840 
863 #define RKH_EN_CNNPNT(name, enpnt, subm) \
864  \
865  RKHROM RKH_SENP_T name = \
866  { \
867  MKBASE(RKH_ENPOINT, name), \
868  MKENP(enpnt,subm) \
869  }
870 
894 #define RKH_CREATE_REF_SUBMACHINE(name, defchild, iact) \
895  \
896  static RKHROM RKH_ST_T * rdyp_##name; \
897  \
898  RKHROM RKH_RSM_T name = \
899  { \
900  MKBASE(RKH_REF_SUBMACHINE, name), \
901  MKMCH(defchild,iact,name) \
902  }
903 
948 #define RKH_CREATE_REF_EXPNT(name, ix, subm) \
949  \
950  RKHROM RKH_SEXP_T name = \
951  { \
952  MKBASE(RKH_EXPOINT, name), \
953  ix, subm \
954  }
955 
985 #define RKH_CREATE_REF_ENPNT(name, act, ts, subm) \
986  \
987  RKHROM RKH_ENPCN_T name = \
988  { \
989  (RKH_TRN_ACT_T)act, (RKHROM struct RKH_ST_T *)ts \
990  }
991 
1017 #define RKH_CREATE_TRANS_TABLE(name) \
1018  \
1019  RKHROM RKH_TR_T name##_trtbl[]= \
1020  {
1021 
1051 #define RKH_TRREG(evt_, guard_, effect_, target_) \
1052  MKTRN(evt_, guard_, effect_, target_)
1053 
1075 #define RKH_TRINT(e, g, a) {e, (RKH_GUARD_T)g, (RKH_TRN_ACT_T)a, NULL}
1076 
1110 #define RKH_TRCOMPLETION(guard_, effect_, target_) \
1111  {RKH_COMPLETION_EVENT, \
1112  (RKH_GUARD_T)guard_, (RKH_TRN_ACT_T)effect_, target_}
1113 
1134 #define RKH_END_TRANS_TABLE {RKH_ANY, NULL, NULL, NULL}};
1135 
1160 #define RKH_CREATE_BRANCH_TABLE(name) \
1161  \
1162  RKH_CREATE_TRANS_TABLE(name)
1163 
1196 #define RKH_BRANCH(guard_, effect_, target_) \
1197  MKTRN(0, guard_, effect_, target_)
1198 
1212 #define RKH_CREATE_HISTORY_STORAGE(compStateName) \
1213  static RKHROM RKH_ST_T *ramHist_##compStateName
1214 
1226 #define RKH_GET_HISTORY_STORAGE(compStateName) \
1227  &ramHist_##compStateName
1228 
1229 /*
1230  * This macro is internal to RKH and the user application should
1231  * not call it.
1232  */
1233 #define RKH_EBTBL {RKH_ANY, NULL, NULL, NULL}
1234 
1253 #define RKH_END_BRANCH_TABLE RKH_EBTBL};
1254 
1259 #define RKH_ROOT RKH_NULL
1260 
1288 #define RKH_SMA_DCLR(me_) \
1289  RKH_DCLR_PTR_TYPE(RKH_SMA_T, me_)
1290 
1317 #define RKH_SMA_DCLR_TYPE(type_, me_) \
1318  RKH_DCLR_PTR_TYPE(type_, me_)
1319 
1347 #define RKH_SM_DCLR(me_) \
1348  RKH_DCLR_PTR_TYPE(RKH_SM_T, me_)
1349 
1372 #define RKH_SM_DCLR_TYPE(type_, me_) \
1373  RKH_DCLR_PTR_TYPE(type_, me_)
1374 
1384 #define RKH_DCLR_COMP_STATE extern RKHROM RKH_SCMP_T
1385 #define RKH_DCLR_BASIC_STATE extern RKHROM RKH_SBSC_T
1386 #define RKH_DCLR_FINAL_STATE extern RKHROM RKH_FINAL_T
1387 #define RKH_DCLR_COND_STATE extern RKHROM RKH_SCOND_T
1388 #define RKH_DCLR_CHOICE_STATE extern RKHROM RKH_SCHOICE_T
1389 #define RKH_DCLR_DHIST_STATE extern RKHROM RKH_SHIST_T
1390 #define RKH_DCLR_SHIST_STATE extern RKHROM RKH_SHIST_T
1391 #define RKH_DCLR_SUBM_STATE extern RKHROM RKH_SSBM_T
1392 #define RKH_DCLR_REF_SUBM extern RKHROM RKH_RSM_T
1393 #define RKH_DCLR_ENPNT extern RKHROM RKH_SENP_T
1394 #define RKH_DCLR_REF_EXPNT extern RKHROM RKH_SEXP_T
1395 #define RKH_DCLR_REF_ENPNT extern RKHROM RKH_ENPCN_T
1396 
1429 #define RKH_ARRAY_SMA_DCLR(_arr, _num) \
1430  extern RKH_SMA_T * const *_arr[_num]
1431 
1464 #define RKH_ARRAY_SMA_DCLR_TYPE(type_, array_, num_) \
1465  extern type_ * const * array_[num_]
1466 
1490 #define RKH_ARRAY_SMA_CREATE(_arr, _num) \
1491  RKH_SMA_T * const *_arr[_num] =
1492 
1517 #define RKH_ARRAY_SMA_CREATE_TYPE(type_, array_, num_) \
1518  type_ * const * array_[num_] =
1519 
1547 #define RKH_ARRAY_SMA(_arr, _ix) *_arr[_ix]
1548 
1571 #define RKH_DCLR_SM_GLOBAL(sma_t, sm, gob) \
1572  sma_t * const gob = &s_##sm;
1573 
1580 #define RKH_DECLARE_TR_TBL(name) \
1581  extern RKHROM RKH_TR_T name##_trtbl[]
1582 
1707 #define RKH_INIT_BASIC_STATE(name, en, ex, parent, prepro) \
1708  { \
1709  { \
1710  MKBASE(RKH_BASIC, name), /* RKH_BASE_T */ \
1711  MKST(en, ex, parent) \
1712  }, /* RKH_ST_T */ \
1713  MKBASIC(name, prepro) \
1714  } /* RKH_SBSC_T */ \
1715 
1716 
1730 #define RKH_INIT_COMPOSITE_STATE(name, en, ex, parent, \
1731  defchild, history) \
1732  { \
1733  { \
1734  MKBASE(RKH_COMPOSITE, name), /* RKH_BASE_T */ \
1735  MKST(en, ex, parent) \
1736  }, /* RKH_ST_T */ \
1737  MKCOMP(name, defchild, history) \
1738  } /* RKH_SCMP_T */ \
1739 
1740 
1748 #define RKH_GFALSE RKH_FALSE
1749 #define RKH_GTRUE RKH_TRUE
1751 #if defined(RKH_USE_TRC_SENDER)
1752 
1770  #define RKH_TIM_TICK(_sender) rkh_tmr_tick(_sender)
1771 #else
1772  #define RKH_TIM_TICK(dummy_) rkh_tmr_tick()
1773 #endif
1774 
1817 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
1818 #if RKH_CFGPORT_SMA_QSTO_EN == RKH_ENABLED
1819  #if RKH_CFGPORT_SMA_STK_EN == RKH_ENABLED
1820  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1821  ((RKH_SMA_T *)(me_))->vptr->activate(me_, \
1822  (const RKH_EVT_T **)qSto_, \
1823  qStoSize, \
1824  (void *)stkSto_, \
1825  (rui32_t)stkSize_)
1826  #else
1827  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1828  ((RKH_SMA_T *)(me_))->vptr->activate(me_, \
1829  (const RKH_EVT_T **)qSto_, \
1830  qStoSize, \
1831  (void *)0, \
1832  (rui32_t)0)
1833  #endif
1834 #else
1835  #if RKH_CFGPORT_SMA_STK_EN == RKH_ENABLED
1836  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1837  ((RKH_SMA_T *)(me_))->vptr->activate(me_, \
1838  (const RKH_EVT_T **)0, \
1839  qStoSize, \
1840  (void *)stkSto_, \
1841  (rui32_t)stkSize_)
1842  #else
1843  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1844  ((RKH_SMA_T *)(me_))->vptr->activate(me_, \
1845  (const RKH_EVT_T **)0, \
1846  qStoSize, \
1847  (void *)0, \
1848  (rui32_t)0)
1849  #endif
1850 #endif
1851 #else
1852 #if RKH_CFGPORT_SMA_QSTO_EN == RKH_ENABLED
1853  #if RKH_CFGPORT_SMA_STK_EN == RKH_ENABLED
1854  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1855  rkh_sma_activate(me_, \
1856  (const RKH_EVT_T **)qSto_, \
1857  qStoSize, \
1858  (void *)stkSto_, \
1859  (rui32_t)stkSize_)
1860  #else
1861  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1862  rkh_sma_activate(me_, \
1863  (const RKH_EVT_T **)qSto_, \
1864  qStoSize, \
1865  (void *)0, \
1866  (rui32_t)0)
1867  #endif
1868 #else
1869  #if RKH_CFGPORT_SMA_STK_EN == RKH_ENABLED
1870  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1871  rkh_sma_activate(me_, \
1872  (const RKH_EVT_T **)0, \
1873  qStoSize, \
1874  (void *)stkSto_, \
1875  (rui32_t)stkSize_)
1876  #else
1877  #define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_) \
1878  rkh_sma_activate(me_, \
1879  (const RKH_EVT_T **)0, \
1880  qStoSize, \
1881  (void *)0, \
1882  (rui32_t)0)
1883  #endif
1884 #endif
1885 #endif
1886 
1887 
1920 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1921  #define RKH_SM_CREATE(type, name, prio, ppty, initialState, \
1922  initialAction, initialEvt) \
1923  RKH_SM_CONST_CREATE(name, prio, ppty, initialState, initialAction, \
1924  initialEvt); \
1925  static type s_##name = {MKSM(&RKH_SM_CONST_NAME(name), initialState)}
1926 #else
1927  #define RKH_SM_CREATE(type, name, prio, ppty, initialState, \
1928  initialAction, initialEvt) \
1929  static type RKH_SMA_NAME(name) = {MKSM(name, prio, ppty, initialState, \
1930  initialAction, initialEvt)}
1931 #endif
1932 
1964 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
1965  #define RKH_SM_INIT(me_, nameSMConst_, prio_, ppty_, initialState_, \
1966  initialAction_, initialEvt_) \
1967  ((RKH_SM_T *)me_)->romrkh = \
1968  (RKHROM RKH_ROM_T *)(RKH_SM_GET_CONST_OBJ(nameSMConst_)); \
1969  ((RKH_SM_T *)me_)->state = \
1970  (RKHROM struct RKH_ST_T *) \
1971  ((RKH_SM_GET_CONST_OBJ(nameSMConst_))->istate)
1972 #else
1973  #define RKH_SM_INIT(sm, name, prio, ppty, initialState, \
1974  initialAction, initialEvt) \
1975  MKRT_SM(sm, name, prio, ppty, initialState, initialAction, initialEvt)
1976 #endif
1977 
2045 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2046  #define RKH_SMA_CREATE(type, name, prio, ppty, initialState, \
2047  initialAction, initialEvt) \
2048  RKH_SM_CONST_CREATE(name, prio, ppty, initialState, initialAction, \
2049  initialEvt); \
2050  static type RKH_SMA_NAME(name) = MKSMA(&RKH_SM_CONST_NAME(name), \
2051  initialState)
2052 #else
2053  #define RKH_SMA_CREATE(type, name, prio, ppty, initialState, \
2054  initialAction, initialEvt) \
2055  static type RKH_SMA_NAME(name) = MKSMA(name, \
2056  prio, \
2057  ppty, \
2058  initialState, \
2059  initialAction, \
2060  initialEvt)
2061 #endif
2062 
2093 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2094  #define RKH_SM_CONST_CREATE(name, prio, ppty, initialState, \
2095  initialAction, initialEvt) \
2096  static RKHROM RKH_ROM_T RKH_SM_CONST_NAME(name) = \
2097  MKRRKH(name, \
2098  prio, \
2099  ppty, \
2100  initialState, \
2101  initialAction, \
2102  initialEvt)
2103 #else
2104  #define RKH_SM_CONST_CREATE(name, prio, ppty, initialState, \
2105  initialAction, initialEvt)
2106 #endif
2107 
2115 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2116  #define RKH_SM_GET_CONST(sm) \
2117  ((RKH_SM_T *)sm)->romrkh
2118 #else
2119  #define RKH_SM_GET_CONST(sm) \
2120  ((RKH_SM_T *)sm)
2121 #endif
2122 
2129 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2130  #define RKH_SM_GET_CONST_OBJ(sm) \
2131  &RKH_SM_CONST_NAME(sm)
2132 #else
2133  #define RKH_SM_GET_CONST_OBJ(sm) \
2134  ((RKH_SM_T *)sm)
2135 #endif
2136 
2137 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2138  #define RKH_SMA_INIT(me, prio, ppty, initialState, initialAction, \
2139  initialEvt)
2140 #else
2141  #define RKH_SMA_INIT(me, prio, ppty, initialState, initialAction, \
2142  initialEvt) \
2143  MKRT_SM(me, me, prio, ppty, initialState, initialAction, initialEvt)
2144 #endif
2145 
2146 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2147  #define RKH_SMA_GET_OBJ(type, me)
2148 #else
2149  #define RKH_SMA_GET_OBJ(type, me) \
2150  (type *)&RKH_SMA_NAME(me)
2151 #endif
2152 
2153 #if RKH_CFG_SMA_SM_CONST_EN == RKH_ENABLED
2154  #define RKH_SM_GET_OBJ(type, sm)
2155 #else
2156  #define RKH_SM_GET_OBJ(type, sm) \
2157  (type *)&RKH_SM_NAME(sm)
2158 #endif
2159 
2169 #define RKH_SM_DEF_PTR(sm) \
2170  RKH_SM_T *const sm = (RKH_SM_T *)&RKH_SM_NAME(sm)
2171 
2186 #define RKH_SM_DEF_PTR_TYPE(type, sm) \
2187  type *const sm = (type *)&RKH_SM_NAME(sm)
2188 
2198 #define RKH_SMA_DEF_PTR(me_) \
2199  RKH_SMA_T *const me_ = (RKH_SMA_T *)&RKH_SMA_NAME(me_)
2200 
2215 #define RKH_SMA_DEF_PTR_TYPE(type, me_) \
2216  type *const me_ = (type *)&RKH_SMA_NAME(me_)
2217 
2248 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
2249  #if defined(RKH_USE_TRC_SENDER)
2250  #define RKH_SMA_POST_FIFO(me_, e_, sender_) \
2251  ((RKH_SMA_T *)(me_))->vptr->post_fifo((me_), (e_), (sender_))
2252  #else
2253  #define RKH_SMA_POST_FIFO(me_, e_, sender_) \
2254  ((RKH_SMA_T *)(me_))->vptr->post_fifo((me_), (e_))
2255  #endif
2256 #else
2257  #if defined(RKH_USE_TRC_SENDER)
2258  #define RKH_SMA_POST_FIFO(me_, e_, sender_) \
2259  rkh_sma_post_fifo((me_), (e_), (sender_))
2260  #else
2261  #define RKH_SMA_POST_FIFO(me_, e_, sender_) \
2262  rkh_sma_post_fifo((me_), (e_))
2263  #endif
2264 #endif
2265 
2296 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
2297  #if defined(RKH_USE_TRC_SENDER)
2298  #define RKH_SMA_POST_LIFO(me_, e_, sender_) \
2299  ((RKH_SMA_T *)(me_))->vptr->post_lifo((me_), (e_), (sender_))
2300  #else
2301  #define RKH_SMA_POST_LIFO(me_, e_, sender_) \
2302  ((RKH_SMA_T *)(me_))->vptr->post_lifo((me_), (e_))
2303  #endif
2304 #else
2305  #if defined(RKH_USE_TRC_SENDER)
2306  #define RKH_SMA_POST_LIFO(me_, e_, sender_) \
2307  rkh_sma_post_lifo((me_), (e_), (sender_))
2308  #else
2309  #define RKH_SMA_POST_LIFO(me_, e_, sender_) \
2310  rkh_sma_post_lifo((me_), (e_))
2311  #endif
2312 #endif
2313 
2346 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
2347  #define RKH_ALLOC_EVT(et, e) \
2348  (et *)rkh_fwk_ae((RKH_ES_T)sizeof(et),(RKH_SIG_T)(e))
2349 #else
2350  #define RKH_ALLOC_EVT(et, e) \
2351  (void)0
2352 #endif
2353 
2384 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
2385  #define RKH_FWK_GC(e) rkh_fwk_gc(e)
2386 #else
2387  #define RKH_FWK_GC(e) (void)0
2388 #endif
2389 
2403 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
2404  #define RKH_FWK_RSV(e) rkh_fwk_reserve(e)
2405 #else
2406  #define RKH_FWK_RSV(e) (void)0
2407 #endif
2408 
2451 #define RKH_SET_STATIC_EVENT(ev_obj, ev_sig) \
2452  MK_SET_EVT(ev_obj, ev_sig)
2453 
2480 #define RKH_STATIC_EVENT(ev_obj, ev_sig) \
2481  MK_EVT(ev_obj, ev_sig)
2482 
2512 #define RKH_ROM_STATIC_EVENT(ev_obj, ev_sig) \
2513  MK_ROM_EVT(ev_obj, ev_sig)
2514 
2545 #define RKH_INIT_STATIC_EVT(ev_sig) \
2546  MK_EVT_STRUCT(ev_sig)
2547 
2557 #define RKH_GET_CSTATE_ID(me) \
2558  ((RKH_BASE_T *)(((RKH_SM_T *)me)->state))->id
2559 
2560 #if R_TRC_AO_NAME_EN == RKH_ENABLED
2561 
2570  #define RKH_GET_AO_NAME(ao) RKH_SMA_ACCESS_CONST(ao, name)
2571 
2581  #define RKH_GET_VERTEX_NAME(vx) \
2582  ((struct RKH_BASE_T *)(vx))->name
2583 #else
2584  #define RKH_GET_AO_NAME(ao) noname
2585  #define RKH_GET_VERTEX_NAME(vx) noname
2586 #endif
2587 
2596 #define RKH_GET_SMA(_prio) \
2597  rkh_sptbl[(rui8_t)(_prio)]
2598 
2605 #define RKH_GET_PRIO(_ao) \
2606  (rui8_t)(RKH_SMA_ACCESS_CONST(_ao, prio))
2607 
2614 #define RKH_EVT_CAST(_e) ((RKH_EVT_T *)(_e))
2615 
2639 #define RKH_CAST(_type, _obj) ((_type *)(_obj))
2640 
2682 #if RKH_CFG_TRC_EN == RKH_ENABLED
2683  #define RKH_TRC_OPEN() rkh_trc_open()
2684 #else
2685  #define RKH_TRC_OPEN() (void)0
2686 #endif
2687 
2713 #if RKH_CFG_TRC_EN == RKH_ENABLED
2714  #define RKH_TRC_CLOSE() rkh_trc_close()
2715 #else
2716  #define RKH_TRC_CLOSE() (void)0
2717 #endif
2718 
2766 #if RKH_CFG_TRC_EN == RKH_ENABLED
2767  #define RKH_TRC_FLUSH() rkh_trc_flush()
2768 #else
2769  #define RKH_TRC_FLUSH() (void)0
2770 #endif
2771 
2796 #if RKH_CFG_TRC_EN == RKH_ENABLED
2797  #define RKH_TRC_SEND_CFG(ts_hz) \
2798  RKH_TR_FWK_TCFG(ts_hz)
2799 #else
2800  #define RKH_TRC_SEND_CFG(ts_hz) (void)0
2801 #endif
2802 
2803 /* -------------------------- Function prototypes -------------------------- */
2825 void rkh_fwk_init(void);
2826 
2856 void rkh_fwk_enter(void);
2857 
2884 void rkh_fwk_exit(void);
2885 
2910 void rkh_sma_terminate(RKH_SMA_T *me);
2911 
2912 #if defined(RKH_USE_TRC_SENDER)
2913 
2932 void rkh_tmr_tick(const void *const sender);
2933 #else
2934 void rkh_tmr_tick(void);
2935 #endif
2936 
2967 void rkh_sma_activate(RKH_SMA_T *me, const RKH_EVT_T * *qSto,
2968  RKH_RQNE_T qSize, void *stkSto, rui32_t stkSize);
2969 
2970 #if defined(RKH_USE_TRC_SENDER)
2971 
3002 void rkh_sma_post_fifo(RKH_SMA_T *me, const RKH_EVT_T *e,
3003  const void *const sender);
3004 #else
3005 void rkh_sma_post_fifo(RKH_SMA_T *me, const RKH_EVT_T *e);
3006 #endif
3007 
3008 #if defined(RKH_USE_TRC_SENDER)
3009 
3041 void rkh_sma_post_lifo(RKH_SMA_T *me, const RKH_EVT_T *e,
3042  const void *const sender);
3043 
3044 #else
3045 void rkh_sma_post_lifo(RKH_SMA_T *me, const RKH_EVT_T *e);
3046 #endif
3047 
3073 
3097 void rkh_sma_get_info(RKH_SMA_T *me, RKH_SMAI_T *psi);
3098 
3110 void rkh_sma_clear_info(RKH_SMA_T *me);
3111 
3120 void rkh_sma_register(RKH_SMA_T *me);
3121 
3130 void rkh_sma_unregister(RKH_SMA_T *me);
3131 
3145 void rkh_sma_ctor(RKH_SMA_T *me, const RKHSmaVtbl *vtbl);
3146 
3189 void rkh_fwk_defer(RKH_RQ_T *q, const RKH_EVT_T *e);
3190 
3219 
3305 void rkh_fwk_epool_register(void *sstart, rui32_t ssize, RKH_ES_T esize);
3306 
3323 
3330 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
3331 void rkh_fwk_gc(RKH_EVT_T *e);
3332 #endif
3333 
3340 #if RKH_CFG_FWK_DYN_EVT_EN == RKH_ENABLED
3341 void rkh_fwk_reserve(RKH_EVT_T *e);
3342 #endif
3343 
3359 void rkh_hook_dispatch(RKH_SMA_T *me, RKH_EVT_T *e);
3360 
3375 void rkh_hook_signal(RKH_EVT_T *e);
3376 
3394 void rkh_hook_timeout(const void *t);
3395 
3408 void rkh_hook_start(void);
3409 
3423 void rkh_hook_exit(void);
3424 
3452 void rkh_hook_idle(void);
3453 
3474 void rkh_hook_timetick(void);
3475 
3485 void rkh_hook_putTrcEvt(void);
3486 
3495 void rkh_sm_init(RKH_SM_T *me);
3496 
3553 ruint rkh_sm_dispatch(RKH_SM_T *me, RKH_EVT_T *e);
3554 
3567 void rkh_sm_ctor(RKH_SM_T *me);
3568 
3577 #if defined(RKH_HISTORY_ENABLED)
3578 void rkh_sm_clear_history(RKHROM RKH_SHIST_T *h);
3579 #else
3580 #define rkh_sm_clear_history(h) (void)0
3581 #endif
3582 
3589 #if RKH_CFG_TRC_EN == RKH_ENABLED
3590 void rkh_trc_open(void);
3591 #endif
3592 
3599 #if RKH_CFG_TRC_EN == RKH_ENABLED
3600 void rkh_trc_close(void);
3601 #endif
3602 
3609 #if RKH_CFG_TRC_EN == RKH_ENABLED
3610 void rkh_trc_flush(void);
3611 #endif
3612 
3636 RKH_TS_T rkh_trc_getts(void);
3637 
3638 /* -------------------- External C language linkage end -------------------- */
3639 #ifdef __cplusplus
3640 }
3641 #endif
3642 
3643 /* ------------------------------ Module end ------------------------------- */
3644 #endif
3645 
3646 /* ------------------------------ End of file ------------------------------ */
Platform - independent interface for RKH trace facility.
void rkh_hook_timeout(const void *t)
If a timer expires the rkh_hook_timeout() function is called just before the assigned event is direct...
rui8_t RKH_RQNE_T
This data type defines the maximum number of elements that any queue can contain. ...
Definition: rkhrq.h:95
rui16_t RKH_TS_T
Defines the size of trace timestamp.
Definition: rkhtrc.h:3446
void rkh_sm_clear_history(RKHROM RKH_SHIST_T *h)
Erase the history of a state. It can be a shallow or deep history.
void rkh_sm_ctor(RKH_SM_T *me)
Initializes the attributes of the state machine instance.
RKH_EVT_T * rkh_sma_get(RKH_SMA_T *me)
Get an event from the event queue of an state machine application (SMA) as known as active object...
RKH_EVT_T * rkh_fwk_ae(RKH_ES_T esize, RKH_SIG_T e)
Allocates an event from the previously created event pool.
RKH_RCODE_T
Return codes from rkh_sm_dispatch() function.
Definition: rkh.h:200
Describes the SMA (active object in UML).
Definition: rkhitl.h:2930
void rkh_trc_open(void)
Open the tracing session.
void rkh_hook_signal(RKH_EVT_T *e)
When the producer of an event directly posts the event to the event queue of the consumer SMA the rkh...
#define RKH_DYNE_TYPE
Defines the data type of the fixed-size memory block for dynamic event support.
Definition: rkhitl.h:2371
Represents events without parameters.
Definition: rkhevt.h:161
void rkh_sma_unregister(RKH_SMA_T *me)
Removes the SMA as known as active object from the priority table, and thus from the framework...
void rkh_sma_ctor(RKH_SMA_T *me, const RKHSmaVtbl *vtbl)
Initializes the virtual table of the active object instance and calls the constructor operation of it...
Defines the data structure used to maintain information about the queue.
Definition: rkhrq.h:167
RKHROM char noname[]
String representing the name of undefined object name.
RKHROM rui8_t rkh_unmaptbl[256]
rkh_unmaptbl[] is a table in ROM, used to return the bit position of the highest priority bit set - a...
rui8_t RKH_SIG_T
Definition: rkhevt.h:92
The assertions (RKH_ASSERT() macro) are used to check expressions that ought to be true as long as th...
void rkh_fwk_enter(void)
RKH framework is started.
RKH engine interface.This header file is directly included in RKH interface file, rkh...
Platform - independent interface for supporting queue services.
void rkh_sma_post_lifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
Platform - independent interface for supporting fixed - size memory blocks facility.
RKH_DYNE_TYPE rkh_eplist[RKH_CFG_FWK_MAX_EVT_POOL]
Event pool list.
RKH_EVT_T * rkh_fwk_recall(RKH_SMA_T *me, RKH_RQ_T *q)
Recall a deferred event from a given event queue.
void rkh_hook_start(void)
This hook function is called just before the RKH takes over control of the application.
Describes the state machine.
Definition: rkhitl.h:2806
void rkh_sm_init(RKH_SM_T *me)
Inits a previously created state machine calling its initializing action.
Virtual table for the RKH_SMA_T structure.
Definition: rkhitl.h:3042
void rkh_sma_activate(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_RQNE_T qSize, void *stkSto, rui32_t stkSize)
Initializes and activates a previously created state machine application (SMA) as known as active obj...
RKHROM rui8_t rkh_maptbl[8]
rkh_maptbl[] is a table in ROM, used to equate an index from 0 to 7 to a bit mask.
void rkh_fwk_epool_register(void *sstart, rui32_t ssize, RKH_ES_T esize)
Registers a new event pool into the event pool list.
void rkh_hook_putTrcEvt(void)
This function is called from rkh_trc_end() function, at the end of that, to allow to the application ...
Defines the data structure into which the collected performance information for state machine is stor...
Definition: rkhitl.h:2712
RKH_SMA_T * rkh_sptbl[RKH_CFG_FWK_MAX_SMA]
Priority arranged table of registered SMA.
void rkh_fwk_gc(RKH_EVT_T *e)
Recycle a dynamic event.
void rkh_sma_post_fifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
Describes the history pseudostate.
Definition: rkhitl.h:3793
RKHROM char rkh_version[]
String describing the RKH version.
void rkh_sma_terminate(RKH_SMA_T *me)
Terminate a state machine application (SMA) as known as active object.
RKH_TS_T rkh_trc_getts(void)
Retrieves a timestamp to be placed in a trace event.
Definition: rkh.h:263
ruint rkh_sm_dispatch(RKH_SM_T *me, RKH_EVT_T *e)
Executes a state machine in a run-to-completation (RTC) model.
void rkh_fwk_reserve(RKH_EVT_T *e)
Reserve the dynamic event to be recycled.
void rkh_hook_timetick(void)
This function is called by rkh_tmr_tick(), which is assumed to be called from an ISR. rkh_hook_timetick() is called at the very beginning of rkh_tmr_tick(), to give priority to user or port-specific code when the tick interrupt occurs.
void rkh_hook_idle(void)
An idle hook function will only get executed (with interrupts LOCKED) when there are no SMAs of highe...
RKH_HPPTY_T
State machine properties.
Definition: rkh.h:248
Platform - independent interface for supporting software timer services.
rui8_t RKH_ES_T
Definition: rkhevt.h:108
void rkh_fwk_init(void)
Initializes the RKH framework.
#define RKH_CFG_FWK_MAX_SMA
Specify the maximum number of state machine applications (SMA) to be used by the application (can be ...
Definition: rkhcfg.h:86
void rkh_sma_clear_info(RKH_SMA_T *me)
Clear performance information for a particular state machine application (SMA) as known as active obj...
void rkh_sma_get_info(RKH_SMA_T *me, RKH_SMAI_T *psi)
Retrieves performance information for a particular state machine application (SMA) as known as active...
void rkh_fwk_exit(void)
Exit the RKH framework.
void rkh_tmr_tick(const void *const sender)
Keep tracks and updates the started timers.
void rkh_trc_flush(void)
Platform-dependent macro flushing the trace stream.
Definition: rkh.h:254
void rkh_hook_exit(void)
This hook function is called just before the RKH returns to the underlying OS/RTOS. Usually, the rkh_hook_exit() is useful when executing clean-up code upon SMA terminate or framework exit.
void rkh_trc_close(void)
Close the tracing session.
void rkh_hook_dispatch(RKH_SMA_T *me, RKH_EVT_T *e)
When dispatching an event to a SMA the dispatch hook function will be executed.
#define RKH_CFG_FWK_MAX_EVT_POOL
If the dynamic event support is enabled (see RKH_CFG_FWK_DYN_EVT_EN) then the RKH_CFG_FWK_MAX_EVT_POO...
Definition: rkhcfg.h:112
void rkh_fwk_defer(RKH_RQ_T *q, const RKH_EVT_T *e)
Defer an event to a given separate event queue.
void rkh_sma_register(RKH_SMA_T *me)
Registers a state machine application (SMA) as known as active object into the framework, which implies to store a pointer to the SMA in the priority table.