GuardedExit.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "GuardedExit.h"
  5. /*! \file Implementation of the state machine 'GuardedExit'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean guardedExit_check_main_region_A_tr0_tr0(const GuardedExit* handle);
  9. static sc_boolean guardedExit_check_main_region_B_tr0_tr0(const GuardedExit* handle);
  10. static void guardedExit_effect_main_region_A_tr0(GuardedExit* handle);
  11. static void guardedExit_effect_main_region_B_tr0(GuardedExit* handle);
  12. static void guardedExit_exact_main_region_A(GuardedExit* handle);
  13. static void guardedExit_enseq_main_region_A_default(GuardedExit* handle);
  14. static void guardedExit_enseq_main_region_B_default(GuardedExit* handle);
  15. static void guardedExit_enseq_main_region_default(GuardedExit* handle);
  16. static void guardedExit_exseq_main_region_A(GuardedExit* handle);
  17. static void guardedExit_exseq_main_region_B(GuardedExit* handle);
  18. static void guardedExit_exseq_main_region(GuardedExit* handle);
  19. static void guardedExit_react_main_region_A(GuardedExit* handle);
  20. static void guardedExit_react_main_region_B(GuardedExit* handle);
  21. static void guardedExit_react_main_region__entry_Default(GuardedExit* handle);
  22. static void guardedExit_clearInEvents(GuardedExit* handle);
  23. static void guardedExit_clearOutEvents(GuardedExit* handle);
  24. void guardedExit_init(GuardedExit* handle)
  25. {
  26. sc_integer i;
  27. for (i = 0; i < GUARDEDEXIT_MAX_ORTHOGONAL_STATES; ++i)
  28. {
  29. handle->stateConfVector[i] = GuardedExit_last_state;
  30. }
  31. handle->stateConfVectorPosition = 0;
  32. guardedExit_clearInEvents(handle);
  33. guardedExit_clearOutEvents(handle);
  34. /* Default init sequence for statechart GuardedExit */
  35. handle->iface.guard = bool_false;
  36. handle->iface.done = bool_false;
  37. }
  38. void guardedExit_enter(GuardedExit* handle)
  39. {
  40. /* Default enter sequence for statechart GuardedExit */
  41. guardedExit_enseq_main_region_default(handle);
  42. }
  43. void guardedExit_exit(GuardedExit* handle)
  44. {
  45. /* Default exit sequence for statechart GuardedExit */
  46. guardedExit_exseq_main_region(handle);
  47. }
  48. sc_boolean guardedExit_isActive(const GuardedExit* handle)
  49. {
  50. sc_boolean result;
  51. if (handle->stateConfVector[0] != GuardedExit_last_state)
  52. {
  53. result = bool_true;
  54. }
  55. else
  56. {
  57. result = bool_false;
  58. }
  59. return result;
  60. }
  61. /*
  62. * Always returns 'false' since this state machine can never become final.
  63. */
  64. sc_boolean guardedExit_isFinal(const GuardedExit* handle)
  65. {
  66. return bool_false;
  67. }
  68. static void guardedExit_clearInEvents(GuardedExit* handle)
  69. {
  70. handle->iface.e_raised = bool_false;
  71. }
  72. static void guardedExit_clearOutEvents(GuardedExit* handle)
  73. {
  74. }
  75. void guardedExit_runCycle(GuardedExit* handle)
  76. {
  77. guardedExit_clearOutEvents(handle);
  78. for (handle->stateConfVectorPosition = 0;
  79. handle->stateConfVectorPosition < GUARDEDEXIT_MAX_ORTHOGONAL_STATES;
  80. handle->stateConfVectorPosition++)
  81. {
  82. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  83. {
  84. case GuardedExit_main_region_A :
  85. {
  86. guardedExit_react_main_region_A(handle);
  87. break;
  88. }
  89. case GuardedExit_main_region_B :
  90. {
  91. guardedExit_react_main_region_B(handle);
  92. break;
  93. }
  94. default:
  95. break;
  96. }
  97. }
  98. guardedExit_clearInEvents(handle);
  99. }
  100. sc_boolean guardedExit_isStateActive(const GuardedExit* handle, GuardedExitStates state)
  101. {
  102. sc_boolean result = bool_false;
  103. switch (state)
  104. {
  105. case GuardedExit_main_region_A :
  106. result = (sc_boolean) (handle->stateConfVector[0] == GuardedExit_main_region_A
  107. );
  108. break;
  109. case GuardedExit_main_region_B :
  110. result = (sc_boolean) (handle->stateConfVector[0] == GuardedExit_main_region_B
  111. );
  112. break;
  113. default:
  114. result = bool_false;
  115. break;
  116. }
  117. return result;
  118. }
  119. void guardedExitIface_raise_e(GuardedExit* handle)
  120. {
  121. handle->iface.e_raised = bool_true;
  122. }
  123. sc_boolean guardedExitIface_get_guard(const GuardedExit* handle)
  124. {
  125. return handle->iface.guard;
  126. }
  127. void guardedExitIface_set_guard(GuardedExit* handle, sc_boolean value)
  128. {
  129. handle->iface.guard = value;
  130. }
  131. sc_boolean guardedExitIface_get_done(const GuardedExit* handle)
  132. {
  133. return handle->iface.done;
  134. }
  135. void guardedExitIface_set_done(GuardedExit* handle, sc_boolean value)
  136. {
  137. handle->iface.done = value;
  138. }
  139. /* implementations of all internal functions */
  140. static sc_boolean guardedExit_check_main_region_A_tr0_tr0(const GuardedExit* handle)
  141. {
  142. return handle->iface.e_raised;
  143. }
  144. static sc_boolean guardedExit_check_main_region_B_tr0_tr0(const GuardedExit* handle)
  145. {
  146. return handle->iface.e_raised;
  147. }
  148. static void guardedExit_effect_main_region_A_tr0(GuardedExit* handle)
  149. {
  150. guardedExit_exseq_main_region_A(handle);
  151. guardedExit_enseq_main_region_B_default(handle);
  152. }
  153. static void guardedExit_effect_main_region_B_tr0(GuardedExit* handle)
  154. {
  155. guardedExit_exseq_main_region_B(handle);
  156. guardedExit_enseq_main_region_A_default(handle);
  157. }
  158. /* Exit action for state 'A'. */
  159. static void guardedExit_exact_main_region_A(GuardedExit* handle)
  160. {
  161. /* Exit action for state 'A'. */
  162. if (handle->iface.guard == bool_true)
  163. {
  164. handle->iface.done = bool_true;
  165. }
  166. }
  167. /* 'default' enter sequence for state A */
  168. static void guardedExit_enseq_main_region_A_default(GuardedExit* handle)
  169. {
  170. /* 'default' enter sequence for state A */
  171. handle->stateConfVector[0] = GuardedExit_main_region_A;
  172. handle->stateConfVectorPosition = 0;
  173. }
  174. /* 'default' enter sequence for state B */
  175. static void guardedExit_enseq_main_region_B_default(GuardedExit* handle)
  176. {
  177. /* 'default' enter sequence for state B */
  178. handle->stateConfVector[0] = GuardedExit_main_region_B;
  179. handle->stateConfVectorPosition = 0;
  180. }
  181. /* 'default' enter sequence for region main region */
  182. static void guardedExit_enseq_main_region_default(GuardedExit* handle)
  183. {
  184. /* 'default' enter sequence for region main region */
  185. guardedExit_react_main_region__entry_Default(handle);
  186. }
  187. /* Default exit sequence for state A */
  188. static void guardedExit_exseq_main_region_A(GuardedExit* handle)
  189. {
  190. /* Default exit sequence for state A */
  191. handle->stateConfVector[0] = GuardedExit_last_state;
  192. handle->stateConfVectorPosition = 0;
  193. guardedExit_exact_main_region_A(handle);
  194. }
  195. /* Default exit sequence for state B */
  196. static void guardedExit_exseq_main_region_B(GuardedExit* handle)
  197. {
  198. /* Default exit sequence for state B */
  199. handle->stateConfVector[0] = GuardedExit_last_state;
  200. handle->stateConfVectorPosition = 0;
  201. }
  202. /* Default exit sequence for region main region */
  203. static void guardedExit_exseq_main_region(GuardedExit* handle)
  204. {
  205. /* Default exit sequence for region main region */
  206. /* Handle exit of all possible states (of GuardedExit.main_region) at position 0... */
  207. switch(handle->stateConfVector[ 0 ])
  208. {
  209. case GuardedExit_main_region_A :
  210. {
  211. guardedExit_exseq_main_region_A(handle);
  212. break;
  213. }
  214. case GuardedExit_main_region_B :
  215. {
  216. guardedExit_exseq_main_region_B(handle);
  217. break;
  218. }
  219. default: break;
  220. }
  221. }
  222. /* The reactions of state A. */
  223. static void guardedExit_react_main_region_A(GuardedExit* handle)
  224. {
  225. /* The reactions of state A. */
  226. if (guardedExit_check_main_region_A_tr0_tr0(handle) == bool_true)
  227. {
  228. guardedExit_effect_main_region_A_tr0(handle);
  229. }
  230. }
  231. /* The reactions of state B. */
  232. static void guardedExit_react_main_region_B(GuardedExit* handle)
  233. {
  234. /* The reactions of state B. */
  235. if (guardedExit_check_main_region_B_tr0_tr0(handle) == bool_true)
  236. {
  237. guardedExit_effect_main_region_B_tr0(handle);
  238. }
  239. }
  240. /* Default react sequence for initial entry */
  241. static void guardedExit_react_main_region__entry_Default(GuardedExit* handle)
  242. {
  243. /* Default react sequence for initial entry */
  244. guardedExit_enseq_main_region_A_default(handle);
  245. }