Zephyr API 3.6.99
Loading...
Searching...
No Matches
smf.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 The Chromium OS Authors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
13#ifndef ZEPHYR_INCLUDE_SMF_H_
14#define ZEPHYR_INCLUDE_SMF_H_
15
16#include <zephyr/sys/util.h>
17
35#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
36{ \
37 .entry = _entry, \
38 .run = _run, \
39 .exit = _exit, \
40 IF_ENABLED(CONFIG_SMF_ANCESTOR_SUPPORT, (.parent = _parent,)) \
41 IF_ENABLED(CONFIG_SMF_INITIAL_TRANSITION, (.initial = _initial,)) \
42}
43
50#define SMF_CTX(o) ((struct smf_ctx *)o)
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56#include <zephyr/kernel.h>
57
63typedef void (*state_execution)(void *obj);
64
66struct smf_state {
76#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
87 const struct smf_state *parent;
88
89#ifdef CONFIG_SMF_INITIAL_TRANSITION
93 const struct smf_state *initial;
94#endif /* CONFIG_SMF_INITIAL_TRANSITION */
95#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
96};
97
99struct smf_ctx {
101 const struct smf_state *current;
103 const struct smf_state *previous;
104
105#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
107 const struct smf_state *executing;
108#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
121};
122
129void smf_set_initial(struct smf_ctx *ctx, const struct smf_state *init_state);
130
139void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);
140
148void smf_set_terminate(struct smf_ctx *ctx, int32_t val);
149
157void smf_set_handled(struct smf_ctx *ctx);
158
169
170#ifdef __cplusplus
171}
172#endif
173
178#endif /* ZEPHYR_INCLUDE_SMF_H_ */
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_set_handled(struct smf_ctx *ctx)
Tell the SMF to stop propagating the event to ancestors.
void smf_set_terminate(struct smf_ctx *ctx, int32_t val)
Terminate a state machine.
void(* state_execution)(void *obj)
Function pointer that implements a portion of a state.
Definition smf.h:63
Public kernel APIs.
__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:99
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:115
const struct smf_state * previous
Previous state the state machine executed.
Definition smf.h:103
const struct smf_state * current
Current state the state machine is executing.
Definition smf.h:101
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:120
General state that can be used in multiple state machines.
Definition smf.h:66
const state_execution exit
Optional method that will be run when this state exists.
Definition smf.h:75
const state_execution entry
Optional method that will be run when this state is entered.
Definition smf.h:68
const state_execution run
Optional method that will be run repeatedly during state machine loop.
Definition smf.h:73
Misc utilities.