Choice.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "Choice.h"
  5. /*! \file Implementation of the state machine 'Choice'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean choice_check_main_region_A_tr0_tr0(const Choice* handle);
  9. static sc_boolean choice_check_main_region_A_tr1_tr1(const Choice* handle);
  10. static sc_boolean choice_check_main_region_A_tr2_tr2(const Choice* handle);
  11. static sc_boolean choice_check_main_region_A_tr3_tr3(const Choice* handle);
  12. static sc_boolean choice_check_main_region_B_tr0_tr0(const Choice* handle);
  13. static sc_boolean choice_check_main_region_C_tr0_tr0(const Choice* handle);
  14. static sc_boolean choice_check_main_region__choice_0_tr1_tr1(const Choice* handle);
  15. static sc_boolean choice_check_main_region__choice_0_tr0_tr0(const Choice* handle);
  16. static sc_boolean choice_check_main_region__choice_1_tr0_tr0(const Choice* handle);
  17. static sc_boolean choice_check_main_region__choice_1_tr1_tr1(const Choice* handle);
  18. static sc_boolean choice_check_main_region__choice_2_tr1_tr1(const Choice* handle);
  19. static sc_boolean choice_check_main_region__choice_2_tr0(const Choice* handle);
  20. static sc_boolean choice_check_main_region__choice_3_tr1_tr1(const Choice* handle);
  21. static sc_boolean choice_check_main_region__choice_3_tr0_tr0(const Choice* handle);
  22. static void choice_effect_main_region_A_tr0(Choice* handle);
  23. static void choice_effect_main_region_A_tr1(Choice* handle);
  24. static void choice_effect_main_region_A_tr2(Choice* handle);
  25. static void choice_effect_main_region_A_tr3(Choice* handle);
  26. static void choice_effect_main_region_B_tr0(Choice* handle);
  27. static void choice_effect_main_region_C_tr0(Choice* handle);
  28. static void choice_effect_main_region__choice_0_tr1(Choice* handle);
  29. static void choice_effect_main_region__choice_0_tr0(Choice* handle);
  30. static void choice_effect_main_region__choice_1_tr0(Choice* handle);
  31. static void choice_effect_main_region__choice_1_tr1(Choice* handle);
  32. static void choice_effect_main_region__choice_2_tr1(Choice* handle);
  33. static void choice_effect_main_region__choice_2_tr0(Choice* handle);
  34. static void choice_effect_main_region__choice_3_tr1(Choice* handle);
  35. static void choice_effect_main_region__choice_3_tr0(Choice* handle);
  36. static void choice_enseq_main_region_A_default(Choice* handle);
  37. static void choice_enseq_main_region_B_default(Choice* handle);
  38. static void choice_enseq_main_region_C_default(Choice* handle);
  39. static void choice_enseq_main_region_default(Choice* handle);
  40. static void choice_exseq_main_region_A(Choice* handle);
  41. static void choice_exseq_main_region_B(Choice* handle);
  42. static void choice_exseq_main_region_C(Choice* handle);
  43. static void choice_exseq_main_region(Choice* handle);
  44. static void choice_react_main_region_A(Choice* handle);
  45. static void choice_react_main_region_B(Choice* handle);
  46. static void choice_react_main_region_C(Choice* handle);
  47. static void choice_react_main_region__choice_0(Choice* handle);
  48. static void choice_react_main_region__choice_1(Choice* handle);
  49. static void choice_react_main_region__choice_2(Choice* handle);
  50. static void choice_react_main_region__choice_3(Choice* handle);
  51. static void choice_react_main_region__entry_Default(Choice* handle);
  52. static void choice_clearInEvents(Choice* handle);
  53. static void choice_clearOutEvents(Choice* handle);
  54. void choice_init(Choice* handle)
  55. {
  56. sc_integer i;
  57. for (i = 0; i < CHOICE_MAX_ORTHOGONAL_STATES; ++i)
  58. {
  59. handle->stateConfVector[i] = Choice_last_state;
  60. }
  61. handle->stateConfVectorPosition = 0;
  62. choice_clearInEvents(handle);
  63. choice_clearOutEvents(handle);
  64. /* Default init sequence for statechart Choice */
  65. handle->iface.c = bool_false;
  66. }
  67. void choice_enter(Choice* handle)
  68. {
  69. /* Default enter sequence for statechart Choice */
  70. choice_enseq_main_region_default(handle);
  71. }
  72. void choice_exit(Choice* handle)
  73. {
  74. /* Default exit sequence for statechart Choice */
  75. choice_exseq_main_region(handle);
  76. }
  77. sc_boolean choice_isActive(const Choice* handle)
  78. {
  79. sc_boolean result;
  80. if (handle->stateConfVector[0] != Choice_last_state)
  81. {
  82. result = bool_true;
  83. }
  84. else
  85. {
  86. result = bool_false;
  87. }
  88. return result;
  89. }
  90. /*
  91. * Always returns 'false' since this state machine can never become final.
  92. */
  93. sc_boolean choice_isFinal(const Choice* handle)
  94. {
  95. return bool_false;
  96. }
  97. static void choice_clearInEvents(Choice* handle)
  98. {
  99. handle->iface.e_raised = bool_false;
  100. handle->iface.f_raised = bool_false;
  101. handle->iface.g_raised = bool_false;
  102. handle->iface.h_raised = bool_false;
  103. }
  104. static void choice_clearOutEvents(Choice* handle)
  105. {
  106. }
  107. void choice_runCycle(Choice* handle)
  108. {
  109. choice_clearOutEvents(handle);
  110. for (handle->stateConfVectorPosition = 0;
  111. handle->stateConfVectorPosition < CHOICE_MAX_ORTHOGONAL_STATES;
  112. handle->stateConfVectorPosition++)
  113. {
  114. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  115. {
  116. case Choice_main_region_A :
  117. {
  118. choice_react_main_region_A(handle);
  119. break;
  120. }
  121. case Choice_main_region_B :
  122. {
  123. choice_react_main_region_B(handle);
  124. break;
  125. }
  126. case Choice_main_region_C :
  127. {
  128. choice_react_main_region_C(handle);
  129. break;
  130. }
  131. default:
  132. break;
  133. }
  134. }
  135. choice_clearInEvents(handle);
  136. }
  137. sc_boolean choice_isStateActive(const Choice* handle, ChoiceStates state)
  138. {
  139. sc_boolean result = bool_false;
  140. switch (state)
  141. {
  142. case Choice_main_region_A :
  143. result = (sc_boolean) (handle->stateConfVector[0] == Choice_main_region_A
  144. );
  145. break;
  146. case Choice_main_region_B :
  147. result = (sc_boolean) (handle->stateConfVector[0] == Choice_main_region_B
  148. );
  149. break;
  150. case Choice_main_region_C :
  151. result = (sc_boolean) (handle->stateConfVector[0] == Choice_main_region_C
  152. );
  153. break;
  154. default:
  155. result = bool_false;
  156. break;
  157. }
  158. return result;
  159. }
  160. void choiceIface_raise_e(Choice* handle)
  161. {
  162. handle->iface.e_raised = bool_true;
  163. }
  164. void choiceIface_raise_f(Choice* handle)
  165. {
  166. handle->iface.f_raised = bool_true;
  167. }
  168. void choiceIface_raise_g(Choice* handle)
  169. {
  170. handle->iface.g_raised = bool_true;
  171. }
  172. void choiceIface_raise_h(Choice* handle)
  173. {
  174. handle->iface.h_raised = bool_true;
  175. }
  176. sc_boolean choiceIface_get_c(const Choice* handle)
  177. {
  178. return handle->iface.c;
  179. }
  180. void choiceIface_set_c(Choice* handle, sc_boolean value)
  181. {
  182. handle->iface.c = value;
  183. }
  184. /* implementations of all internal functions */
  185. static sc_boolean choice_check_main_region_A_tr0_tr0(const Choice* handle)
  186. {
  187. return handle->iface.e_raised;
  188. }
  189. static sc_boolean choice_check_main_region_A_tr1_tr1(const Choice* handle)
  190. {
  191. return handle->iface.f_raised;
  192. }
  193. static sc_boolean choice_check_main_region_A_tr2_tr2(const Choice* handle)
  194. {
  195. return handle->iface.g_raised;
  196. }
  197. static sc_boolean choice_check_main_region_A_tr3_tr3(const Choice* handle)
  198. {
  199. return handle->iface.h_raised;
  200. }
  201. static sc_boolean choice_check_main_region_B_tr0_tr0(const Choice* handle)
  202. {
  203. return bool_true;
  204. }
  205. static sc_boolean choice_check_main_region_C_tr0_tr0(const Choice* handle)
  206. {
  207. return bool_true;
  208. }
  209. static sc_boolean choice_check_main_region__choice_0_tr1_tr1(const Choice* handle)
  210. {
  211. return handle->iface.c;
  212. }
  213. static sc_boolean choice_check_main_region__choice_0_tr0_tr0(const Choice* handle)
  214. {
  215. return bool_true;
  216. }
  217. static sc_boolean choice_check_main_region__choice_1_tr0_tr0(const Choice* handle)
  218. {
  219. return handle->iface.c;
  220. }
  221. static sc_boolean choice_check_main_region__choice_1_tr1_tr1(const Choice* handle)
  222. {
  223. return bool_true;
  224. }
  225. static sc_boolean choice_check_main_region__choice_2_tr1_tr1(const Choice* handle)
  226. {
  227. return handle->iface.c;
  228. }
  229. static sc_boolean choice_check_main_region__choice_2_tr0(const Choice* handle)
  230. {
  231. return bool_true;
  232. }
  233. static sc_boolean choice_check_main_region__choice_3_tr1_tr1(const Choice* handle)
  234. {
  235. return handle->iface.c;
  236. }
  237. static sc_boolean choice_check_main_region__choice_3_tr0_tr0(const Choice* handle)
  238. {
  239. return bool_true;
  240. }
  241. static void choice_effect_main_region_A_tr0(Choice* handle)
  242. {
  243. choice_exseq_main_region_A(handle);
  244. choice_react_main_region__choice_0(handle);
  245. }
  246. static void choice_effect_main_region_A_tr1(Choice* handle)
  247. {
  248. choice_exseq_main_region_A(handle);
  249. choice_react_main_region__choice_2(handle);
  250. }
  251. static void choice_effect_main_region_A_tr2(Choice* handle)
  252. {
  253. choice_exseq_main_region_A(handle);
  254. choice_react_main_region__choice_1(handle);
  255. }
  256. static void choice_effect_main_region_A_tr3(Choice* handle)
  257. {
  258. choice_exseq_main_region_A(handle);
  259. choice_react_main_region__choice_3(handle);
  260. }
  261. static void choice_effect_main_region_B_tr0(Choice* handle)
  262. {
  263. choice_exseq_main_region_B(handle);
  264. choice_enseq_main_region_A_default(handle);
  265. }
  266. static void choice_effect_main_region_C_tr0(Choice* handle)
  267. {
  268. choice_exseq_main_region_C(handle);
  269. choice_enseq_main_region_A_default(handle);
  270. }
  271. static void choice_effect_main_region__choice_0_tr1(Choice* handle)
  272. {
  273. choice_enseq_main_region_C_default(handle);
  274. }
  275. static void choice_effect_main_region__choice_0_tr0(Choice* handle)
  276. {
  277. choice_enseq_main_region_B_default(handle);
  278. }
  279. static void choice_effect_main_region__choice_1_tr0(Choice* handle)
  280. {
  281. choice_enseq_main_region_C_default(handle);
  282. }
  283. static void choice_effect_main_region__choice_1_tr1(Choice* handle)
  284. {
  285. choice_enseq_main_region_B_default(handle);
  286. }
  287. static void choice_effect_main_region__choice_2_tr1(Choice* handle)
  288. {
  289. choice_enseq_main_region_C_default(handle);
  290. }
  291. static void choice_effect_main_region__choice_2_tr0(Choice* handle)
  292. {
  293. choice_enseq_main_region_B_default(handle);
  294. }
  295. static void choice_effect_main_region__choice_3_tr1(Choice* handle)
  296. {
  297. choice_enseq_main_region_C_default(handle);
  298. }
  299. static void choice_effect_main_region__choice_3_tr0(Choice* handle)
  300. {
  301. choice_enseq_main_region_B_default(handle);
  302. }
  303. /* 'default' enter sequence for state A */
  304. static void choice_enseq_main_region_A_default(Choice* handle)
  305. {
  306. /* 'default' enter sequence for state A */
  307. handle->stateConfVector[0] = Choice_main_region_A;
  308. handle->stateConfVectorPosition = 0;
  309. }
  310. /* 'default' enter sequence for state B */
  311. static void choice_enseq_main_region_B_default(Choice* handle)
  312. {
  313. /* 'default' enter sequence for state B */
  314. handle->stateConfVector[0] = Choice_main_region_B;
  315. handle->stateConfVectorPosition = 0;
  316. }
  317. /* 'default' enter sequence for state C */
  318. static void choice_enseq_main_region_C_default(Choice* handle)
  319. {
  320. /* 'default' enter sequence for state C */
  321. handle->stateConfVector[0] = Choice_main_region_C;
  322. handle->stateConfVectorPosition = 0;
  323. }
  324. /* 'default' enter sequence for region main region */
  325. static void choice_enseq_main_region_default(Choice* handle)
  326. {
  327. /* 'default' enter sequence for region main region */
  328. choice_react_main_region__entry_Default(handle);
  329. }
  330. /* Default exit sequence for state A */
  331. static void choice_exseq_main_region_A(Choice* handle)
  332. {
  333. /* Default exit sequence for state A */
  334. handle->stateConfVector[0] = Choice_last_state;
  335. handle->stateConfVectorPosition = 0;
  336. }
  337. /* Default exit sequence for state B */
  338. static void choice_exseq_main_region_B(Choice* handle)
  339. {
  340. /* Default exit sequence for state B */
  341. handle->stateConfVector[0] = Choice_last_state;
  342. handle->stateConfVectorPosition = 0;
  343. }
  344. /* Default exit sequence for state C */
  345. static void choice_exseq_main_region_C(Choice* handle)
  346. {
  347. /* Default exit sequence for state C */
  348. handle->stateConfVector[0] = Choice_last_state;
  349. handle->stateConfVectorPosition = 0;
  350. }
  351. /* Default exit sequence for region main region */
  352. static void choice_exseq_main_region(Choice* handle)
  353. {
  354. /* Default exit sequence for region main region */
  355. /* Handle exit of all possible states (of Choice.main_region) at position 0... */
  356. switch(handle->stateConfVector[ 0 ])
  357. {
  358. case Choice_main_region_A :
  359. {
  360. choice_exseq_main_region_A(handle);
  361. break;
  362. }
  363. case Choice_main_region_B :
  364. {
  365. choice_exseq_main_region_B(handle);
  366. break;
  367. }
  368. case Choice_main_region_C :
  369. {
  370. choice_exseq_main_region_C(handle);
  371. break;
  372. }
  373. default: break;
  374. }
  375. }
  376. /* The reactions of state A. */
  377. static void choice_react_main_region_A(Choice* handle)
  378. {
  379. /* The reactions of state A. */
  380. if (choice_check_main_region_A_tr0_tr0(handle) == bool_true)
  381. {
  382. choice_effect_main_region_A_tr0(handle);
  383. } else
  384. {
  385. if (choice_check_main_region_A_tr1_tr1(handle) == bool_true)
  386. {
  387. choice_effect_main_region_A_tr1(handle);
  388. } else
  389. {
  390. if (choice_check_main_region_A_tr2_tr2(handle) == bool_true)
  391. {
  392. choice_effect_main_region_A_tr2(handle);
  393. } else
  394. {
  395. if (choice_check_main_region_A_tr3_tr3(handle) == bool_true)
  396. {
  397. choice_effect_main_region_A_tr3(handle);
  398. }
  399. }
  400. }
  401. }
  402. }
  403. /* The reactions of state B. */
  404. static void choice_react_main_region_B(Choice* handle)
  405. {
  406. /* The reactions of state B. */
  407. choice_effect_main_region_B_tr0(handle);
  408. }
  409. /* The reactions of state C. */
  410. static void choice_react_main_region_C(Choice* handle)
  411. {
  412. /* The reactions of state C. */
  413. choice_effect_main_region_C_tr0(handle);
  414. }
  415. /* The reactions of state null. */
  416. static void choice_react_main_region__choice_0(Choice* handle)
  417. {
  418. /* The reactions of state null. */
  419. if (choice_check_main_region__choice_0_tr1_tr1(handle) == bool_true)
  420. {
  421. choice_effect_main_region__choice_0_tr1(handle);
  422. } else
  423. {
  424. choice_effect_main_region__choice_0_tr0(handle);
  425. }
  426. }
  427. /* The reactions of state null. */
  428. static void choice_react_main_region__choice_1(Choice* handle)
  429. {
  430. /* The reactions of state null. */
  431. if (choice_check_main_region__choice_1_tr0_tr0(handle) == bool_true)
  432. {
  433. choice_effect_main_region__choice_1_tr0(handle);
  434. } else
  435. {
  436. choice_effect_main_region__choice_1_tr1(handle);
  437. }
  438. }
  439. /* The reactions of state null. */
  440. static void choice_react_main_region__choice_2(Choice* handle)
  441. {
  442. /* The reactions of state null. */
  443. if (choice_check_main_region__choice_2_tr1_tr1(handle) == bool_true)
  444. {
  445. choice_effect_main_region__choice_2_tr1(handle);
  446. } else
  447. {
  448. choice_effect_main_region__choice_2_tr0(handle);
  449. }
  450. }
  451. /* The reactions of state null. */
  452. static void choice_react_main_region__choice_3(Choice* handle)
  453. {
  454. /* The reactions of state null. */
  455. if (choice_check_main_region__choice_3_tr1_tr1(handle) == bool_true)
  456. {
  457. choice_effect_main_region__choice_3_tr1(handle);
  458. } else
  459. {
  460. choice_effect_main_region__choice_3_tr0(handle);
  461. }
  462. }
  463. /* Default react sequence for initial entry */
  464. static void choice_react_main_region__entry_Default(Choice* handle)
  465. {
  466. /* Default react sequence for initial entry */
  467. choice_enseq_main_region_A_default(handle);
  468. }