13#ifndef ZEPHYR_INCLUDE_SMF_H_
14#define ZEPHYR_INCLUDE_SMF_H_
36#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
41 IF_ENABLED(CONFIG_SMF_ANCESTOR_SUPPORT, (.parent = _parent,)) \
42 IF_ENABLED(CONFIG_SMF_INITIAL_TRANSITION, (.initial = _initial,)) \
52#define SMF_CTX(o) ((struct smf_ctx *)o)
79#define SMF_ERR_NULL_TRANSITION 1
80#define SMF_ERR_TRANSITION_IN_EXIT 2
82#if defined(CONFIG_SMF_INSTRUMENTATION) || defined(__DOXYGEN__)
158#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
171#ifdef CONFIG_SMF_INITIAL_TRANSITION
187#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
204#ifdef CONFIG_SMF_INSTRUMENTATION
237#ifdef CONFIG_SMF_INSTRUMENTATION
287#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
288 return ctx->executing;
smf_state_result
enum for the return value of a state_execution function
Definition smf.h:63
enum smf_state_result(* state_execution)(void *obj)
Function pointer that implements a the run action of a state.
Definition smf.h:143
void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state)
Changes a state machines state.
void smf_set_initial(struct smf_ctx *ctx, const struct smf_state *init_state)
Initializes the state machine and sets its initial state.
int32_t smf_run_state(struct smf_ctx *ctx)
Runs one iteration of a state machine (including any parent states)
void(* smf_error_hook)(struct smf_ctx *ctx, int error_code)
Called when an invalid operation is detected.
Definition smf.h:114
void smf_set_terminate(struct smf_ctx *ctx, int32_t val)
Terminate a state machine.
void(* smf_action_hook)(struct smf_ctx *ctx, const struct smf_state *state, enum smf_action_type action_type)
Called before a state action (entry/run/exit) is invoked.
Definition smf.h:105
static const struct smf_state * smf_get_current_leaf_state(const struct smf_ctx *const ctx)
Get the current leaf state.
Definition smf.h:273
void(* state_method)(void *obj)
Function pointer that implements a entry and exit actions of a state.
Definition smf.h:134
smf_action_type
Enum identifying which action type is being executed.
Definition smf.h:72
static const struct smf_state * smf_get_current_executing_state(const struct smf_ctx *const ctx)
Get the state that is currently executing.
Definition smf.h:285
void(* smf_transition_hook)(struct smf_ctx *ctx, const struct smf_state *source, const struct smf_state *dest)
Called after the current state pointer is updated, before entry actions of the new state execute.
Definition smf.h:95
@ SMF_EVENT_HANDLED
Definition smf.h:64
@ SMF_EVENT_PROPAGATE
Definition smf.h:65
@ SMF_ACTION_RUN
Run action.
Definition smf.h:74
@ SMF_ACTION_EXIT
Exit action.
Definition smf.h:75
@ SMF_ACTION_ENTRY
Entry action.
Definition smf.h:73
state
Definition parser_state.h:29
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
Defines the current context of the state machine.
Definition smf.h:181
int32_t terminate_val
This value is set by the set_terminate function and should terminate the state machine when its set t...
Definition smf.h:197
const struct smf_state * previous
Previous state the state machine executed.
Definition smf.h:185
const struct smf_state * current
Current state the state machine is executing.
Definition smf.h:183
uint32_t internal
The state machine casts this to a "struct internal_ctx" and it's used to track state machine context.
Definition smf.h:202
Collection of optional instrumentation hooks.
Definition smf.h:121
smf_error_hook on_error
Hook called on error.
Definition smf.h:124
smf_transition_hook on_transition
Hook called on transition.
Definition smf.h:122
smf_action_hook on_action
Hook called on entry/run/exit actions.
Definition smf.h:123
General state that can be used in multiple state machines.
Definition smf.h:146
const state_method exit
Optional method that will be run when this state exists.
Definition smf.h:157
const state_method entry
Optional method that will be run when this state is entered.
Definition smf.h:148
const state_execution run
Optional method that will be run repeatedly during state machine loop.
Definition smf.h:154