LocalReactions.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "LocalReactions.h"
  5. /*! \file Implementation of the state machine 'LocalReactions'
  6. */
  7. /* prototypes of all internal functions */
  8. static sc_boolean localReactions_check_main_region_A_lr0_lr0(const LocalReactions* handle);
  9. static void localReactions_effect_main_region_A_lr0_lr0(LocalReactions* handle);
  10. static void localReactions_enseq_main_region_A_default(LocalReactions* handle);
  11. static void localReactions_enseq_main_region_default(LocalReactions* handle);
  12. static void localReactions_exseq_main_region_A(LocalReactions* handle);
  13. static void localReactions_exseq_main_region(LocalReactions* handle);
  14. static void localReactions_react_main_region_A(LocalReactions* handle);
  15. static void localReactions_react_main_region__entry_Default(LocalReactions* handle);
  16. static void localReactions_clearInEvents(LocalReactions* handle);
  17. static void localReactions_clearOutEvents(LocalReactions* handle);
  18. void localReactions_init(LocalReactions* handle)
  19. {
  20. sc_integer i;
  21. for (i = 0; i < LOCALREACTIONS_MAX_ORTHOGONAL_STATES; ++i)
  22. {
  23. handle->stateConfVector[i] = LocalReactions_last_state;
  24. }
  25. handle->stateConfVectorPosition = 0;
  26. localReactions_clearInEvents(handle);
  27. localReactions_clearOutEvents(handle);
  28. /* Default init sequence for statechart LocalReactions */
  29. handle->iface.x = 0;
  30. }
  31. void localReactions_enter(LocalReactions* handle)
  32. {
  33. /* Default enter sequence for statechart LocalReactions */
  34. localReactions_enseq_main_region_default(handle);
  35. }
  36. void localReactions_exit(LocalReactions* handle)
  37. {
  38. /* Default exit sequence for statechart LocalReactions */
  39. localReactions_exseq_main_region(handle);
  40. }
  41. sc_boolean localReactions_isActive(const LocalReactions* handle)
  42. {
  43. sc_boolean result = bool_false;
  44. int i;
  45. for(i = 0; i < LOCALREACTIONS_MAX_ORTHOGONAL_STATES; i++)
  46. {
  47. result = result || handle->stateConfVector[i] != LocalReactions_last_state;
  48. }
  49. return result;
  50. }
  51. /*
  52. * Always returns 'false' since this state machine can never become final.
  53. */
  54. sc_boolean localReactions_isFinal(const LocalReactions* handle)
  55. {
  56. return bool_false;
  57. }
  58. static void localReactions_clearInEvents(LocalReactions* handle)
  59. {
  60. }
  61. static void localReactions_clearOutEvents(LocalReactions* handle)
  62. {
  63. }
  64. void localReactions_runCycle(LocalReactions* handle)
  65. {
  66. localReactions_clearOutEvents(handle);
  67. for (handle->stateConfVectorPosition = 0;
  68. handle->stateConfVectorPosition < LOCALREACTIONS_MAX_ORTHOGONAL_STATES;
  69. handle->stateConfVectorPosition++)
  70. {
  71. switch (handle->stateConfVector[handle->stateConfVectorPosition])
  72. {
  73. case LocalReactions_main_region_A :
  74. {
  75. localReactions_react_main_region_A(handle);
  76. break;
  77. }
  78. default:
  79. break;
  80. }
  81. }
  82. localReactions_clearInEvents(handle);
  83. }
  84. sc_boolean localReactions_isStateActive(const LocalReactions* handle, LocalReactionsStates state)
  85. {
  86. sc_boolean result = bool_false;
  87. switch (state)
  88. {
  89. case LocalReactions_main_region_A :
  90. result = (sc_boolean) (handle->stateConfVector[SCVI_LOCALREACTIONS_MAIN_REGION_A] == LocalReactions_main_region_A
  91. );
  92. break;
  93. default:
  94. result = bool_false;
  95. break;
  96. }
  97. return result;
  98. }
  99. sc_integer localReactionsIface_get_x(const LocalReactions* handle)
  100. {
  101. return handle->iface.x;
  102. }
  103. void localReactionsIface_set_x(LocalReactions* handle, sc_integer value)
  104. {
  105. handle->iface.x = value;
  106. }
  107. /* implementations of all internal functions */
  108. static sc_boolean localReactions_check_main_region_A_lr0_lr0(const LocalReactions* handle)
  109. {
  110. return (handle->iface.x == 0) ? bool_true : bool_false;
  111. }
  112. static void localReactions_effect_main_region_A_lr0_lr0(LocalReactions* handle)
  113. {
  114. handle->iface.x += 1;
  115. }
  116. /* 'default' enter sequence for state A */
  117. static void localReactions_enseq_main_region_A_default(LocalReactions* handle)
  118. {
  119. /* 'default' enter sequence for state A */
  120. handle->stateConfVector[0] = LocalReactions_main_region_A;
  121. handle->stateConfVectorPosition = 0;
  122. }
  123. /* 'default' enter sequence for region main region */
  124. static void localReactions_enseq_main_region_default(LocalReactions* handle)
  125. {
  126. /* 'default' enter sequence for region main region */
  127. localReactions_react_main_region__entry_Default(handle);
  128. }
  129. /* Default exit sequence for state A */
  130. static void localReactions_exseq_main_region_A(LocalReactions* handle)
  131. {
  132. /* Default exit sequence for state A */
  133. handle->stateConfVector[0] = LocalReactions_last_state;
  134. handle->stateConfVectorPosition = 0;
  135. }
  136. /* Default exit sequence for region main region */
  137. static void localReactions_exseq_main_region(LocalReactions* handle)
  138. {
  139. /* Default exit sequence for region main region */
  140. /* Handle exit of all possible states (of LocalReactions.main_region) at position 0... */
  141. switch(handle->stateConfVector[ 0 ])
  142. {
  143. case LocalReactions_main_region_A :
  144. {
  145. localReactions_exseq_main_region_A(handle);
  146. break;
  147. }
  148. default: break;
  149. }
  150. }
  151. /* The reactions of state A. */
  152. static void localReactions_react_main_region_A(LocalReactions* handle)
  153. {
  154. /* The reactions of state A. */
  155. if (localReactions_check_main_region_A_lr0_lr0(handle) == bool_true)
  156. {
  157. localReactions_effect_main_region_A_lr0_lr0(handle);
  158. }
  159. }
  160. /* Default react sequence for initial entry */
  161. static void localReactions_react_main_region__entry_Default(LocalReactions* handle)
  162. {
  163. /* Default react sequence for initial entry */
  164. localReactions_enseq_main_region_A_default(handle);
  165. }