Infuse-IoT SDK API 0.0.1
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
schedule.h
Go to the documentation of this file.
1
10#ifndef INFUSE_SDK_INCLUDE_INFUSE_TASK_RUNNER_SCHEDULE_H_
11#define INFUSE_SDK_INCLUDE_INFUSE_TASK_RUNNER_SCHEDULE_H_
12
13#include <stdint.h>
14#include <stdbool.h>
15
16#include <zephyr/toolchain.h>
17#include <zephyr/sys/atomic.h>
18
20
21#ifdef CONFIG_TASK_RUNNER_CUSTOM_TASK_DEFINITIONS
22#include CONFIG_TASK_RUNNER_CUSTOM_TASK_DEFINITIONS_PATH
23#endif /* CONFIG_TASK_RUNNER_CUSTOM_TASK_DEFINITIONS */
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
47 _TASK_VALID_END,
48 _TASK_VALID_MASK = 0x7F,
50};
51
63
65#define TR_NOT 0x100
66
69#define _TR_STATE_BASE 0xFF
70#define _TR_STATES_BIT_COMMON(state, idx) ((state) & TR_NOT ? BIT(idx) : 0)
71#define _TR_STATES_DEFINE_ALL(s0, s1, s2, s3) \
72 { \
73 .metadata = _TR_STATES_BIT_COMMON(s0, 0) | _TR_STATES_BIT_COMMON(s1, 1) | \
74 _TR_STATES_BIT_COMMON(s2, 2) | _TR_STATES_BIT_COMMON(s3, 3), \
75 .states = { \
76 (s0) & _TR_STATE_BASE, \
77 (s1) & _TR_STATE_BASE, \
78 (s2) & _TR_STATE_BASE, \
79 (s3) & _TR_STATE_BASE, \
80 } \
81 }
82
83#define _TR_GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
84#define _TR_STATES_1(arg1) _TR_STATES_DEFINE_ALL(arg1, 0, 0, 0)
85#define _TR_STATES_2(arg1, arg2) _TR_STATES_DEFINE_ALL(arg1, arg2, 0, 0)
86#define _TR_STATES_3(arg1, arg2, arg3) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, 0)
87#define _TR_STATES_4(arg1, arg2, arg3, arg4) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, arg4)
88
104#define TASK_STATES_DEFINE(...) \
105 _TR_GET_MACRO(__VA_ARGS__, _TR_STATES_4, _TR_STATES_3, _TR_STATES_2, _TR_STATES_1) \
106 (__VA_ARGS__)
107
113 uint8_t loggers;
115 uint8_t tdf_mask;
116} __packed;
117
125 /* Metadata associated with states (inversion) */
126 uint8_t metadata;
128 uint8_t states[4];
129};
130
136#define TASK_RUNNER_LOCKOUT_IGNORE_FIRST BIT(31)
137
144 uint8_t task_id;
146 uint8_t validity;
150 uint32_t timeout_s;
187 union task_args {
188 uint8_t raw[16];
190#ifdef CONFIG_TASK_RUNNER_CUSTOM_TASK_DEFINITIONS
191 union custom_task_arguments custom;
192#endif /* CONFIG_TASK_RUNNER_CUSTOM_TASK_DEFINITIONS */
194} __packed;
195
205
215typedef void (*task_schedule_event_cb_t)(const struct task_schedule *schedule,
216 enum task_schedule_event event);
217
229 uint32_t last_run;
231 uint32_t runtime;
235 uint8_t task_idx;
236#ifdef CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE
238 uint8_t runtime_state[CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE];
239#endif /* CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE */
240};
241
243#define _TASK_SCHEDULE_MAX_SCHEDULES(schedules) \
244 COND_CODE_1(CONFIG_KV_STORE_KEY_TASK_SCHEDULES, \
245 (CONFIG_KV_STORE_KEY_TASK_SCHEDULES_RANGE), (ARRAY_SIZE(schedules)))
257#define TASK_SCHEDULE_STATES_DEFINE(name, schedules) \
258 static struct task_schedule_state name[_TASK_SCHEDULE_MAX_SCHEDULES(schedules)]
259
271bool task_schedule_validate(const struct task_schedule *schedule);
272
286bool task_schedule_should_start(const struct task_schedule *schedule,
287 struct task_schedule_state *state, atomic_t *app_states,
288 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
289
304 struct task_schedule_state *state, atomic_t *app_states,
305 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
306
311#ifdef __cplusplus
312}
313#endif
314
315#endif /* INFUSE_SDK_INCLUDE_INFUSE_TASK_RUNNER_SCHEDULE_H_ */
bool task_schedule_should_start(const struct task_schedule *schedule, struct task_schedule_state *state, atomic_t *app_states, uint32_t uptime, uint32_t epoch_time, uint8_t battery)
Determine whether a task should start executing.
void(* task_schedule_event_cb_t)(const struct task_schedule *schedule, enum task_schedule_event event)
Callback notifying that an event has occurred on a schedule.
Definition schedule.h:215
task_runner_valid_type
Definition schedule.h:35
bool task_schedule_validate(const struct task_schedule *schedule)
Basic validity checking on task schedules.
bool task_schedule_should_terminate(const struct task_schedule *schedule, struct task_schedule_state *state, atomic_t *app_states, uint32_t uptime, uint32_t epoch_time, uint8_t battery)
Determine whether a task should be terminated.
task_runner_periodicity_type
Definition schedule.h:52
task_schedule_event
Events that can trigger callbacks.
Definition schedule.h:197
@ TASK_VALID_ACTIVE
Task is only valid when INFUSE_STATE_APPLICATION_ACTIVE is set.
Definition schedule.h:41
@ TASK_VALID_ALWAYS
Task is always valid.
Definition schedule.h:39
@ TASK_VALID_PERMANENTLY_RUNS
Entry and exit conditions never checked, task is rebooted if it terminates.
Definition schedule.h:45
@ TASK_LOCKED
Do not update definition from KV store.
Definition schedule.h:37
@ TASK_VALID_INACTIVE
Task is only valid when INFUSE_STATE_APPLICATION_ACTIVE is not set.
Definition schedule.h:43
@ TASK_PERIODICITY_FIXED
Task can only run on N second boundaries.
Definition schedule.h:54
@ TASK_PERIODICITY_AFTER
Task can only run N seconds after another schedule terminates.
Definition schedule.h:58
@ TASK_PERIODICITY_LOCKOUT
Task can only run N seconds after previous run started.
Definition schedule.h:56
@ TASK_SCHEDULE_STARTED
Task associated with the schedule has been started.
Definition schedule.h:199
@ TASK_SCHEDULE_STOPPED
Task associated with the schedule has stopped.
Definition schedule.h:203
@ TASK_SCHEDULE_TERMINATE_REQUEST
Task associated with the schedule has been requested to terminate.
Definition schedule.h:201
Task Runner Infuse-IoT task arguments.
Battery charge thresholds to start the task.
Definition schedule.h:152
uint8_t upper
Start task if <= this charge.
Definition schedule.h:156
uint8_t lower
Start task if >= this charge.
Definition schedule.h:154
Battery charge thresholds to terminate the task.
Definition schedule.h:159
uint8_t lower
Terminate task if <= this charge.
Definition schedule.h:161
uint8_t upper
Terminate task if >= this charge.
Definition schedule.h:163
uint16_t duration_s
Definition schedule.h:175
uint8_t schedule_idx
Definition schedule.h:174
uint32_t lockout_s
Definition schedule.h:171
uint32_t period_s
Definition schedule.h:168
Schedule state conditions.
Definition schedule.h:124
uint8_t metadata
Definition schedule.h:126
uint8_t states[4]
Array of states to test.
Definition schedule.h:128
State for a given task schedule.
Definition schedule.h:223
uint32_t last_run
System uptime that started the last run of this schedule.
Definition schedule.h:229
uint32_t last_terminate
System uptime at termination of last run of this schedule.
Definition schedule.h:233
uint32_t runtime
Duration of current run.
Definition schedule.h:231
uint8_t task_idx
Index into task array that corresponds with schedule task_id.
Definition schedule.h:235
struct task_schedule_state * linked
Linked schedule for TASK_PERIODICITY_AFTER.
Definition schedule.h:225
task_schedule_event_cb_t event_cb
Optional callback to be notified of schedule events.
Definition schedule.h:227
Control TDF logging output of a task.
Definition schedule.h:111
uint8_t loggers
TDF loggers to log to.
Definition schedule.h:113
uint8_t tdf_mask
TDFs to log (bitmask defined by the activity)
Definition schedule.h:115
Schedule for a given task.
Definition schedule.h:143
struct task_schedule::battery_start_thresholds battery_start
struct task_schedule_tdf_logging task_logging[2]
Task logging configuration.
Definition schedule.h:185
uint8_t task_id
Definition schedule.h:144
struct task_schedule_state_conditions states_terminate
Task termination state conditions.
Definition schedule.h:183
uint8_t periodicity_type
TASK_PERIODICITY_* value.
Definition schedule.h:148
uint16_t states_start_timeout_2x_s
states_start will evaluate as true 2x this many seconds after last run started
Definition schedule.h:179
uint32_t timeout_s
Duration after which task is requested to terminate.
Definition schedule.h:150
uint8_t validity
TASK_VALID_* value.
Definition schedule.h:146
union task_schedule::task_args task_args
union task_schedule::periodicity_args periodicity
struct task_schedule::battery_terminate_thresholds battery_terminate
struct task_schedule_state_conditions states_start
Task start state conditions.
Definition schedule.h:181
Definition infuse_task_args.h:31
Periodicity parameters.
Definition schedule.h:166
struct task_schedule::periodicity_args::periodicity_lockout lockout
struct task_schedule::periodicity_args::periodicity_periodic fixed
struct task_schedule::periodicity_args::periodicity_after after
Task specific arguments
Definition schedule.h:187
union infuse_task_arguments infuse
Definition schedule.h:189
uint8_t raw[16]
Definition schedule.h:188