Labor04
State Machine header.

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_tpsStateTable_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_tpsStateTransitions_t
 
typedef struct stateTableEvents sStateTableEvents_t
 State table holds states and corresponding event tables. More...
 
typedef sStateTableEvents_tpsStateTableEvents_t
 
typedef struct stateMachine sStateMachine_t
 All nesseccary data for a state machine. More...
 
typedef sStateMachine_tpsStateMachine_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
 

Detailed Description

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.

Macro Definition Documentation

◆ IS_IN

#define IS_IN (   statemachine,
  state 
)    (statemachine.s32ActualState == state)

MACRO checking if statemachine is in state.

◆ SW_USE_ONDO

#define SW_USE_ONDO   0

Set to one, if onDo() functions are needed.

◆ SW_USE_ONENTRY

#define SW_USE_ONENTRY   1

Set to one, if onEntry() functions are needed.

◆ SW_USE_ONEXIT

#define SW_USE_ONEXIT   1

Set to one, if onExit() functions are needed.

◆ SW_USE_TRANSITIONFUNCTION

#define SW_USE_TRANSITIONFUNCTION   1

Set to one, if transition functions are nedded.

Typedef Documentation

◆ bCallbackGuard_t

typedef _Bool(* bCallbackGuard_t) (void)

Callback for guard functions, that return either true or false.

◆ eSpecialEvents_t

Special events that can occur while the state machine is running.

◆ eSpecialStates_t

Special states to use with nextStateId in sStateTransitions_t.

◆ psStateMachine_t

◆ psStateTable_t

◆ psStateTableEvents_t

◆ psStateTransitions_t

◆ sStateMachine_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.

◆ sStateTable_t

Forward declaration of 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.

◆ 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.

◆ vCallback_t

typedef void(* vCallback_t) (void)

Callback typedef for better readable code.

Enumeration Type Documentation

◆ specialEvents

Special events that can occur while the state machine is running.

Enumerator
NO_EVENT 
TIME_EVENT 

◆ specialStates

Special states to use with nextStateId in sStateTransitions_t.

Enumerator
FAULT_STATE 
FINAL_STATE 

Function Documentation

◆ bFsmframeworkDispatchEvent()

_Bool bFsmframeworkDispatchEvent ( psStateMachine_t  psStateMachine,
int32_t  s32Event 
)

Dispatch Event.

Here is the caller graph for this function:

◆ bFsmframeworkInitialize()

_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.

Here is the caller graph for this function:

◆ bFsmframeworkIsStateChanged()

_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.

Here is the caller graph for this function:

◆ s32FsmframeworkGetState()

int32_t s32FsmframeworkGetState ( psStateMachine_t  psStateMachine)

Get the actual state of a statemachine.

Here is the caller graph for this function:

Variable Documentation

◆ bGuardCb

bCallbackGuard_t bGuardCb

◆ bStateChanged

_Bool bStateChanged

◆ psNestedStateTable

psStateTable_t psNestedStateTable

◆ psStateEvents

psStateTransitions_t psStateEvents

◆ psStateTable

psStateTable_t psStateTable

◆ s32ActualState

int32_t s32ActualState

◆ s32EventId

int32_t s32EventId

◆ s32NextState

int32_t s32NextState

◆ s32NextStateId

int32_t s32NextStateId

◆ s32StateId

int32_t s32StateId

◆ u32EventCount

uint32_t u32EventCount

◆ u32StateCount

uint32_t u32StateCount

◆ u32StateMachineId

uint32_t u32StateMachineId

◆ vOnDo

vCallback_t vOnDo

◆ vOnEntry

vCallback_t vOnEntry

◆ vOnExit

vCallback_t vOnExit

◆ vTransitionCb

vCallback_t vTransitionCb