Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
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
23#ifdef CONFIG_SMF_ANCESTOR_SUPPORT
32#ifndef CONFIG_SMF_INITIAL_TRANSITION
33#define SMF_CREATE_STATE(_entry, _run, _exit, _parent) \
34{ \
35 .entry = _entry, \
36 .run = _run, \
37 .exit = _exit, \
38 .parent = _parent \
39}
40#else
50#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
51{ \
52 .entry = _entry, \
53 .run = _run, \
54 .exit = _exit, \
55 .parent = _parent, \
56 .initial = _initial \
57}
58#endif /* CONFIG_SMF_INITIAL_TRANSITION */
59
60#else
61
69#define SMF_CREATE_STATE(_entry, _run, _exit) \
70{ \
71 .entry = _entry, \
72 .run = _run, \
73 .exit = _exit \
74}
75
76#endif /* CONFIG_SMF_ANCESTOR_SUPPORT */
77
84#define SMF_CTX(o) ((struct smf_ctx *)o)
85
86#ifdef __cplusplus
87extern "C" {
88#endif
89
90#include <zephyr/kernel.h>
91
97typedef void (*state_execution)(void *obj);
98
100struct smf_state {
120 const struct smf_state *parent;
121
122#ifdef CONFIG_SMF_INITIAL_TRANSITION
126 const struct smf_state *initial;
127#endif
128};
129
131struct smf_ctx {
133 const struct smf_state *current;
135 const struct smf_state *previous;
148};
149
156void smf_set_initial(struct smf_ctx *ctx, const struct smf_state *init_state);
157
166void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);
167
175void smf_set_terminate(struct smf_ctx *ctx, int32_t val);
176
184void smf_set_handled(struct smf_ctx *ctx);
185
196
197#ifdef __cplusplus
198}
199#endif
200
205#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:97
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:131
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:142
const struct smf_state * previous
Previous state the state machine executed.
Definition: smf.h:135
const struct smf_state * current
Current state the state machine is executing.
Definition: smf.h:133
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:147
General state that can be used in multiple state machines.
Definition: smf.h:100
const state_execution exit
Optional method that will be run when this state exists.
Definition: smf.h:109
const state_execution entry
Optional method that will be run when this state is entered.
Definition: smf.h:102
const state_execution run
Optional method that will be run repeatedly during state machine loop.
Definition: smf.h:107
const struct smf_state * parent
Optional parent state that contains common entry/run/exit implementation among various child states.
Definition: smf.h:120