Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
states.h
Go to the documentation of this file.
1
10#ifndef INFUSE_SDK_INCLUDE_INFUSE_STATES_H_
11#define INFUSE_SDK_INCLUDE_INFUSE_STATES_H_
12
13#include <stdint.h>
14#include <stdbool.h>
15
16#include <zephyr/sys/atomic.h>
17#include <zephyr/sys/slist.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
35 /* Device is about to reboot */
37 /* Application is active according to KV-store values */
39 /* Application has a valid time source */
41 /* Device is stationary (not moving) */
43 /* Device is currently sending high-priority data to the cloud */
45 /* Device started moving */
47 /* Device stopped moving */
49 /* Start of application-specific state range */
51 INFUSE_STATES_END = UINT8_MAX
52};
53
54/* Required size of atomic array for Infuse-IoT application states */
55#define INFUSE_STATES_ARRAY_SIZE ATOMIC_BITMAP_SIZE(INFUSE_STATES_END + 1)
56
60#define INFUSE_STATES_ARRAY(name) atomic_t name[INFUSE_STATES_ARRAY_SIZE]
61
72 void (*state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx);
73
80 void (*state_cleared)(enum infuse_state state, void *user_ctx);
81
82 /* User provided context pointer */
83 void *user_ctx;
84
85 sys_snode_t node;
86};
87
94
104
116
129bool infuse_state_set_timeout(enum infuse_state state, uint16_t timeout);
130
141
150
159static inline bool infuse_state_set_to(enum infuse_state state, bool val)
160{
161 if (val) {
162 return infuse_state_set(state);
163 } else {
164 return infuse_state_clear(state);
165 }
166}
167
176
183
197
202#ifdef __cplusplus
203}
204#endif
205
206#endif /* INFUSE_SDK_INCLUDE_INFUSE_STATES_H_ */
void infuse_state_register_callback(struct infuse_state_cb *cb)
Register to be notified of state update events.
#define INFUSE_STATES_ARRAY_SIZE
Definition states.h:55
bool infuse_state_clear(enum infuse_state state)
Clear an application state.
void infuse_states_tick(atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
Run one tick of the state timeouts.
bool infuse_state_unregister_callback(struct infuse_state_cb *cb)
Unregister previously registered callback structure.
bool infuse_state_set(enum infuse_state state)
Set an application state.
void infuse_states_snapshot(atomic_t snapshot[ATOMIC_BITMAP_SIZE(INFUSE_STATES_END+1)])
Get a snapshot of the current application states.
static bool infuse_state_set_to(enum infuse_state state, bool val)
Set an application state to a specific value.
Definition states.h:159
bool infuse_state_get(enum infuse_state state)
Get an application state.
int infuse_state_get_timeout(enum infuse_state state)
Get the timeout associated with a state.
bool infuse_state_set_timeout(enum infuse_state state, uint16_t timeout)
Set an application state that times out after a duration.
infuse_state
Infuse-IoT application states.
Definition states.h:34
@ INFUSE_STATE_DEVICE_STATIONARY
Definition states.h:42
@ INFUSE_STATE_HIGH_PRIORITY_UPLINK
Definition states.h:44
@ INFUSE_STATE_DEVICE_STARTED_MOVING
Definition states.h:46
@ INFUSE_STATE_APPLICATION_ACTIVE
Definition states.h:38
@ INFUSE_STATE_REBOOTING
Definition states.h:36
@ INFUSE_STATE_TIME_KNOWN
Definition states.h:40
@ INFUSE_STATES_APP_START
Definition states.h:50
@ INFUSE_STATES_END
Definition states.h:51
@ INFUSE_STATE_DEVICE_STOPPED_MOVING
Definition states.h:48
Infuse-IoT application state callback structure.
Definition states.h:63
void(* state_cleared)(enum infuse_state state, void *user_ctx)
Application state has been cleared.
Definition states.h:80
void * user_ctx
Definition states.h:83
void(* state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx)
Application state has been set.
Definition states.h:72
sys_snode_t node
Definition states.h:85