TrafficLightCtrl.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef TRAFFICLIGHTCTRL_H_
  2. #define TRAFFICLIGHTCTRL_H_
  3. #include "sc/sc_types.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /*! \file Header of the state machine 'TrafficLightCtrl'.
  8. */
  9. /*! Enumeration of all states */
  10. typedef enum
  11. {
  12. TrafficLightCtrl_main_region_on,
  13. TrafficLightCtrl_main_region_on_r1_StreetGreen,
  14. TrafficLightCtrl_main_region_on_r1_PedWaiting,
  15. TrafficLightCtrl_main_region_on_r1_PedWaiting_r1_waitOn,
  16. TrafficLightCtrl_main_region_on_r1_PedWaiting_r1_waitOff,
  17. TrafficLightCtrl_main_region_on_r1_StreetAttention,
  18. TrafficLightCtrl_main_region_on_r1_StreetRed,
  19. TrafficLightCtrl_main_region_on_r1_PedestrianGreen,
  20. TrafficLightCtrl_main_region_on_r1_PedestrianRed,
  21. TrafficLightCtrl_main_region_on_r1_StreetPrepare,
  22. TrafficLightCtrl_main_region_on_r1_Safe,
  23. TrafficLightCtrl_main_region_off,
  24. TrafficLightCtrl_main_region_off_r1_YellowOn,
  25. TrafficLightCtrl_main_region_off_r1_YellowOff,
  26. TrafficLightCtrl_last_state
  27. } TrafficLightCtrlStates;
  28. /*! Type definition of the data structure for the TrafficLightCtrlIfaceTrafficLight interface scope. */
  29. typedef struct
  30. {
  31. sc_boolean red;
  32. sc_boolean yellow;
  33. sc_boolean green;
  34. } TrafficLightCtrlIfaceTrafficLight;
  35. /*! Type definition of the data structure for the TrafficLightCtrlIfacePedestrian interface scope. */
  36. typedef struct
  37. {
  38. sc_boolean request;
  39. sc_boolean red;
  40. sc_boolean green;
  41. } TrafficLightCtrlIfacePedestrian;
  42. /*! Type definition of the data structure for the TrafficLightCtrlIface interface scope. */
  43. typedef struct
  44. {
  45. sc_boolean pedestrianRequest_raised;
  46. sc_boolean onOff_raised;
  47. } TrafficLightCtrlIface;
  48. /*! Type definition of the data structure for the TrafficLightCtrlTimeEvents interface scope. */
  49. typedef struct
  50. {
  51. sc_boolean trafficLightCtrl_main_region_on_r1_PedWaiting_tev0_raised;
  52. sc_boolean trafficLightCtrl_main_region_on_r1_PedWaiting_r1_waitOn_tev0_raised;
  53. sc_boolean trafficLightCtrl_main_region_on_r1_PedWaiting_r1_waitOff_tev0_raised;
  54. sc_boolean trafficLightCtrl_main_region_on_r1_StreetAttention_tev0_raised;
  55. sc_boolean trafficLightCtrl_main_region_on_r1_StreetRed_tev0_raised;
  56. sc_boolean trafficLightCtrl_main_region_on_r1_PedestrianGreen_tev0_raised;
  57. sc_boolean trafficLightCtrl_main_region_on_r1_PedestrianRed_tev0_raised;
  58. sc_boolean trafficLightCtrl_main_region_on_r1_StreetPrepare_tev0_raised;
  59. sc_boolean trafficLightCtrl_main_region_on_r1_Safe_tev0_raised;
  60. sc_boolean trafficLightCtrl_main_region_off_r1_YellowOn_tev0_raised;
  61. sc_boolean trafficLightCtrl_main_region_off_r1_YellowOff_tev0_raised;
  62. sc_boolean trafficLightCtrl_tev0_raised;
  63. } TrafficLightCtrlTimeEvents;
  64. /*! Define dimension of the state configuration vector for orthogonal states. */
  65. #define TRAFFICLIGHTCTRL_MAX_ORTHOGONAL_STATES 1
  66. /*!
  67. * Type definition of the data structure for the TrafficLightCtrl state machine.
  68. * This data structure has to be allocated by the client code.
  69. */
  70. typedef struct
  71. {
  72. TrafficLightCtrlStates stateConfVector[TRAFFICLIGHTCTRL_MAX_ORTHOGONAL_STATES];
  73. sc_ushort stateConfVectorPosition;
  74. TrafficLightCtrlIfaceTrafficLight ifaceTrafficLight;
  75. TrafficLightCtrlIfacePedestrian ifacePedestrian;
  76. TrafficLightCtrlIface iface;
  77. TrafficLightCtrlTimeEvents timeEvents;
  78. } TrafficLightCtrl;
  79. /*! Initializes the TrafficLightCtrl state machine data structures. Must be called before first usage.*/
  80. extern void trafficLightCtrl_init(TrafficLightCtrl* handle);
  81. /*! Activates the state machine */
  82. extern void trafficLightCtrl_enter(TrafficLightCtrl* handle);
  83. /*! Deactivates the state machine */
  84. extern void trafficLightCtrl_exit(TrafficLightCtrl* handle);
  85. /*! Performs a 'run to completion' step. */
  86. extern void trafficLightCtrl_runCycle(TrafficLightCtrl* handle);
  87. /*! Raises a time event. */
  88. extern void trafficLightCtrl_raiseTimeEvent(const TrafficLightCtrl* handle, sc_eventid evid);
  89. /*! Gets the value of the variable 'red' that is defined in the interface scope 'TrafficLight'. */
  90. extern sc_boolean trafficLightCtrlIfaceTrafficLight_get_red(const TrafficLightCtrl* handle);
  91. /*! Sets the value of the variable 'red' that is defined in the interface scope 'TrafficLight'. */
  92. extern void trafficLightCtrlIfaceTrafficLight_set_red(TrafficLightCtrl* handle, sc_boolean value);
  93. /*! Gets the value of the variable 'yellow' that is defined in the interface scope 'TrafficLight'. */
  94. extern sc_boolean trafficLightCtrlIfaceTrafficLight_get_yellow(const TrafficLightCtrl* handle);
  95. /*! Sets the value of the variable 'yellow' that is defined in the interface scope 'TrafficLight'. */
  96. extern void trafficLightCtrlIfaceTrafficLight_set_yellow(TrafficLightCtrl* handle, sc_boolean value);
  97. /*! Gets the value of the variable 'green' that is defined in the interface scope 'TrafficLight'. */
  98. extern sc_boolean trafficLightCtrlIfaceTrafficLight_get_green(const TrafficLightCtrl* handle);
  99. /*! Sets the value of the variable 'green' that is defined in the interface scope 'TrafficLight'. */
  100. extern void trafficLightCtrlIfaceTrafficLight_set_green(TrafficLightCtrl* handle, sc_boolean value);
  101. /*! Gets the value of the variable 'request' that is defined in the interface scope 'Pedestrian'. */
  102. extern sc_boolean trafficLightCtrlIfacePedestrian_get_request(const TrafficLightCtrl* handle);
  103. /*! Sets the value of the variable 'request' that is defined in the interface scope 'Pedestrian'. */
  104. extern void trafficLightCtrlIfacePedestrian_set_request(TrafficLightCtrl* handle, sc_boolean value);
  105. /*! Gets the value of the variable 'red' that is defined in the interface scope 'Pedestrian'. */
  106. extern sc_boolean trafficLightCtrlIfacePedestrian_get_red(const TrafficLightCtrl* handle);
  107. /*! Sets the value of the variable 'red' that is defined in the interface scope 'Pedestrian'. */
  108. extern void trafficLightCtrlIfacePedestrian_set_red(TrafficLightCtrl* handle, sc_boolean value);
  109. /*! Gets the value of the variable 'green' that is defined in the interface scope 'Pedestrian'. */
  110. extern sc_boolean trafficLightCtrlIfacePedestrian_get_green(const TrafficLightCtrl* handle);
  111. /*! Sets the value of the variable 'green' that is defined in the interface scope 'Pedestrian'. */
  112. extern void trafficLightCtrlIfacePedestrian_set_green(TrafficLightCtrl* handle, sc_boolean value);
  113. /*! Raises the in event 'pedestrianRequest' that is defined in the default interface scope. */
  114. extern void trafficLightCtrlIface_raise_pedestrianRequest(TrafficLightCtrl* handle);
  115. /*! Raises the in event 'onOff' that is defined in the default interface scope. */
  116. extern void trafficLightCtrlIface_raise_onOff(TrafficLightCtrl* handle);
  117. /*!
  118. * Checks whether the state machine is active (until 2.4.1 this method was used for states).
  119. * A state machine is active if it was entered. It is inactive if it has not been entered at all or if it has been exited.
  120. */
  121. extern sc_boolean trafficLightCtrl_isActive(const TrafficLightCtrl* handle);
  122. /*!
  123. * Checks if all active states are final.
  124. * If there are no active states then the state machine is considered being inactive. In this case this method returns false.
  125. */
  126. extern sc_boolean trafficLightCtrl_isFinal(const TrafficLightCtrl* handle);
  127. /*! Checks if the specified state is active (until 2.4.1 the used method for states was called isActive()). */
  128. extern sc_boolean trafficLightCtrl_isStateActive(const TrafficLightCtrl* handle, TrafficLightCtrlStates state);
  129. #ifdef __cplusplus
  130. }
  131. #endif
  132. #endif /* TRAFFICLIGHTCTRL_H_ */