|
Zephyr Project API 4.3.99
A Scalable Open Source RTOS
|
State Machine Framework API. More...
Data Structures | |
| struct | smf_hooks |
| Collection of optional instrumentation hooks. More... | |
| 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) |
| Macro to cast user defined object to state machine context. | |
| #define | SMF_ERR_NULL_TRANSITION 1 |
| Error codes reported via the instrumentation error hook. | |
| #define | SMF_ERR_TRANSITION_IN_EXIT 2 |
| smf_set_state called in exit action | |
Typedefs | |
| typedef 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. | |
| typedef 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. | |
| typedef void(* | smf_error_hook) (struct smf_ctx *ctx, int error_code) |
| Called when an invalid operation is detected. | |
| 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... | |
| enum | smf_action_type { SMF_ACTION_ENTRY , SMF_ACTION_RUN , SMF_ACTION_EXIT } |
| Enum identifying which action type is being executed. 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) | |
| static const struct smf_state * | smf_get_current_leaf_state (const struct smf_ctx *const ctx) |
| Get the current leaf state. | |
| static const struct smf_state * | smf_get_current_executing_state (const struct smf_ctx *const ctx) |
| Get the state that is currently executing. | |
State Machine Framework API.
| #define SMF_CREATE_STATE | ( | _entry, | |
| _run, | |||
| _exit, | |||
| _parent, | |||
| _initial ) |
#include </__w/bridle/bridle/workspace/zephyr/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 | ) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Macro to cast user defined object to state machine context.
| o | A pointer to the user defined object |
| #define SMF_ERR_NULL_TRANSITION 1 |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Error codes reported via the instrumentation error hook.
new_state is NULL in smf_set_state
| #define SMF_ERR_TRANSITION_IN_EXIT 2 |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
smf_set_state called in exit action
| typedef void(* smf_action_hook) (struct smf_ctx *ctx, const struct smf_state *state, enum smf_action_type action_type) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Called before a state action (entry/run/exit) is invoked.
| ctx | State machine context |
| state | The state whose action is about to execute |
| action_type | Which action (entry, run, or exit) |
| typedef void(* smf_error_hook) (struct smf_ctx *ctx, int error_code) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Called when an invalid operation is detected.
| ctx | State machine context |
| error_code | One of SMF_ERR_* defines |
| typedef void(* smf_transition_hook) (struct smf_ctx *ctx, const struct smf_state *source, const struct smf_state *dest) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Called after the current state pointer is updated, before entry actions of the new state execute.
| ctx | State machine context |
| source | Previous state (before transition) |
| dest | New current state (after transition) |
| typedef enum smf_state_result(* state_execution) (void *obj) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Function pointer that implements a the run action of a state.
| obj | pointer user defined object |
| typedef void(* state_method) (void *obj) |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Function pointer that implements a entry and exit actions of a state.
| obj | pointer user defined object |
| enum smf_action_type |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Enum identifying which action type is being executed.
| Enumerator | |
|---|---|
| SMF_ACTION_ENTRY | Entry action. |
| SMF_ACTION_RUN | Run action. |
| SMF_ACTION_EXIT | Exit action. |
| enum smf_state_result |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
enum for the return value of a state_execution function
| Enumerator | |
|---|---|
| SMF_EVENT_HANDLED | |
| SMF_EVENT_PROPAGATE | |
|
inlinestatic |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Get the state that is currently executing.
This may be a parent state.
| ctx | State machine context |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Get the current leaf state.
| ctx | State machine context |
#include </__w/bridle/bridle/workspace/zephyr/include/zephyr/smf.h>
Runs one iteration of a state machine (including any parent states)
| ctx | State machine context |
#include </__w/bridle/bridle/workspace/zephyr/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 </__w/bridle/bridle/workspace/zephyr/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 </__w/bridle/bridle/workspace/zephyr/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. |