nRF5 SDK v17.1.0
Data Structures | Macros | Typedefs | Functions
Finite State Machine API

Module to declare Finite State Machine API. More...

Data Structures

struct  sys_fsm_transition_t
 FSM transition description (item of FSM transition table). More...
 
struct  sys_fsm_const_descriptor_t
 Constant FSM descriptor which can reside in read-only memory. More...
 
struct  sys_fsm_t
 FSM dynamic descriptor, holding the current state of the FSM. More...
 

Macros

#define SYS_FSM_TRANSITION(event_id, guard_id, action_id, new_state_id)   {(event_id), (guard_id), (action_id), (new_state_id)}
 FSM transition declaration (item of FSM transition table).
 
#define SYS_FSM_STATE(state_id)   {(state_id) | SYS_FSM_STATE_FLAG, 0, 0, 0}
 FSM state declaration. More...
 
#define SYS_FSM_NO_GUARD   0xFF
 Empty guard condition ID. More...
 
#define SYS_FSM_OTHERWISE   0xFF
 Empty guard condition ID (useful synonym). More...
 
#define SYS_FSM_ALWAYS   0xFF
 Empty guard condition ID (useful synonym). More...
 
#define SYS_FSM_NO_ACTION   0xFF
 Empty action ID. More...
 
#define SYS_FSM_SAME_STATE   0xFF
 Same state ID. More...
 
#define SYS_FSM_ANY_STATE   0xFF
 Any state ID. More...
 
#define SYS_FSM_STATE_FLAG   0x80
 State declaration flag. More...
 
#define FSM_DEBUG_NAME(name_string)
 

Typedefs

typedef uint8_t sys_fsm_state_id_t
 Fixed-size type for FSM state ID.
 
typedef uint8_t sys_fsm_event_id_t
 Fixed-size type for FSM event ID.
 
typedef uint8_t sys_fsm_guard_id_t
 Fixed-size type for FSM guard condition ID.
 
typedef uint8_t sys_fsm_action_id_t
 Fixed-size type for FSM action ID.
 
typedef bool(* sys_fsm_guard_t )(sys_fsm_guard_id_t guard_id, void *p_data)
 Prototype of a user-defined FSM guard condition function. More...
 
typedef void(* sys_fsm_action_t )(sys_fsm_action_id_t action_id, void *p_data)
 Prototype of a user-defined FSM action function. More...
 

Functions

void sys_fsm_init (sys_fsm_t *p_fsm, const sys_fsm_const_descriptor_t *p_fsm_const)
 Function for initializing a specific FSM. More...
 
void sys_fsm_event_post (sys_fsm_t *p_fsm, sys_fsm_event_id_t event_id, void *p_data)
 Function for posting an event to FSM. More...
 

Detailed Description

Module to declare Finite State Machine API.

The FSM module implements the Finite State Machine abstraction. The user is intended to implement a transition table of states with guards and actions in order to represent some event-driven subject. When a table is implemented, call sys_fsm_init() to initialize the FSM. After that, the only routine to work with FSM is sys_fsm_event_post().

Macro Definition Documentation

#define SYS_FSM_ALWAYS   0xFF

Empty guard condition ID (useful synonym).

Special value of the guard_id field. If it is used in transition declaration, guard check will be omitted.

#define SYS_FSM_ANY_STATE   0xFF

Any state ID.

Special value of the event_id field. If it is used in transition declaration table, then the transitions listed in this state will be applied in case they have not been listed in the transition table for the current FSM state. Only one SYS_FSM_STATE(SYS_FSM_ANY_STATE) can be present in the transition table.

#define SYS_FSM_NO_ACTION   0xFF

Empty action ID.

Special value of the action_id field. If it is used in transition declaration, no action will be performed during the transition.

#define SYS_FSM_NO_GUARD   0xFF

Empty guard condition ID.

Special value of the guard_id field. If it is used in transition declaration, guard check will be omitted.

#define SYS_FSM_OTHERWISE   0xFF

Empty guard condition ID (useful synonym).

Special value of the guard_id field. If it is used in transition declaration, guard check will be omitted.

#define SYS_FSM_SAME_STATE   0xFF

Same state ID.

Special value of the next_state_id field. If it is used in transition declaration, the current state will not be changed.

#define SYS_FSM_STATE (   state_id)    {(state_id) | SYS_FSM_STATE_FLAG, 0, 0, 0}

FSM state declaration.

The state is an aggregator item of the FSM transition table, aggregating the transitions, declared immediately after this state declaration. All transition declaration items, following the state declaration item, will be aggregated in this state, until the next state declaration item, or the "end of table" item.

#define SYS_FSM_STATE_FLAG   0x80

State declaration flag.

Special flag of the event_id field. This flag is used to distinguish between state declaration and transition declaration.

Typedef Documentation

typedef void(* sys_fsm_action_t)(sys_fsm_action_id_t action_id, void *p_data)

Prototype of a user-defined FSM action function.

You must implement a single FSM action function which will use an ID of the needed action as a parameter.

Parameters
[in]action_idAction ID to be performed.
[in]p_dataAdditional FSM specific data.
typedef bool(* sys_fsm_guard_t)(sys_fsm_guard_id_t guard_id, void *p_data)

Prototype of a user-defined FSM guard condition function.

You must implement a single FSM guard condition function which will use an ID of the needed guard check as a parameter.

Parameters
[in]guard_idGuard condition ID to be checked.
[in]p_dataAdditional FSM specific data.
Return values
trueTransition is allowed, false otherwise.

Function Documentation

void sys_fsm_event_post ( sys_fsm_t p_fsm,
sys_fsm_event_id_t  event_id,
void *  p_data 
)

Function for posting an event to FSM.

This function causes FSM transition from the current state to the new state, according to the transition table of this FSM. The corresponding guard check and action is performed.

Parameters
[in]p_fsmPointer to FSM descriptor.
[in]event_idEvent ID to post.
[in]p_dataPointer to the FSM-specific data.
void sys_fsm_init ( sys_fsm_t p_fsm,
const sys_fsm_const_descriptor_t p_fsm_const 
)

Function for initializing a specific FSM.

Parameters
[in]p_fsmPointer to FSM descriptor to initialize.
[in]p_fsm_constPointer to constant FSM descriptor with transition table, etc.

Documentation feedback | Developer Zone | Subscribe | Updated