SyncJoin.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "SyncJoin.h"
  5. /*! \file Implementation of the state machine 'SyncJoin'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean syncJoin_check_main_region_A_tr0_tr0(const SyncJoin* handle);
  9. static sc_boolean syncJoin_check_main_region_B_r1_C1_tr0_tr0(const SyncJoin* handle);
  10. static sc_boolean syncJoin_check_main_region_B_r1_C2_tr0_tr0(const SyncJoin* handle);
  11. static sc_boolean syncJoin_check_main_region_B_r2_D1_tr0_tr0(const SyncJoin* handle);
  12. static sc_boolean syncJoin_check_main_region_B_r2_D2_tr0_tr0(const SyncJoin* handle);
  13. static void syncJoin_effect_main_region_A_tr0(SyncJoin* handle);
  14. static void syncJoin_effect_main_region_B_r1_C1_tr0(SyncJoin* handle);
  15. static void syncJoin_effect_main_region_B_r1_C2_tr0(SyncJoin* handle);
  16. static void syncJoin_effect_main_region_B_r2_D1_tr0(SyncJoin* handle);
  17. static void syncJoin_effect_main_region_B_r2_D2_tr0(SyncJoin* handle);
  18. static void syncJoin_enact_main_region_A(SyncJoin* handle);
  19. static void syncJoin_enseq_main_region_A_default(SyncJoin* handle);
  20. static void syncJoin_enseq_main_region_B_default(SyncJoin* handle);
  21. static void syncJoin_enseq_main_region_B_r1_C1_default(SyncJoin* handle);
  22. static void syncJoin_enseq_main_region_B_r1_C2_default(SyncJoin* handle);
  23. static void syncJoin_enseq_main_region_B_r2_D1_default(SyncJoin* handle);
  24. static void syncJoin_enseq_main_region_B_r2_D2_default(SyncJoin* handle);
  25. static void syncJoin_enseq_main_region_default(SyncJoin* handle);
  26. static void syncJoin_enseq_main_region_B_r1_default(SyncJoin* handle);
  27. static void syncJoin_enseq_main_region_B_r2_default(SyncJoin* handle);
  28. static void syncJoin_exseq_main_region_A(SyncJoin* handle);
  29. static void syncJoin_exseq_main_region_B(SyncJoin* handle);
  30. static void syncJoin_exseq_main_region_B_r1_C1(SyncJoin* handle);
  31. static void syncJoin_exseq_main_region_B_r1_C2(SyncJoin* handle);
  32. static void syncJoin_exseq_main_region_B_r2_D1(SyncJoin* handle);
  33. static void syncJoin_exseq_main_region_B_r2_D2(SyncJoin* handle);
  34. static void syncJoin_exseq_main_region(SyncJoin* handle);
  35. static void syncJoin_exseq_main_region_B_r1(SyncJoin* handle);
  36. static void syncJoin_exseq_main_region_B_r2(SyncJoin* handle);
  37. static void syncJoin_react_main_region_A(SyncJoin* handle);
  38. static void syncJoin_react_main_region_B_r1_C1(SyncJoin* handle);
  39. static void syncJoin_react_main_region_B_r1_C2(SyncJoin* handle);
  40. static void syncJoin_react_main_region_B_r2_D1(SyncJoin* handle);
  41. static void syncJoin_react_main_region_B_r2_D2(SyncJoin* handle);
  42. static void syncJoin_react_main_region__entry_Default(SyncJoin* handle);
  43. static void syncJoin_react_main_region_B_r1__entry_Default(SyncJoin* handle);
  44. static void syncJoin_react_main_region_B_r2__entry_Default(SyncJoin* handle);
  45. static void syncJoin_react_main_region__sync0(SyncJoin* handle);
  46. static void syncJoin_clearInEvents(SyncJoin* handle);
  47. static void syncJoin_clearOutEvents(SyncJoin* handle);
  48. void syncJoin_init(SyncJoin* handle)
  49. {
  50. sc_integer i;
  51. for (i = 0; i < SYNCJOIN_MAX_ORTHOGONAL_STATES; ++i)
  52. {
  53. handle->stateConfVector[i] = SyncJoin_last_state;
  54. }
  55. handle->stateConfVectorPosition = 0;
  56. syncJoin_clearInEvents(handle);
  57. syncJoin_clearOutEvents(handle);
  58. /* Default init sequence for statechart SyncJoin */
  59. handle->iface.x = 0;
  60. }
  61. void syncJoin_enter(SyncJoin* handle)
  62. {
  63. /* Default enter sequence for statechart SyncJoin */
  64. syncJoin_enseq_main_region_default(handle);
  65. }
  66. void syncJoin_exit(SyncJoin* handle)
  67. {
  68. /* Default exit sequence for statechart SyncJoin */
  69. syncJoin_exseq_main_region(handle);
  70. }
  71. sc_boolean syncJoin_isActive(const SyncJoin* handle)
  72. {
  73. sc_boolean result = bool_false;
  74. int i;
  75. for(i = 0; i < SYNCJOIN_MAX_ORTHOGONAL_STATES; i++)
  76. {
  77. result = result || handle->stateConfVector[i] != SyncJoin_last_state;
  78. }
  79. return result;
  80. }
  81. /*
  82. * Always returns 'false' since this state machine can never become final.
  83. */
  84. sc_boolean syncJoin_isFinal(const SyncJoin* handle)
  85. {
  86. return bool_false;
  87. }
  88. static void syncJoin_clearInEvents(SyncJoin* handle)
  89. {
  90. handle->iface.e_raised = bool_false;
  91. handle->iface.f_raised = bool_false;
  92. handle->iface.jc_raised = bool_false;
  93. handle->iface.jd_raised = bool_false;
  94. }
  95. static void syncJoin_clearOutEvents(SyncJoin* handle)
  96. {
  97. }
  98. void syncJoin_runCycle(SyncJoin* handle)
  99. {
  100. syncJoin_clearOutEvents(handle);
  101. for (handle->stateConfVectorPosition = 0;
  102. handle->stateConfVectorPosition < SYNCJOIN_MAX_ORTHOGONAL_STATES;
  103. handle->stateConfVectorPosition++)
  104. {
  105. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  106. {
  107. case SyncJoin_main_region_A :
  108. {
  109. syncJoin_react_main_region_A(handle);
  110. break;
  111. }
  112. case SyncJoin_main_region_B_r1_C1 :
  113. {
  114. syncJoin_react_main_region_B_r1_C1(handle);
  115. break;
  116. }
  117. case SyncJoin_main_region_B_r1_C2 :
  118. {
  119. syncJoin_react_main_region_B_r1_C2(handle);
  120. break;
  121. }
  122. case SyncJoin_main_region_B_r2_D1 :
  123. {
  124. syncJoin_react_main_region_B_r2_D1(handle);
  125. break;
  126. }
  127. case SyncJoin_main_region_B_r2_D2 :
  128. {
  129. syncJoin_react_main_region_B_r2_D2(handle);
  130. break;
  131. }
  132. default:
  133. break;
  134. }
  135. }
  136. syncJoin_clearInEvents(handle);
  137. }
  138. sc_boolean syncJoin_isStateActive(const SyncJoin* handle, SyncJoinStates state)
  139. {
  140. sc_boolean result = bool_false;
  141. switch (state)
  142. {
  143. case SyncJoin_main_region_A :
  144. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_A] == SyncJoin_main_region_A
  145. );
  146. break;
  147. case SyncJoin_main_region_B :
  148. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B] >= SyncJoin_main_region_B
  149. && handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B] <= SyncJoin_main_region_B_r2_D2);
  150. break;
  151. case SyncJoin_main_region_B_r1_C1 :
  152. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B_R1_C1] == SyncJoin_main_region_B_r1_C1
  153. );
  154. break;
  155. case SyncJoin_main_region_B_r1_C2 :
  156. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B_R1_C2] == SyncJoin_main_region_B_r1_C2
  157. );
  158. break;
  159. case SyncJoin_main_region_B_r2_D1 :
  160. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B_R2_D1] == SyncJoin_main_region_B_r2_D1
  161. );
  162. break;
  163. case SyncJoin_main_region_B_r2_D2 :
  164. result = (sc_boolean) (handle->stateConfVector[SCVI_SYNCJOIN_MAIN_REGION_B_R2_D2] == SyncJoin_main_region_B_r2_D2
  165. );
  166. break;
  167. default:
  168. result = bool_false;
  169. break;
  170. }
  171. return result;
  172. }
  173. void syncJoinIface_raise_e(SyncJoin* handle)
  174. {
  175. handle->iface.e_raised = bool_true;
  176. }
  177. void syncJoinIface_raise_f(SyncJoin* handle)
  178. {
  179. handle->iface.f_raised = bool_true;
  180. }
  181. void syncJoinIface_raise_jc(SyncJoin* handle)
  182. {
  183. handle->iface.jc_raised = bool_true;
  184. }
  185. void syncJoinIface_raise_jd(SyncJoin* handle)
  186. {
  187. handle->iface.jd_raised = bool_true;
  188. }
  189. sc_integer syncJoinIface_get_x(const SyncJoin* handle)
  190. {
  191. return handle->iface.x;
  192. }
  193. void syncJoinIface_set_x(SyncJoin* handle, sc_integer value)
  194. {
  195. handle->iface.x = value;
  196. }
  197. /* implementations of all internal functions */
  198. static sc_boolean syncJoin_check_main_region_A_tr0_tr0(const SyncJoin* handle)
  199. {
  200. return (handle->iface.e_raised || handle->iface.f_raised) ? bool_true : bool_false;
  201. }
  202. static sc_boolean syncJoin_check_main_region_B_r1_C1_tr0_tr0(const SyncJoin* handle)
  203. {
  204. return handle->iface.e_raised;
  205. }
  206. static sc_boolean syncJoin_check_main_region_B_r1_C2_tr0_tr0(const SyncJoin* handle)
  207. {
  208. return (handle->iface.jc_raised && syncJoin_isStateActive(handle, SyncJoin_main_region_B_r2_D2) && handle->iface.jd_raised) ? bool_true : bool_false;
  209. }
  210. static sc_boolean syncJoin_check_main_region_B_r2_D1_tr0_tr0(const SyncJoin* handle)
  211. {
  212. return handle->iface.f_raised;
  213. }
  214. static sc_boolean syncJoin_check_main_region_B_r2_D2_tr0_tr0(const SyncJoin* handle)
  215. {
  216. return (handle->iface.jd_raised && syncJoin_isStateActive(handle, SyncJoin_main_region_B_r1_C2) && handle->iface.jc_raised) ? bool_true : bool_false;
  217. }
  218. static void syncJoin_effect_main_region_A_tr0(SyncJoin* handle)
  219. {
  220. syncJoin_exseq_main_region_A(handle);
  221. syncJoin_enseq_main_region_B_default(handle);
  222. }
  223. static void syncJoin_effect_main_region_B_r1_C1_tr0(SyncJoin* handle)
  224. {
  225. syncJoin_exseq_main_region_B_r1_C1(handle);
  226. syncJoin_enseq_main_region_B_r1_C2_default(handle);
  227. }
  228. static void syncJoin_effect_main_region_B_r1_C2_tr0(SyncJoin* handle)
  229. {
  230. syncJoin_exseq_main_region_B(handle);
  231. syncJoin_react_main_region__sync0(handle);
  232. }
  233. static void syncJoin_effect_main_region_B_r2_D1_tr0(SyncJoin* handle)
  234. {
  235. syncJoin_exseq_main_region_B_r2_D1(handle);
  236. syncJoin_enseq_main_region_B_r2_D2_default(handle);
  237. }
  238. static void syncJoin_effect_main_region_B_r2_D2_tr0(SyncJoin* handle)
  239. {
  240. syncJoin_exseq_main_region_B(handle);
  241. syncJoin_react_main_region__sync0(handle);
  242. }
  243. /* Entry action for state 'A'. */
  244. static void syncJoin_enact_main_region_A(SyncJoin* handle)
  245. {
  246. /* Entry action for state 'A'. */
  247. handle->iface.x += 1;
  248. }
  249. /* 'default' enter sequence for state A */
  250. static void syncJoin_enseq_main_region_A_default(SyncJoin* handle)
  251. {
  252. /* 'default' enter sequence for state A */
  253. syncJoin_enact_main_region_A(handle);
  254. handle->stateConfVector[0] = SyncJoin_main_region_A;
  255. handle->stateConfVectorPosition = 0;
  256. }
  257. /* 'default' enter sequence for state B */
  258. static void syncJoin_enseq_main_region_B_default(SyncJoin* handle)
  259. {
  260. /* 'default' enter sequence for state B */
  261. syncJoin_enseq_main_region_B_r1_default(handle);
  262. syncJoin_enseq_main_region_B_r2_default(handle);
  263. }
  264. /* 'default' enter sequence for state C1 */
  265. static void syncJoin_enseq_main_region_B_r1_C1_default(SyncJoin* handle)
  266. {
  267. /* 'default' enter sequence for state C1 */
  268. handle->stateConfVector[0] = SyncJoin_main_region_B_r1_C1;
  269. handle->stateConfVectorPosition = 0;
  270. }
  271. /* 'default' enter sequence for state C2 */
  272. static void syncJoin_enseq_main_region_B_r1_C2_default(SyncJoin* handle)
  273. {
  274. /* 'default' enter sequence for state C2 */
  275. handle->stateConfVector[0] = SyncJoin_main_region_B_r1_C2;
  276. handle->stateConfVectorPosition = 0;
  277. }
  278. /* 'default' enter sequence for state D1 */
  279. static void syncJoin_enseq_main_region_B_r2_D1_default(SyncJoin* handle)
  280. {
  281. /* 'default' enter sequence for state D1 */
  282. handle->stateConfVector[1] = SyncJoin_main_region_B_r2_D1;
  283. handle->stateConfVectorPosition = 1;
  284. }
  285. /* 'default' enter sequence for state D2 */
  286. static void syncJoin_enseq_main_region_B_r2_D2_default(SyncJoin* handle)
  287. {
  288. /* 'default' enter sequence for state D2 */
  289. handle->stateConfVector[1] = SyncJoin_main_region_B_r2_D2;
  290. handle->stateConfVectorPosition = 1;
  291. }
  292. /* 'default' enter sequence for region main region */
  293. static void syncJoin_enseq_main_region_default(SyncJoin* handle)
  294. {
  295. /* 'default' enter sequence for region main region */
  296. syncJoin_react_main_region__entry_Default(handle);
  297. }
  298. /* 'default' enter sequence for region r1 */
  299. static void syncJoin_enseq_main_region_B_r1_default(SyncJoin* handle)
  300. {
  301. /* 'default' enter sequence for region r1 */
  302. syncJoin_react_main_region_B_r1__entry_Default(handle);
  303. }
  304. /* 'default' enter sequence for region r2 */
  305. static void syncJoin_enseq_main_region_B_r2_default(SyncJoin* handle)
  306. {
  307. /* 'default' enter sequence for region r2 */
  308. syncJoin_react_main_region_B_r2__entry_Default(handle);
  309. }
  310. /* Default exit sequence for state A */
  311. static void syncJoin_exseq_main_region_A(SyncJoin* handle)
  312. {
  313. /* Default exit sequence for state A */
  314. handle->stateConfVector[0] = SyncJoin_last_state;
  315. handle->stateConfVectorPosition = 0;
  316. }
  317. /* Default exit sequence for state B */
  318. static void syncJoin_exseq_main_region_B(SyncJoin* handle)
  319. {
  320. /* Default exit sequence for state B */
  321. syncJoin_exseq_main_region_B_r1(handle);
  322. syncJoin_exseq_main_region_B_r2(handle);
  323. }
  324. /* Default exit sequence for state C1 */
  325. static void syncJoin_exseq_main_region_B_r1_C1(SyncJoin* handle)
  326. {
  327. /* Default exit sequence for state C1 */
  328. handle->stateConfVector[0] = SyncJoin_last_state;
  329. handle->stateConfVectorPosition = 0;
  330. }
  331. /* Default exit sequence for state C2 */
  332. static void syncJoin_exseq_main_region_B_r1_C2(SyncJoin* handle)
  333. {
  334. /* Default exit sequence for state C2 */
  335. handle->stateConfVector[0] = SyncJoin_last_state;
  336. handle->stateConfVectorPosition = 0;
  337. }
  338. /* Default exit sequence for state D1 */
  339. static void syncJoin_exseq_main_region_B_r2_D1(SyncJoin* handle)
  340. {
  341. /* Default exit sequence for state D1 */
  342. handle->stateConfVector[1] = SyncJoin_last_state;
  343. handle->stateConfVectorPosition = 1;
  344. }
  345. /* Default exit sequence for state D2 */
  346. static void syncJoin_exseq_main_region_B_r2_D2(SyncJoin* handle)
  347. {
  348. /* Default exit sequence for state D2 */
  349. handle->stateConfVector[1] = SyncJoin_last_state;
  350. handle->stateConfVectorPosition = 1;
  351. }
  352. /* Default exit sequence for region main region */
  353. static void syncJoin_exseq_main_region(SyncJoin* handle)
  354. {
  355. /* Default exit sequence for region main region */
  356. /* Handle exit of all possible states (of SyncJoin.main_region) at position 0... */
  357. switch(handle->stateConfVector[ 0 ])
  358. {
  359. case SyncJoin_main_region_A :
  360. {
  361. syncJoin_exseq_main_region_A(handle);
  362. break;
  363. }
  364. case SyncJoin_main_region_B_r1_C1 :
  365. {
  366. syncJoin_exseq_main_region_B_r1_C1(handle);
  367. break;
  368. }
  369. case SyncJoin_main_region_B_r1_C2 :
  370. {
  371. syncJoin_exseq_main_region_B_r1_C2(handle);
  372. break;
  373. }
  374. default: break;
  375. }
  376. /* Handle exit of all possible states (of SyncJoin.main_region) at position 1... */
  377. switch(handle->stateConfVector[ 1 ])
  378. {
  379. case SyncJoin_main_region_B_r2_D1 :
  380. {
  381. syncJoin_exseq_main_region_B_r2_D1(handle);
  382. break;
  383. }
  384. case SyncJoin_main_region_B_r2_D2 :
  385. {
  386. syncJoin_exseq_main_region_B_r2_D2(handle);
  387. break;
  388. }
  389. default: break;
  390. }
  391. }
  392. /* Default exit sequence for region r1 */
  393. static void syncJoin_exseq_main_region_B_r1(SyncJoin* handle)
  394. {
  395. /* Default exit sequence for region r1 */
  396. /* Handle exit of all possible states (of SyncJoin.main_region.B.r1) at position 0... */
  397. switch(handle->stateConfVector[ 0 ])
  398. {
  399. case SyncJoin_main_region_B_r1_C1 :
  400. {
  401. syncJoin_exseq_main_region_B_r1_C1(handle);
  402. break;
  403. }
  404. case SyncJoin_main_region_B_r1_C2 :
  405. {
  406. syncJoin_exseq_main_region_B_r1_C2(handle);
  407. break;
  408. }
  409. default: break;
  410. }
  411. }
  412. /* Default exit sequence for region r2 */
  413. static void syncJoin_exseq_main_region_B_r2(SyncJoin* handle)
  414. {
  415. /* Default exit sequence for region r2 */
  416. /* Handle exit of all possible states (of SyncJoin.main_region.B.r2) at position 1... */
  417. switch(handle->stateConfVector[ 1 ])
  418. {
  419. case SyncJoin_main_region_B_r2_D1 :
  420. {
  421. syncJoin_exseq_main_region_B_r2_D1(handle);
  422. break;
  423. }
  424. case SyncJoin_main_region_B_r2_D2 :
  425. {
  426. syncJoin_exseq_main_region_B_r2_D2(handle);
  427. break;
  428. }
  429. default: break;
  430. }
  431. }
  432. /* The reactions of state A. */
  433. static void syncJoin_react_main_region_A(SyncJoin* handle)
  434. {
  435. /* The reactions of state A. */
  436. if (syncJoin_check_main_region_A_tr0_tr0(handle) == bool_true)
  437. {
  438. syncJoin_effect_main_region_A_tr0(handle);
  439. }
  440. }
  441. /* The reactions of state C1. */
  442. static void syncJoin_react_main_region_B_r1_C1(SyncJoin* handle)
  443. {
  444. /* The reactions of state C1. */
  445. if (syncJoin_check_main_region_B_r1_C1_tr0_tr0(handle) == bool_true)
  446. {
  447. syncJoin_effect_main_region_B_r1_C1_tr0(handle);
  448. }
  449. }
  450. /* The reactions of state C2. */
  451. static void syncJoin_react_main_region_B_r1_C2(SyncJoin* handle)
  452. {
  453. /* The reactions of state C2. */
  454. if (syncJoin_check_main_region_B_r1_C2_tr0_tr0(handle) == bool_true)
  455. {
  456. syncJoin_effect_main_region_B_r1_C2_tr0(handle);
  457. }
  458. }
  459. /* The reactions of state D1. */
  460. static void syncJoin_react_main_region_B_r2_D1(SyncJoin* handle)
  461. {
  462. /* The reactions of state D1. */
  463. if (syncJoin_check_main_region_B_r2_D1_tr0_tr0(handle) == bool_true)
  464. {
  465. syncJoin_effect_main_region_B_r2_D1_tr0(handle);
  466. }
  467. }
  468. /* The reactions of state D2. */
  469. static void syncJoin_react_main_region_B_r2_D2(SyncJoin* handle)
  470. {
  471. /* The reactions of state D2. */
  472. if (syncJoin_check_main_region_B_r2_D2_tr0_tr0(handle) == bool_true)
  473. {
  474. syncJoin_effect_main_region_B_r2_D2_tr0(handle);
  475. }
  476. }
  477. /* Default react sequence for initial entry */
  478. static void syncJoin_react_main_region__entry_Default(SyncJoin* handle)
  479. {
  480. /* Default react sequence for initial entry */
  481. syncJoin_enseq_main_region_B_default(handle);
  482. }
  483. /* Default react sequence for initial entry */
  484. static void syncJoin_react_main_region_B_r1__entry_Default(SyncJoin* handle)
  485. {
  486. /* Default react sequence for initial entry */
  487. syncJoin_enseq_main_region_B_r1_C1_default(handle);
  488. }
  489. /* Default react sequence for initial entry */
  490. static void syncJoin_react_main_region_B_r2__entry_Default(SyncJoin* handle)
  491. {
  492. /* Default react sequence for initial entry */
  493. syncJoin_enseq_main_region_B_r2_D1_default(handle);
  494. }
  495. /* The reactions of state null. */
  496. static void syncJoin_react_main_region__sync0(SyncJoin* handle)
  497. {
  498. /* The reactions of state null. */
  499. syncJoin_enseq_main_region_A_default(handle);
  500. }