Labor04
|
Header-File for the state machine. More...
Data Structures | |
struct | stateTransition |
Event table holds events that can generate a state transition. More... | |
struct | stateTableEvents |
State table holds states and corresponding event tables. More... | |
struct | stateMachine |
All nesseccary data for a state machine. More... | |
Macros | |
#define | SW_USE_ONENTRY 1 |
Set to one, if onEntry() functions are needed. More... | |
#define | SW_USE_ONDO 0 |
Set to one, if onDo() functions are needed. More... | |
#define | SW_USE_ONEXIT 1 |
Set to one, if onExit() functions are needed. More... | |
#define | SW_USE_TRANSITIONFUNCTION 1 |
Set to one, if transition functions are nedded. More... | |
#define | IS_IN(statemachine, state) (statemachine.s32ActualState == state) |
MACRO checking if statemachine is in state. More... | |
Typedefs | |
typedef struct stateTableEvents | sStateTable_t |
typedef sStateTable_t * | psStateTable_t |
typedef enum specialStates | eSpecialStates_t |
Special states to use with nextStateId in sStateTransitions_t. More... | |
typedef enum specialEvents | eSpecialEvents_t |
Special events that can occur while the state machine is running. More... | |
typedef void(* | vCallback_t) (void) |
Callback typedef for better readable code. More... | |
typedef _Bool(* | bCallbackGuard_t) (void) |
Callback for guard functions, that return either true or false. More... | |
typedef struct stateTransition | sStateTransitions_t |
Event table holds events that can generate a state transition. More... | |
typedef sStateTransitions_t * | psStateTransitions_t |
typedef struct stateTableEvents | sStateTableEvents_t |
State table holds states and corresponding event tables. More... | |
typedef sStateTableEvents_t * | psStateTableEvents_t |
typedef struct stateMachine | sStateMachine_t |
All nesseccary data for a state machine. More... | |
typedef sStateMachine_t * | psStateMachine_t |
Enumerations | |
enum | specialStates { FAULT_STATE = -1, FINAL_STATE = -2 } |
Special states to use with nextStateId in sStateTransitions_t. More... | |
enum | specialEvents { NO_EVENT = -1, TIME_EVENT = -2 } |
Special events that can occur while the state machine is running. More... | |
Functions | |
_Bool | bFsmframeworkInitialize (psStateMachine_t psStateMachine, psStateTable_t psStateTable, int32_t s32StartState, uint32_t u32StateCount, uint32_t u32EventCount, vCallback_t vInitCallback) |
Initialization of the State Machine. More... | |
_Bool | bFsmframeworkDispatchEvent (psStateMachine_t psStateMachine, int32_t s32Event) |
Dispatch Event. More... | |
int32_t | s32FsmframeworkGetState (psStateMachine_t psStateMachine) |
Get the actual state of a statemachine. More... | |
_Bool | bFsmframeworkIsStateChanged (psStateMachine_t psStateMachine) |
Get the statechanged flag. 1 if last event changed the state, 0 if last event did not changed the state. More... | |
Variables | |
int32_t | s32EventId |
bCallbackGuard_t | bGuardCb |
vCallback_t | vTransitionCb |
int32_t | s32NextStateId |
int32_t | s32StateId |
vCallback_t | vOnEntry |
vCallback_t | vOnDo |
vCallback_t | vOnExit |
psStateTransitions_t | psStateEvents |
psStateTable_t | psNestedStateTable |
uint32_t | u32StateMachineId |
int32_t | s32ActualState |
int32_t | s32NextState |
uint32_t | u32StateCount |
uint32_t | u32EventCount |
_Bool | bStateChanged |
psStateTable_t | psStateTable |
Header-File for the state machine.
This statemachine framework can be used for easy implementing an own state machine. The only thing you need is a two-dimensional state transition table with all states and events.
There are some limitations and restrictions to this implementation of a statemachine framework.
#define IS_IN | ( | statemachine, | |
state | |||
) | (statemachine.s32ActualState == state) |
MACRO checking if statemachine is in state.
#define SW_USE_ONDO 0 |
Set to one, if onDo() functions are needed.
#define SW_USE_ONENTRY 1 |
Set to one, if onEntry() functions are needed.
#define SW_USE_ONEXIT 1 |
Set to one, if onExit() functions are needed.
#define SW_USE_TRANSITIONFUNCTION 1 |
Set to one, if transition functions are nedded.
typedef _Bool(* bCallbackGuard_t) (void) |
Callback for guard functions, that return either true or false.
typedef enum specialEvents eSpecialEvents_t |
Special events that can occur while the state machine is running.
typedef enum specialStates eSpecialStates_t |
Special states to use with nextStateId in sStateTransitions_t.
typedef sStateMachine_t* psStateMachine_t |
typedef sStateTable_t* psStateTable_t |
typedef sStateTableEvents_t* psStateTableEvents_t |
typedef sStateTransitions_t* psStateTransitions_t |
typedef struct stateMachine sStateMachine_t |
All nesseccary data for a state machine.
This struct holds all data that is needed by a state machine. Saving the state table is important, because it is needed to identify the state machine.
typedef struct stateTableEvents sStateTable_t |
Forward declaration of stateTableEvents
typedef struct stateTableEvents sStateTableEvents_t |
State table holds states and corresponding event tables.
An entry in state table holds the state id for which the entry is created, as well as the event table and three callbacks for functions that are called on state entry, exit and while beeing in the state. Not used functions should be null.
typedef struct stateTransition sStateTransitions_t |
Event table holds events that can generate a state transition.
An entry for the event table holds the event, that generates a state transition as well as callbacks for the guard check and the transition function. A transition between two states can only be done, if an event occurs and the guard is true, otherwise the state won't change. If both are true, the transition function will be called, if there is one and the state changes to the nextStateId. A Table should only hold events for one state, so each state should have it's own event table.
typedef void(* vCallback_t) (void) |
Callback typedef for better readable code.
enum specialEvents |
enum specialStates |
_Bool bFsmframeworkDispatchEvent | ( | psStateMachine_t | psStateMachine, |
int32_t | s32Event | ||
) |
Dispatch Event.
_Bool bFsmframeworkInitialize | ( | psStateMachine_t | psStateMachine, |
psStateTable_t | psStateTable, | ||
int32_t | s32StartState, | ||
uint32_t | u32StateCount, | ||
uint32_t | u32EventCount, | ||
vCallback_t | vInitCallback | ||
) |
Initialization of the State Machine.
_Bool bFsmframeworkIsStateChanged | ( | psStateMachine_t | psStateMachine | ) |
Get the statechanged flag. 1 if last event changed the state, 0 if last event did not changed the state.
int32_t s32FsmframeworkGetState | ( | psStateMachine_t | psStateMachine | ) |
Get the actual state of a statemachine.
bCallbackGuard_t bGuardCb |
_Bool bStateChanged |
psStateTable_t psNestedStateTable |
psStateTransitions_t psStateEvents |
psStateTable_t psStateTable |
int32_t s32ActualState |
int32_t s32EventId |
int32_t s32NextState |
int32_t s32NextStateId |
int32_t s32StateId |
uint32_t u32EventCount |
uint32_t u32StateCount |
uint32_t u32StateMachineId |
vCallback_t vOnDo |
vCallback_t vOnEntry |
vCallback_t vOnExit |
vCallback_t vTransitionCb |