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
16#include <zephyr/sys/util.h>
17
34#define SMF_CREATE_STATE(_entry, _run, _exit, _parent, _initial) \
35{ \
36 .entry = _entry, \
37 .run = _run, \
38 .exit = _exit, \
39 IF_ENABLED(CONFIG_SMF_ANCESTOR_SUPPORT, (.parent = _parent,)) \
40 IF_ENABLED(CONFIG_SMF_INITIAL_TRANSITION, (.initial = _initial,)) \
41}
42
49#define SMF_CTX(o) ((struct smf_ctx *)o)
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#include <zephyr/kernel.h>
56
62typedef void (*state_execution)(void *obj);
63
65struct smf_state {
85 const struct smf_state *parent;
86
87#ifdef CONFIG_SMF_INITIAL_TRANSITION
91 const struct smf_state *initial;
92#endif
93};
94
96struct smf_ctx {
98 const struct smf_state *current;
100 const struct smf_state *previous;
113};
114
121void smf_set_initial(struct smf_ctx *ctx, const struct smf_state *init_state);
122
131void smf_set_state(struct smf_ctx *ctx, const struct smf_state *new_state);
132
140void smf_set_terminate(struct smf_ctx *ctx, int32_t val);
141
149void smf_set_handled(struct smf_ctx *ctx);
150
161
162#ifdef __cplusplus
163}
164#endif
165
170#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:62
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:96
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:107
const struct smf_state * previous
Previous state the state machine executed.
Definition: smf.h:100
const struct smf_state * current
Current state the state machine is executing.
Definition: smf.h:98
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:112
General state that can be used in multiple state machines.
Definition: smf.h:65
const state_execution exit
Optional method that will be run when this state exists.
Definition: smf.h:74
const state_execution entry
Optional method that will be run when this state is entered.
Definition: smf.h:67
const state_execution run
Optional method that will be run repeatedly during state machine loop.
Definition: smf.h:72
const struct smf_state * parent
Optional parent state that contains common entry/run/exit implementation among various child states.
Definition: smf.h:85
Misc utilities.