Guard.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "Guard.h"
  5. /*! \file Implementation of the state machine 'Guard'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean guard_check_main_region_A_tr0_tr0(const Guard* handle);
  9. static sc_boolean guard_check_main_region_A_tr1_tr1(const Guard* handle);
  10. static sc_boolean guard_check_main_region_B_tr0_tr0(const Guard* handle);
  11. static void guard_effect_main_region_A_tr0(Guard* handle);
  12. static void guard_effect_main_region_A_tr1(Guard* handle);
  13. static void guard_effect_main_region_B_tr0(Guard* handle);
  14. static void guard_enact_main_region_B(Guard* handle);
  15. static void guard_enseq_main_region_A_default(Guard* handle);
  16. static void guard_enseq_main_region_B_default(Guard* handle);
  17. static void guard_enseq_main_region_default(Guard* handle);
  18. static void guard_exseq_main_region_A(Guard* handle);
  19. static void guard_exseq_main_region_B(Guard* handle);
  20. static void guard_exseq_main_region(Guard* handle);
  21. static void guard_react_main_region_A(Guard* handle);
  22. static void guard_react_main_region_B(Guard* handle);
  23. static void guard_react_main_region__entry_Default(Guard* handle);
  24. static void guard_clearInEvents(Guard* handle);
  25. static void guard_clearOutEvents(Guard* handle);
  26. void guard_init(Guard* handle)
  27. {
  28. sc_integer i;
  29. for (i = 0; i < GUARD_MAX_ORTHOGONAL_STATES; ++i)
  30. {
  31. handle->stateConfVector[i] = Guard_last_state;
  32. }
  33. handle->stateConfVectorPosition = 0;
  34. guard_clearInEvents(handle);
  35. guard_clearOutEvents(handle);
  36. /* Default init sequence for statechart Guard */
  37. handle->iface.MyVar = 0;
  38. }
  39. void guard_enter(Guard* handle)
  40. {
  41. /* Default enter sequence for statechart Guard */
  42. guard_enseq_main_region_default(handle);
  43. }
  44. void guard_exit(Guard* handle)
  45. {
  46. /* Default exit sequence for statechart Guard */
  47. guard_exseq_main_region(handle);
  48. }
  49. sc_boolean guard_isActive(const Guard* handle)
  50. {
  51. sc_boolean result;
  52. if (handle->stateConfVector[0] != Guard_last_state)
  53. {
  54. result = bool_true;
  55. }
  56. else
  57. {
  58. result = bool_false;
  59. }
  60. return result;
  61. }
  62. /*
  63. * Always returns 'false' since this state machine can never become final.
  64. */
  65. sc_boolean guard_isFinal(const Guard* handle)
  66. {
  67. return bool_false;
  68. }
  69. static void guard_clearInEvents(Guard* handle)
  70. {
  71. handle->iface.Event1_raised = bool_false;
  72. handle->iface.Event2_raised = bool_false;
  73. handle->iface.Return_raised = bool_false;
  74. }
  75. static void guard_clearOutEvents(Guard* handle)
  76. {
  77. }
  78. void guard_runCycle(Guard* handle)
  79. {
  80. guard_clearOutEvents(handle);
  81. for (handle->stateConfVectorPosition = 0;
  82. handle->stateConfVectorPosition < GUARD_MAX_ORTHOGONAL_STATES;
  83. handle->stateConfVectorPosition++)
  84. {
  85. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  86. {
  87. case Guard_main_region_A :
  88. {
  89. guard_react_main_region_A(handle);
  90. break;
  91. }
  92. case Guard_main_region_B :
  93. {
  94. guard_react_main_region_B(handle);
  95. break;
  96. }
  97. default:
  98. break;
  99. }
  100. }
  101. guard_clearInEvents(handle);
  102. }
  103. sc_boolean guard_isStateActive(const Guard* handle, GuardStates state)
  104. {
  105. sc_boolean result = bool_false;
  106. switch (state)
  107. {
  108. case Guard_main_region_A :
  109. result = (sc_boolean) (handle->stateConfVector[0] == Guard_main_region_A
  110. );
  111. break;
  112. case Guard_main_region_B :
  113. result = (sc_boolean) (handle->stateConfVector[0] == Guard_main_region_B
  114. );
  115. break;
  116. default:
  117. result = bool_false;
  118. break;
  119. }
  120. return result;
  121. }
  122. void guardIface_raise_event1(Guard* handle)
  123. {
  124. handle->iface.Event1_raised = bool_true;
  125. }
  126. void guardIface_raise_event2(Guard* handle)
  127. {
  128. handle->iface.Event2_raised = bool_true;
  129. }
  130. void guardIface_raise_return(Guard* handle)
  131. {
  132. handle->iface.Return_raised = bool_true;
  133. }
  134. sc_integer guardIface_get_myVar(const Guard* handle)
  135. {
  136. return handle->iface.MyVar;
  137. }
  138. void guardIface_set_myVar(Guard* handle, sc_integer value)
  139. {
  140. handle->iface.MyVar = value;
  141. }
  142. /* implementations of all internal functions */
  143. static sc_boolean guard_check_main_region_A_tr0_tr0(const Guard* handle)
  144. {
  145. return ((handle->iface.Event1_raised) && (handle->iface.MyVar == 10)) ? bool_true : bool_false;
  146. }
  147. static sc_boolean guard_check_main_region_A_tr1_tr1(const Guard* handle)
  148. {
  149. return handle->iface.Event2_raised;
  150. }
  151. static sc_boolean guard_check_main_region_B_tr0_tr0(const Guard* handle)
  152. {
  153. return handle->iface.Return_raised;
  154. }
  155. static void guard_effect_main_region_A_tr0(Guard* handle)
  156. {
  157. guard_exseq_main_region_A(handle);
  158. guard_enseq_main_region_B_default(handle);
  159. }
  160. static void guard_effect_main_region_A_tr1(Guard* handle)
  161. {
  162. guard_exseq_main_region_A(handle);
  163. guard_enseq_main_region_B_default(handle);
  164. }
  165. static void guard_effect_main_region_B_tr0(Guard* handle)
  166. {
  167. guard_exseq_main_region_B(handle);
  168. guard_enseq_main_region_A_default(handle);
  169. }
  170. /* Entry action for state 'B'. */
  171. static void guard_enact_main_region_B(Guard* handle)
  172. {
  173. /* Entry action for state 'B'. */
  174. handle->iface.MyVar = 10;
  175. }
  176. /* 'default' enter sequence for state A */
  177. static void guard_enseq_main_region_A_default(Guard* handle)
  178. {
  179. /* 'default' enter sequence for state A */
  180. handle->stateConfVector[0] = Guard_main_region_A;
  181. handle->stateConfVectorPosition = 0;
  182. }
  183. /* 'default' enter sequence for state B */
  184. static void guard_enseq_main_region_B_default(Guard* handle)
  185. {
  186. /* 'default' enter sequence for state B */
  187. guard_enact_main_region_B(handle);
  188. handle->stateConfVector[0] = Guard_main_region_B;
  189. handle->stateConfVectorPosition = 0;
  190. }
  191. /* 'default' enter sequence for region main region */
  192. static void guard_enseq_main_region_default(Guard* handle)
  193. {
  194. /* 'default' enter sequence for region main region */
  195. guard_react_main_region__entry_Default(handle);
  196. }
  197. /* Default exit sequence for state A */
  198. static void guard_exseq_main_region_A(Guard* handle)
  199. {
  200. /* Default exit sequence for state A */
  201. handle->stateConfVector[0] = Guard_last_state;
  202. handle->stateConfVectorPosition = 0;
  203. }
  204. /* Default exit sequence for state B */
  205. static void guard_exseq_main_region_B(Guard* handle)
  206. {
  207. /* Default exit sequence for state B */
  208. handle->stateConfVector[0] = Guard_last_state;
  209. handle->stateConfVectorPosition = 0;
  210. }
  211. /* Default exit sequence for region main region */
  212. static void guard_exseq_main_region(Guard* handle)
  213. {
  214. /* Default exit sequence for region main region */
  215. /* Handle exit of all possible states (of Guard.main_region) at position 0... */
  216. switch(handle->stateConfVector[ 0 ])
  217. {
  218. case Guard_main_region_A :
  219. {
  220. guard_exseq_main_region_A(handle);
  221. break;
  222. }
  223. case Guard_main_region_B :
  224. {
  225. guard_exseq_main_region_B(handle);
  226. break;
  227. }
  228. default: break;
  229. }
  230. }
  231. /* The reactions of state A. */
  232. static void guard_react_main_region_A(Guard* handle)
  233. {
  234. /* The reactions of state A. */
  235. if (guard_check_main_region_A_tr0_tr0(handle) == bool_true)
  236. {
  237. guard_effect_main_region_A_tr0(handle);
  238. } else
  239. {
  240. if (guard_check_main_region_A_tr1_tr1(handle) == bool_true)
  241. {
  242. guard_effect_main_region_A_tr1(handle);
  243. }
  244. }
  245. }
  246. /* The reactions of state B. */
  247. static void guard_react_main_region_B(Guard* handle)
  248. {
  249. /* The reactions of state B. */
  250. if (guard_check_main_region_B_tr0_tr0(handle) == bool_true)
  251. {
  252. guard_effect_main_region_B_tr0(handle);
  253. }
  254. }
  255. /* Default react sequence for initial entry */
  256. static void guard_react_main_region__entry_Default(Guard* handle)
  257. {
  258. /* Default react sequence for initial entry */
  259. guard_enseq_main_region_A_default(handle);
  260. }