AlwaysOncycle.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "sc_types.h"
  4. #include "AlwaysOncycle.h"
  5. #include "AlwaysOncycleRequired.h"
  6. /*! \file Implementation of the state machine 'AlwaysOncycle'
  7. */
  8. // prototypes of all internal functions
  9. static void alwaysOncycle_entryaction(AlwaysOncycle* handle);
  10. static void alwaysOncycle_exitaction(AlwaysOncycle* handle);
  11. static void alwaysOncycle_react_main_region_StateA(AlwaysOncycle* handle);
  12. static void alwaysOncycle_react_main_region_StateB(AlwaysOncycle* handle);
  13. static void clearInEvents(AlwaysOncycle* handle);
  14. static void clearOutEvents(AlwaysOncycle* handle);
  15. void alwaysOncycle_init(AlwaysOncycle* handle)
  16. {
  17. int i;
  18. for (i = 0; i < ALWAYSONCYCLE_MAX_ORTHOGONAL_STATES; ++i)
  19. handle->stateConfVector[i] = AlwaysOncycle_last_state;
  20. handle->stateConfVectorPosition = 0;
  21. // TODO: initialize all events ...
  22. // TODO: initialize all variables ... (set default values - here or inenter sequence ?!?)
  23. }
  24. void alwaysOncycle_enter(AlwaysOncycle* handle)
  25. {
  26. /* Default enter sequence for statechart AlwaysOncycle */
  27. alwaysOncycle_entryaction(handle);
  28. /* Default enter sequence for region main region */
  29. /* Default react sequence for initial entry */
  30. /* Default enter sequence for state StateA */
  31. /* Entry action for state 'StateA'. */
  32. handle->iface.value = 0;
  33. handle->stateConfVector[0] = AlwaysOncycle_main_region_StateA;
  34. handle->stateConfVectorPosition = 0;
  35. }
  36. void alwaysOncycle_exit(AlwaysOncycle* handle)
  37. {
  38. /* Default exit sequence for statechart AlwaysOncycle */
  39. /* Default exit sequence for region main region */
  40. /* Handle exit of all possible states (of main region) at position 0... */
  41. switch(handle->stateConfVector[ 0 ]) {
  42. case AlwaysOncycle_main_region_StateA : {
  43. /* Default exit sequence for state StateA */
  44. handle->stateConfVector[0] = AlwaysOncycle_last_state;
  45. handle->stateConfVectorPosition = 0;
  46. /* Exit action for state 'StateA'. */
  47. handle->iface.value = 0;
  48. break;
  49. }
  50. case AlwaysOncycle_main_region_StateB : {
  51. /* Default exit sequence for state StateB */
  52. handle->stateConfVector[0] = AlwaysOncycle_last_state;
  53. handle->stateConfVectorPosition = 0;
  54. break;
  55. }
  56. default: break;
  57. }
  58. alwaysOncycle_exitaction(handle);
  59. }
  60. static void clearInEvents(AlwaysOncycle* handle) {
  61. }
  62. static void clearOutEvents(AlwaysOncycle* handle) {
  63. }
  64. void alwaysOncycle_runCycle(AlwaysOncycle* handle) {
  65. clearOutEvents(handle);
  66. for (handle->stateConfVectorPosition = 0;
  67. handle->stateConfVectorPosition < ALWAYSONCYCLE_MAX_ORTHOGONAL_STATES;
  68. handle->stateConfVectorPosition++) {
  69. switch (handle->stateConfVector[handle->stateConfVectorPosition]) {
  70. case AlwaysOncycle_main_region_StateA : {
  71. alwaysOncycle_react_main_region_StateA(handle);
  72. break;
  73. }
  74. case AlwaysOncycle_main_region_StateB : {
  75. alwaysOncycle_react_main_region_StateB(handle);
  76. break;
  77. }
  78. default:
  79. break;
  80. }
  81. }
  82. clearInEvents(handle);
  83. }
  84. sc_boolean alwaysOncycle_isActive(AlwaysOncycle* handle, AlwaysOncycleStates state) {
  85. switch (state) {
  86. case AlwaysOncycle_main_region_StateA :
  87. return (sc_boolean) (handle->stateConfVector[0] == AlwaysOncycle_main_region_StateA
  88. );
  89. case AlwaysOncycle_main_region_StateB :
  90. return (sc_boolean) (handle->stateConfVector[0] == AlwaysOncycle_main_region_StateB
  91. );
  92. default: return bool_false;
  93. }
  94. }
  95. sc_integer alwaysOncycleIface_get_value(AlwaysOncycle* handle) {
  96. return handle->iface.value;
  97. }
  98. void alwaysOncycleIface_set_value(AlwaysOncycle* handle, sc_integer value) {
  99. handle->iface.value = value;
  100. }
  101. // implementations of all internal functions
  102. /* Entry action for statechart 'AlwaysOncycle'. */
  103. static void alwaysOncycle_entryaction(AlwaysOncycle* handle) {
  104. /* Entry action for statechart 'AlwaysOncycle'. */
  105. }
  106. /* Exit action for state 'AlwaysOncycle'. */
  107. static void alwaysOncycle_exitaction(AlwaysOncycle* handle) {
  108. /* Exit action for state 'AlwaysOncycle'. */
  109. }
  110. /* The reactions of state StateA. */
  111. static void alwaysOncycle_react_main_region_StateA(AlwaysOncycle* handle) {
  112. /* The reactions of state StateA. */
  113. if (handle->iface.value == 5) {
  114. /* Default exit sequence for state StateA */
  115. handle->stateConfVector[0] = AlwaysOncycle_last_state;
  116. handle->stateConfVectorPosition = 0;
  117. /* Exit action for state 'StateA'. */
  118. handle->iface.value = 0;
  119. /* Default enter sequence for state StateB */
  120. handle->stateConfVector[0] = AlwaysOncycle_main_region_StateB;
  121. handle->stateConfVectorPosition = 0;
  122. } else {
  123. handle->iface.value += 1;
  124. }
  125. }
  126. /* The reactions of state StateB. */
  127. static void alwaysOncycle_react_main_region_StateB(AlwaysOncycle* handle) {
  128. /* The reactions of state StateB. */
  129. if (handle->iface.value == 5) {
  130. /* Default exit sequence for state StateB */
  131. handle->stateConfVector[0] = AlwaysOncycle_last_state;
  132. handle->stateConfVectorPosition = 0;
  133. /* Default enter sequence for state StateA */
  134. /* Entry action for state 'StateA'. */
  135. handle->iface.value = 0;
  136. handle->stateConfVector[0] = AlwaysOncycle_main_region_StateA;
  137. handle->stateConfVectorPosition = 0;
  138. } else {
  139. handle->iface.value += 1;
  140. }
  141. }