Zephyr Project API 3.7.0
A Scalable Open Source RTOS
|
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_execution) (void *obj) |
Function pointer that implements a portion of a state. | |
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. | |
void | smf_set_handled (struct smf_ctx *ctx) |
Tell the SMF to stop propagating the event to ancestors. | |
int32_t | smf_run_state (struct smf_ctx *ctx) |
Runs one iteration of a state machine (including any parent states) | |
State Machine Framework API.
#define SMF_CREATE_STATE | ( | _entry, | |
_run, | |||
_exit, | |||
_parent, | |||
_initial | |||
) |
#include <include/zephyr/smf.h>
Macro to create a hierarchical state with initial transitions.
_entry | State entry function or NULL |
_run | State run function or NULL |
_exit | State exit function or NULL |
_parent | State parent object or NULL |
_initial | State initial transition object or NULL |
#define SMF_CTX | ( | o | ) | ((struct smf_ctx *)o) |
#include <include/zephyr/smf.h>
Macro to cast user defined object to state machine context.
o | A pointer to the user defined object |
typedef void(* state_execution) (void *obj) |
#include <include/zephyr/smf.h>
Function pointer that implements a portion of a state.
obj | pointer user defined object |
#include <include/zephyr/smf.h>
Runs one iteration of a state machine (including any parent states)
ctx | State machine context |
void smf_set_handled | ( | struct smf_ctx * | ctx | ) |
#include <include/zephyr/smf.h>
Tell the SMF to stop propagating the event to ancestors.
This allows HSMs to implement 'programming by difference' where substates can handle events on their own or propagate up to a common handler.
ctx | State machine context |
#include <include/zephyr/smf.h>
Initializes the state machine and sets its initial state.
ctx | State machine context |
init_state | Initial state the state machine starts in. |
#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.
ctx | State machine context |
new_state | State to transition to (NULL is valid and exits all states) |
#include <include/zephyr/smf.h>
Terminate a state machine.
ctx | State machine context |
val | Non-Zero termination value that's returned by the smf_run_state function. |