244 lines
7.2 KiB
C
244 lines
7.2 KiB
C
/* Generated by itemis CREATE code generator. */
|
|
|
|
#ifndef STATECHART_H_
|
|
#define STATECHART_H_
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*!
|
|
* Forward declaration for the Statechart state machine.
|
|
*/
|
|
typedef struct Statechart Statechart;
|
|
|
|
/*!
|
|
* Forward declaration of the data structure for the StatechartIface interface scope.
|
|
*/
|
|
typedef struct StatechartIface StatechartIface;
|
|
|
|
/*!
|
|
* Forward declaration of the data structure for the StatechartInternal interface scope.
|
|
*/
|
|
typedef struct StatechartInternal StatechartInternal;
|
|
|
|
/*!
|
|
* Forward declaration of the data structure for the StatechartTimeEvents interface scope.
|
|
*/
|
|
typedef struct StatechartTimeEvents StatechartTimeEvents;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#include "../src/data_types.h"
|
|
#include "../src/sc_types.h"
|
|
#include "../src/sc_rxc.h"
|
|
#include "../src/sc_rxc_int32_t.h"
|
|
#include "../src/sc_rxc_bool.h"
|
|
#include "../src/sc_rxc_int32_t.h"
|
|
#include "../src/sc_rxc_int32_t.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/*! \file
|
|
Header of the state machine 'Statechart'.
|
|
*/
|
|
|
|
#ifndef STATECHART_EVENTQUEUE_BUFFERSIZE
|
|
#define STATECHART_EVENTQUEUE_BUFFERSIZE 20
|
|
#endif
|
|
#ifndef STATECHART_IN_EVENTQUEUE_BUFFERSIZE
|
|
#define STATECHART_IN_EVENTQUEUE_BUFFERSIZE STATECHART_EVENTQUEUE_BUFFERSIZE
|
|
#endif
|
|
#ifndef STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE
|
|
#define STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE STATECHART_EVENTQUEUE_BUFFERSIZE
|
|
#endif
|
|
#ifndef SC_INVALID_EVENT_VALUE
|
|
#define SC_INVALID_EVENT_VALUE 0
|
|
#endif
|
|
/*! Define number of states in the state enum */
|
|
#define STATECHART_STATE_COUNT 9
|
|
|
|
/*! Define dimension of the state configuration vector for orthogonal states. */
|
|
#define STATECHART_MAX_ORTHOGONAL_STATES 3
|
|
/*! Define maximum number of time events that can be active at once */
|
|
#define STATECHART_MAX_PARALLEL_TIME_EVENTS 1
|
|
|
|
/*! Define indices of states in the StateConfVector */
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING 0
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_OFF 0
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON 0
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R1_RESPONDING 0
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R1_SENSOR_ERROR 0
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R2_NOT_PRESSED 1
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_R1_ON_R2_PRESSED 1
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_POLLBUTTON_BUTTON0 2
|
|
#define SCVI_STATECHART_MAIN_REGION_EVERYTHING_POLLBUTTON_BUTTON1 2
|
|
|
|
/*
|
|
* Union of all possible event value types.
|
|
*/
|
|
typedef union {
|
|
int32_t Statechart_sensor_value;
|
|
sc_boolean Statechart_buttonState_value;
|
|
} statechart_event_value;
|
|
|
|
/*
|
|
* Enum of event names in the statechart.
|
|
*/
|
|
typedef enum {
|
|
Statechart_invalid_event = SC_INVALID_EVENT_VALUE,
|
|
Statechart_sensor,
|
|
Statechart_buttonState,
|
|
Statechart_internal_buttonPressed,
|
|
Statechart_internal_buttonReleased,
|
|
Statechart_Statechart_main_region_everything_r1_on_r2_pressed_time_event_0
|
|
} StatechartEventID;
|
|
|
|
/*
|
|
* Struct that represents a single event.
|
|
*/
|
|
typedef struct {
|
|
StatechartEventID name;
|
|
sc_boolean has_value;
|
|
statechart_event_value value;
|
|
} statechart_event;
|
|
|
|
/*
|
|
* Queue that holds the raised events.
|
|
*/
|
|
typedef struct statechart_eventqueue_s {
|
|
statechart_event *events;
|
|
sc_integer capacity;
|
|
sc_integer pop_index;
|
|
sc_integer push_index;
|
|
sc_integer size;
|
|
} statechart_eventqueue;
|
|
|
|
/*! Enumeration of all states */
|
|
typedef enum
|
|
{
|
|
Statechart_last_state,
|
|
Statechart_main_region_everything,
|
|
Statechart_main_region_everything_r1_off,
|
|
Statechart_main_region_everything_r1_on,
|
|
Statechart_main_region_everything_r1_on_r1_responding,
|
|
Statechart_main_region_everything_r1_on_r1_sensor_error,
|
|
Statechart_main_region_everything_r1_on_r2_not_pressed,
|
|
Statechart_main_region_everything_r1_on_r2_pressed,
|
|
Statechart_main_region_everything_pollButton_button0,
|
|
Statechart_main_region_everything_pollButton_button1
|
|
} StatechartStates;
|
|
|
|
|
|
|
|
|
|
/*! Type declaration of the data structure for the StatechartIface interface scope. */
|
|
struct StatechartIface
|
|
{
|
|
sc_boolean sensor_raised;
|
|
int32_t sensor_value;
|
|
sc_boolean buttonState_raised;
|
|
sc_boolean buttonState_value;
|
|
sc_observable_int32_t setMotorR;
|
|
sc_observable_int32_t setMotorL;
|
|
};
|
|
|
|
|
|
|
|
/*! Type declaration of the data structure for the StatechartInternal interface scope. */
|
|
struct StatechartInternal
|
|
{
|
|
sc_boolean buttonPressed_raised;
|
|
sc_boolean buttonReleased_raised;
|
|
int32_t speed;
|
|
pid_vars_t pid_vars;
|
|
};
|
|
|
|
|
|
|
|
/*! Type declaration of the data structure for the StatechartTimeEvents interface scope. */
|
|
struct StatechartTimeEvents
|
|
{
|
|
sc_boolean statechart_main_region_everything_r1_on_r2_pressed_tev0_raised;
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
* Type declaration of the data structure for the Statechart state machine.
|
|
* This data structure has to be allocated by the client code.
|
|
*/
|
|
struct Statechart
|
|
{
|
|
StatechartStates stateConfVector[STATECHART_MAX_ORTHOGONAL_STATES];
|
|
StatechartIface iface;
|
|
StatechartInternal internal;
|
|
StatechartTimeEvents timeEvents;
|
|
sc_boolean isExecuting;
|
|
sc_integer stateConfVectorPosition;
|
|
statechart_eventqueue internal_event_queue;
|
|
statechart_event internal_buffer[STATECHART_INTERNAL_EVENTQUEUE_BUFFERSIZE];
|
|
statechart_eventqueue in_event_queue;
|
|
statechart_event in_buffer[STATECHART_IN_EVENTQUEUE_BUFFERSIZE];
|
|
};
|
|
|
|
|
|
|
|
/*! Initializes the Statechart state machine data structures. Must be called before first usage.*/
|
|
extern void statechart_init(Statechart* handle);
|
|
|
|
|
|
/*! Activates the state machine. */
|
|
extern void statechart_enter(Statechart* handle);
|
|
|
|
/*! Deactivates the state machine. */
|
|
extern void statechart_exit(Statechart* handle);
|
|
|
|
/*!
|
|
Can be used by the client code to trigger a run to completion step without raising an event.
|
|
*/
|
|
extern void statechart_trigger_without_event(Statechart* handle);
|
|
|
|
|
|
/*! Raises a time event. */
|
|
extern void statechart_raise_time_event(Statechart* handle, sc_eventid evid);
|
|
|
|
/*! Raises the in event 'sensor' that is defined in the default interface scope. */
|
|
extern void statechart_raise_sensor(Statechart* handle, int32_t value);
|
|
/*! Raises the in event 'buttonState' that is defined in the default interface scope. */
|
|
extern void statechart_raise_buttonState(Statechart* handle, sc_boolean value);
|
|
/*! Returns the observable for the out event 'setMotorR' that is defined in the default interface scope. */
|
|
extern sc_observable_int32_t* statechart_get_setMotorR(Statechart* handle);
|
|
|
|
/*! Returns the observable for the out event 'setMotorL' that is defined in the default interface scope. */
|
|
extern sc_observable_int32_t* statechart_get_setMotorL(Statechart* handle);
|
|
|
|
|
|
/*!
|
|
* Checks whether the state machine is active (until 2.4.1 this method was used for states).
|
|
* 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.
|
|
*/
|
|
extern sc_boolean statechart_is_active(const Statechart* handle);
|
|
|
|
/*!
|
|
* Checks if all active states are final.
|
|
* If there are no active states then the state machine is considered being inactive. In this case this method returns false.
|
|
*/
|
|
extern sc_boolean statechart_is_final(const Statechart* handle);
|
|
|
|
/*! Checks if the specified state is active (until 2.4.1 the used method for states was called isActive()). */
|
|
extern sc_boolean statechart_is_state_active(const Statechart* handle, StatechartStates state);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* STATECHART_H_ */
|