LogicalOr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "LogicalOr.h"
  5. /*! \file Implementation of the state machine 'LogicalOr'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean logicalOr_check_main_region_A_tr0_tr0(const LogicalOr* handle);
  9. static void logicalOr_effect_main_region_A_tr0(LogicalOr* handle);
  10. static void logicalOr_enseq_main_region_A_default(LogicalOr* handle);
  11. static void logicalOr_enseq_main_region_default(LogicalOr* handle);
  12. static void logicalOr_exseq_main_region_A(LogicalOr* handle);
  13. static void logicalOr_exseq_main_region(LogicalOr* handle);
  14. static void logicalOr_react_main_region_A(LogicalOr* handle);
  15. static void logicalOr_react_main_region__entry_Default(LogicalOr* handle);
  16. static void logicalOr_clearInEvents(LogicalOr* handle);
  17. static void logicalOr_clearOutEvents(LogicalOr* handle);
  18. void logicalOr_init(LogicalOr* handle)
  19. {
  20. sc_integer i;
  21. for (i = 0; i < LOGICALOR_MAX_ORTHOGONAL_STATES; ++i)
  22. {
  23. handle->stateConfVector[i] = LogicalOr_last_state;
  24. }
  25. handle->stateConfVectorPosition = 0;
  26. logicalOr_clearInEvents(handle);
  27. logicalOr_clearOutEvents(handle);
  28. /* Default init sequence for statechart LogicalOr */
  29. handle->iface.x = 1;
  30. handle->iface.b = bool_false;
  31. }
  32. void logicalOr_enter(LogicalOr* handle)
  33. {
  34. /* Default enter sequence for statechart LogicalOr */
  35. logicalOr_enseq_main_region_default(handle);
  36. }
  37. void logicalOr_exit(LogicalOr* handle)
  38. {
  39. /* Default exit sequence for statechart LogicalOr */
  40. logicalOr_exseq_main_region(handle);
  41. }
  42. sc_boolean logicalOr_isActive(const LogicalOr* handle)
  43. {
  44. sc_boolean result = bool_false;
  45. int i;
  46. for(i = 0; i < LOGICALOR_MAX_ORTHOGONAL_STATES; i++)
  47. {
  48. result = result || handle->stateConfVector[i] != LogicalOr_last_state;
  49. }
  50. return result;
  51. }
  52. /*
  53. * Always returns 'false' since this state machine can never become final.
  54. */
  55. sc_boolean logicalOr_isFinal(const LogicalOr* handle)
  56. {
  57. return bool_false;
  58. }
  59. static void logicalOr_clearInEvents(LogicalOr* handle)
  60. {
  61. }
  62. static void logicalOr_clearOutEvents(LogicalOr* handle)
  63. {
  64. }
  65. void logicalOr_runCycle(LogicalOr* handle)
  66. {
  67. logicalOr_clearOutEvents(handle);
  68. for (handle->stateConfVectorPosition = 0;
  69. handle->stateConfVectorPosition < LOGICALOR_MAX_ORTHOGONAL_STATES;
  70. handle->stateConfVectorPosition++)
  71. {
  72. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  73. {
  74. case LogicalOr_main_region_A :
  75. {
  76. logicalOr_react_main_region_A(handle);
  77. break;
  78. }
  79. default:
  80. break;
  81. }
  82. }
  83. logicalOr_clearInEvents(handle);
  84. }
  85. sc_boolean logicalOr_isStateActive(const LogicalOr* handle, LogicalOrStates state)
  86. {
  87. sc_boolean result = bool_false;
  88. switch (state)
  89. {
  90. case LogicalOr_main_region_A :
  91. result = (sc_boolean) (handle->stateConfVector[SCVI_LOGICALOR_MAIN_REGION_A] == LogicalOr_main_region_A
  92. );
  93. break;
  94. default:
  95. result = bool_false;
  96. break;
  97. }
  98. return result;
  99. }
  100. sc_integer logicalOrIface_get_x(const LogicalOr* handle)
  101. {
  102. return handle->iface.x;
  103. }
  104. void logicalOrIface_set_x(LogicalOr* handle, sc_integer value)
  105. {
  106. handle->iface.x = value;
  107. }
  108. sc_boolean logicalOrIface_get_b(const LogicalOr* handle)
  109. {
  110. return handle->iface.b;
  111. }
  112. void logicalOrIface_set_b(LogicalOr* handle, sc_boolean value)
  113. {
  114. handle->iface.b = value;
  115. }
  116. /* implementations of all internal functions */
  117. static sc_boolean logicalOr_check_main_region_A_tr0_tr0(const LogicalOr* handle)
  118. {
  119. return (handle->iface.x == 1) ? bool_true : bool_false;
  120. }
  121. static void logicalOr_effect_main_region_A_tr0(LogicalOr* handle)
  122. {
  123. logicalOr_exseq_main_region_A(handle);
  124. handle->iface.b = ((handle->iface.x += 1) != 2 || (handle->iface.x *= 2) == 4);
  125. logicalOr_enseq_main_region_A_default(handle);
  126. }
  127. /* 'default' enter sequence for state A */
  128. static void logicalOr_enseq_main_region_A_default(LogicalOr* handle)
  129. {
  130. /* 'default' enter sequence for state A */
  131. handle->stateConfVector[0] = LogicalOr_main_region_A;
  132. handle->stateConfVectorPosition = 0;
  133. }
  134. /* 'default' enter sequence for region main region */
  135. static void logicalOr_enseq_main_region_default(LogicalOr* handle)
  136. {
  137. /* 'default' enter sequence for region main region */
  138. logicalOr_react_main_region__entry_Default(handle);
  139. }
  140. /* Default exit sequence for state A */
  141. static void logicalOr_exseq_main_region_A(LogicalOr* handle)
  142. {
  143. /* Default exit sequence for state A */
  144. handle->stateConfVector[0] = LogicalOr_last_state;
  145. handle->stateConfVectorPosition = 0;
  146. }
  147. /* Default exit sequence for region main region */
  148. static void logicalOr_exseq_main_region(LogicalOr* handle)
  149. {
  150. /* Default exit sequence for region main region */
  151. /* Handle exit of all possible states (of LogicalOr.main_region) at position 0... */
  152. switch(handle->stateConfVector[ 0 ])
  153. {
  154. case LogicalOr_main_region_A :
  155. {
  156. logicalOr_exseq_main_region_A(handle);
  157. break;
  158. }
  159. default: break;
  160. }
  161. }
  162. /* The reactions of state A. */
  163. static void logicalOr_react_main_region_A(LogicalOr* handle)
  164. {
  165. /* The reactions of state A. */
  166. if (logicalOr_check_main_region_A_tr0_tr0(handle) == bool_true)
  167. {
  168. logicalOr_effect_main_region_A_tr0(handle);
  169. }
  170. }
  171. /* Default react sequence for initial entry */
  172. static void logicalOr_react_main_region__entry_Default(LogicalOr* handle)
  173. {
  174. /* Default react sequence for initial entry */
  175. logicalOr_enseq_main_region_A_default(handle);
  176. }