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
9
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
27
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 /* Suppress LED activity */
51 /* Device is moving (not stationary) */
53 /* Start of application-specific state range */
56};
57
58/* Required size of atomic array for Infuse-IoT application states */
59#define INFUSE_STATES_ARRAY_SIZE ATOMIC_BITMAP_SIZE(INFUSE_STATES_END + 1)
60
64#define INFUSE_STATES_ARRAY(name) atomic_t name[INFUSE_STATES_ARRAY_SIZE]
65
76 void (*state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx);
77
84 void (*state_cleared)(enum infuse_state state, void *user_ctx);
85
86 /* User provided context pointer */
87 void *user_ctx;
88
89 sys_snode_t node;
90};
91
98
108
120
133bool infuse_state_set_timeout(enum infuse_state state, uint16_t timeout);
134
145
154
163static inline bool infuse_state_set_to(enum infuse_state state, bool val)
164{
165 if (val) {
166 return infuse_state_set(state);
167 } else {
168 return infuse_state_clear(state);
169 }
170}
171
180
187
201
205
206#ifdef __cplusplus
207}
208#endif
209
210#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:59
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:163
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_LED_SUPPRESS
Definition states.h:50
@ 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:54
@ INFUSE_STATES_END
Definition states.h:55
@ INFUSE_STATE_DEVICE_STOPPED_MOVING
Definition states.h:48
@ INFUSE_STATE_DEVICE_MOVING
Definition states.h:52
Infuse-IoT application state callback structure.
Definition states.h:67
void(* state_cleared)(enum infuse_state state, void *user_ctx)
Application state has been cleared.
Definition states.h:84
void * user_ctx
Definition states.h:87
void(* state_set)(enum infuse_state state, bool already, uint16_t timeout, void *user_ctx)
Application state has been set.
Definition states.h:76
sys_snode_t node
Definition states.h:89