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
9
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 __cplusplus
22extern "C" {
23#endif
24
30
45 _TASK_VALID_END,
46 _TASK_VALID_MASK = 0x7F,
48};
49
63
65#define TR_NOT 0x100
67#define TR_OR 0x200
69#define TR_AND 0x00
70
72
73#define _TR_STATE_BASE 0xFF
74#define _TR_NOT_BIT_COMMON(state, idx) ((state) & TR_NOT ? BIT(idx) : 0)
75#define _TR_OR_BIT_COMMON(state, idx) ((state) & TR_OR ? BIT(idx) : 0)
76#define _TR_STATES_DEFINE_ALL(s0, s1, s2, s3) \
77 { \
78 .metadata = _TR_NOT_BIT_COMMON(s0, 0) | _TR_NOT_BIT_COMMON(s1, 1) | \
79 _TR_NOT_BIT_COMMON(s2, 2) | _TR_NOT_BIT_COMMON(s3, 3) | \
80 _TR_OR_BIT_COMMON(s0, 4) | _TR_OR_BIT_COMMON(s1, 5) | \
81 _TR_OR_BIT_COMMON(s2, 6) | _TR_OR_BIT_COMMON(s3, 7), \
82 .states = { \
83 (s0) & _TR_STATE_BASE, \
84 (s1) & _TR_STATE_BASE, \
85 (s2) & _TR_STATE_BASE, \
86 (s3) & _TR_STATE_BASE, \
87 } \
88 }
89
90#define _TR_GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
91#define _TR_STATES_1(arg1) _TR_STATES_DEFINE_ALL(arg1, 0, 0, 0)
92#define _TR_STATES_2(arg1, arg2) _TR_STATES_DEFINE_ALL(arg1, arg2, 0, 0)
93#define _TR_STATES_3(arg1, arg2, arg3) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, 0)
94#define _TR_STATES_4(arg1, arg2, arg3, arg4) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, arg4)
95
97
116#define TASK_STATES_DEFINE(...) \
117 _TR_GET_MACRO(__VA_ARGS__, _TR_STATES_4, _TR_STATES_3, _TR_STATES_2, _TR_STATES_1) \
118 (__VA_ARGS__)
119
129#define TASK_STATES_START_TIMEOUT(seconds) ((seconds) / 2)
130
136 uint8_t loggers;
138 uint8_t tdf_mask;
139} __packed;
140
148 /* Metadata associated with states (inversion) */
149 uint8_t metadata;
151 uint8_t states[4];
152} __packed;
153
159#define TASK_RUNNER_LOCKOUT_IGNORE_FIRST BIT(31)
160
232
234BUILD_ASSERT(sizeof(union task_arguments) == 17);
235
245
255typedef void (*task_schedule_event_cb_t)(const struct task_schedule *schedule,
256 enum task_schedule_event event);
257
269 uint32_t last_run;
271 uint32_t runtime;
275 uint8_t task_idx;
276#ifdef CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE
278 uint8_t runtime_state[CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE];
279#endif /* CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE */
280};
281
283#define _TASK_SCHEDULE_MAX_SCHEDULES(schedules) \
284 COND_CODE_1(CONFIG_KV_STORE_KEY_TASK_SCHEDULES, \
285 (CONFIG_KV_STORE_KEY_TASK_SCHEDULES_RANGE), (ARRAY_SIZE(schedules)))
287
297#define TASK_SCHEDULE_STATES_DEFINE(name, schedules) \
298 static struct task_schedule_state name[_TASK_SCHEDULE_MAX_SCHEDULES(schedules)]
299
311bool task_schedule_validate(const struct task_schedule *schedule);
312
326bool task_schedule_should_start(const struct task_schedule *schedule,
327 struct task_schedule_state *state, atomic_t *app_states,
328 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
329
344 struct task_schedule_state *state, atomic_t *app_states,
345 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
346
350
351#ifdef __cplusplus
352}
353#endif
354
355#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:255
task_runner_valid_type
Definition schedule.h:31
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:50
task_schedule_event
Validate argument union hasn't expanded.
Definition schedule.h:237
@ TASK_VALID_ACTIVE
Task is only valid when INFUSE_STATE_APPLICATION_ACTIVE is set.
Definition schedule.h:39
@ TASK_VALID_ALWAYS
Task is always valid.
Definition schedule.h:37
@ TASK_VALID_PERMANENTLY_RUNS
Entry and exit conditions never checked, task is rebooted if it terminates.
Definition schedule.h:43
@ TASK_LOCKED
Do not update definition from KV store.
Definition schedule.h:33
@ TASK_VALID_INACTIVE
Task is only valid when INFUSE_STATE_APPLICATION_ACTIVE is not set.
Definition schedule.h:41
@ TASK_VALID_NEVER
Task is never valid.
Definition schedule.h:35
@ TASK_PERIODICITY_FIXED
Task can only run on N second boundaries.
Definition schedule.h:52
@ TASK_PERIODICITY_LOCKOUT_DYNAMIC_BATTERY
TASK_PERIODICITY_LOCKOUT with a dynamic lockout based on battery charge
Definition schedule.h:58
@ TASK_PERIODICITY_AFTER
Task can only run N seconds after another schedule terminates.
Definition schedule.h:56
@ TASK_PERIODICITY_LOCKOUT
Task can only run N seconds after previous run started.
Definition schedule.h:54
@ TASK_SCHEDULE_STARTED
Task associated with the schedule has been started.
Definition schedule.h:239
@ TASK_SCHEDULE_STOPPED
Task associated with the schedule has stopped.
Definition schedule.h:243
@ TASK_SCHEDULE_TERMINATE_REQUEST
Task associated with the schedule has been requested to terminate.
Definition schedule.h:241
Autogenerated Task Runner Infuse-IoT task arguments.
Battery charge thresholds to start the task.
Definition schedule.h:177
uint8_t upper
Start task if <= this charge.
Definition schedule.h:181
uint8_t lower
Start task if >= this charge.
Definition schedule.h:179
Battery charge thresholds to terminate the task.
Definition schedule.h:184
uint8_t lower
Terminate task if <= this charge.
Definition schedule.h:186
uint8_t upper
Terminate task if >= this charge.
Definition schedule.h:188
Start N seconds after another task finishes.
Definition schedule.h:201
uint16_t duration_s
Definition schedule.h:203
uint8_t schedule_idx
Definition schedule.h:202
Lockout for a variable duration based on battery state.
Definition schedule.h:210
uint8_t battery_max
Upper battery threshold.
Definition schedule.h:218
uint16_t lockout_min
Lockout between runs at <= battery_min.
Definition schedule.h:212
uint8_t battery_min
Lower battery threshold.
Definition schedule.h:216
uint16_t lockout_max
Lockout between runs at >= battery_max.
Definition schedule.h:214
Start N seconds after task last started.
Definition schedule.h:197
uint32_t lockout_s
Definition schedule.h:198
Start on global N second boundaries.
Definition schedule.h:193
uint32_t period_s
Definition schedule.h:194
Schedule state conditions.
Definition schedule.h:147
uint8_t metadata
Definition schedule.h:149
uint8_t states[4]
Array of states to test.
Definition schedule.h:151
State for a given task schedule.
Definition schedule.h:263
uint32_t last_run
System uptime that started the last run of this schedule.
Definition schedule.h:269
uint32_t last_terminate
System uptime at termination of last run of this schedule.
Definition schedule.h:273
uint32_t runtime
Duration of current run.
Definition schedule.h:271
uint8_t task_idx
Index into task array that corresponds with schedule task_id.
Definition schedule.h:275
struct task_schedule_state * linked
Linked schedule for TASK_PERIODICITY_AFTER.
Definition schedule.h:265
task_schedule_event_cb_t event_cb
Optional callback to be notified of schedule events.
Definition schedule.h:267
Control TDF logging output of a task.
Definition schedule.h:134
uint8_t loggers
TDF loggers to log to.
Definition schedule.h:136
uint8_t tdf_mask
TDFs to log (bitmask defined by the activity)
Definition schedule.h:138
Schedule for a given task.
Definition schedule.h:166
struct task_schedule::battery_start_thresholds battery_start
struct task_schedule_tdf_logging task_logging[2]
Task logging configuration.
Definition schedule.h:228
uint8_t task_id
Definition schedule.h:167
union task_arguments task_args
Task specific arguments.
Definition schedule.h:230
struct task_schedule_state_conditions states_terminate
Task termination state conditions.
Definition schedule.h:226
uint8_t periodicity_type
TASK_PERIODICITY_* value.
Definition schedule.h:171
uint16_t states_start_timeout_2x_s
states_start will evaluate as true 2x this many seconds after last run started
Definition schedule.h:222
uint8_t boot_lockout_minutes
Task will not start for the first N minutes after boot.
Definition schedule.h:173
uint32_t timeout_s
Duration after which task is requested to terminate.
Definition schedule.h:175
uint8_t validity
TASK_VALID_* value.
Definition schedule.h:169
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:224
Definition infuse_task_args.h:35
Periodicity parameters.
Definition schedule.h:191
struct task_schedule::periodicity_args::periodicity_lockout lockout
struct task_schedule::periodicity_args::periodicity_periodic fixed
struct task_schedule::periodicity_args::periodicity_after after
struct task_schedule::periodicity_args::periodicity_lockout_dynamic_battery lockout_dynamic_battery