Zephyr Project API 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
State Machine Framework API

State Machine Framework API. More...

Data Structures

struct  smf_state
 General state that can be used in multiple state machines. More...
 
struct  smf_ctx
 Defines the current context of the state machine. More...
 

Macros

#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial)
 Macro to create a hierarchical state with initial transitions.
 
#define SMF_CTX(o)   ((struct smf_ctx *)o)
 Macro to cast user defined object to state machine context.
 

Typedefs

typedef void(* state_method) (void *obj)
 Function pointer that implements a entry and exit actions of a state.
 
typedef enum smf_state_result(* state_execution) (void *obj)
 Function pointer that implements a the run action of a state.
 

Enumerations

enum  smf_state_result { SMF_EVENT_HANDLED , SMF_EVENT_PROPAGATE }
 enum for the return value of a state_execution function More...
 

Functions

void smf_set_initial (struct smf_ctx *ctx, const struct smf_state *init_state)
 Initializes the state machine and sets its initial state.
 
void smf_set_state (struct smf_ctx *ctx, const struct smf_state *new_state)
 Changes a state machines state.
 
void smf_set_terminate (struct smf_ctx *ctx, int32_t val)
 Terminate a state machine.
 
int32_t smf_run_state (struct smf_ctx *ctx)
 Runs one iteration of a state machine (including any parent states)
 

Detailed Description

State Machine Framework API.

Version
0.1.0

Macro Definition Documentation

◆ SMF_CREATE_STATE

#define SMF_CREATE_STATE (   _entry,
  _run,
  _exit,
  _parent,
  _initial 
)

#include <include/zephyr/smf.h>

Value:
{ \
.entry = _entry, \
.run = _run, \
.exit = _exit, \
IF_ENABLED(CONFIG_SMF_ANCESTOR_SUPPORT, (.parent = _parent,)) \
IF_ENABLED(CONFIG_SMF_INITIAL_TRANSITION, (.initial = _initial,)) \
}

Macro to create a hierarchical state with initial transitions.

Parameters
_entryState entry function or NULL
_runState run function or NULL
_exitState exit function or NULL
_parentState parent object or NULL
_initialState initial transition object or NULL

◆ SMF_CTX

#define SMF_CTX (   o)    ((struct smf_ctx *)o)

#include <include/zephyr/smf.h>

Macro to cast user defined object to state machine context.

Parameters
oA pointer to the user defined object

Typedef Documentation

◆ state_execution

typedef enum smf_state_result(* state_execution) (void *obj)

#include <include/zephyr/smf.h>

Function pointer that implements a the run action of a state.

Parameters
objpointer user defined object
Returns
If the event should be propagated to parent states or not (Ignored when CONFIG_SMF_ANCESTOR_SUPPORT not defined)

◆ state_method

typedef void(* state_method) (void *obj)

#include <include/zephyr/smf.h>

Function pointer that implements a entry and exit actions of a state.

Parameters
objpointer user defined object

Enumeration Type Documentation

◆ smf_state_result

#include <include/zephyr/smf.h>

enum for the return value of a state_execution function

Enumerator
SMF_EVENT_HANDLED 
SMF_EVENT_PROPAGATE 

Function Documentation

◆ smf_run_state()

int32_t smf_run_state ( struct smf_ctx ctx)

#include <include/zephyr/smf.h>

Runs one iteration of a state machine (including any parent states)

Parameters
ctxState machine context
Returns
A non-zero value should terminate the state machine. This non-zero value could represent a terminal state being reached or the detection of an error that should result in the termination of the state machine.

◆ smf_set_initial()

void smf_set_initial ( struct smf_ctx ctx,
const struct smf_state init_state 
)

#include <include/zephyr/smf.h>

Initializes the state machine and sets its initial state.

Parameters
ctxState machine context
init_stateInitial state the state machine starts in.

◆ smf_set_state()

void smf_set_state ( struct smf_ctx ctx,
const struct smf_state new_state 
)

#include <include/zephyr/smf.h>

Changes a state machines state.

This handles exiting the previous state and entering the target state. For HSMs the entry and exit actions of the Least Common Ancestor will not be run.

Parameters
ctxState machine context
new_stateState to transition to (NULL is valid and exits all states)

◆ smf_set_terminate()

void smf_set_terminate ( struct smf_ctx ctx,
int32_t  val 
)

#include <include/zephyr/smf.h>

Terminate a state machine.

Parameters
ctxState machine context
valNon-Zero termination value that's returned by the smf_run_state function.