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
31
47 _TASK_VALID_END,
48 _TASK_VALID_MASK = 0x7F,
50};
51
66
68#define TR_NOT 0x100
70#define TR_OR 0x200
72#define TR_AND 0x00
73
75
76#define _TR_STATE_BASE 0xFF
77#define _TR_NOT_BIT_COMMON(state, idx) ((state) & TR_NOT ? BIT(idx) : 0)
78#define _TR_OR_BIT_COMMON(state, idx) ((state) & TR_OR ? BIT(idx) : 0)
79#define _TR_STATES_DEFINE_ALL(s0, s1, s2, s3) \
80 { \
81 .metadata = _TR_NOT_BIT_COMMON(s0, 0) | _TR_NOT_BIT_COMMON(s1, 1) | \
82 _TR_NOT_BIT_COMMON(s2, 2) | _TR_NOT_BIT_COMMON(s3, 3) | \
83 _TR_OR_BIT_COMMON(s0, 4) | _TR_OR_BIT_COMMON(s1, 5) | \
84 _TR_OR_BIT_COMMON(s2, 6) | _TR_OR_BIT_COMMON(s3, 7), \
85 .states = { \
86 (s0) & _TR_STATE_BASE, \
87 (s1) & _TR_STATE_BASE, \
88 (s2) & _TR_STATE_BASE, \
89 (s3) & _TR_STATE_BASE, \
90 } \
91 }
92
93#define _TR_GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
94#define _TR_STATES_1(arg1) _TR_STATES_DEFINE_ALL(arg1, 0, 0, 0)
95#define _TR_STATES_2(arg1, arg2) _TR_STATES_DEFINE_ALL(arg1, arg2, 0, 0)
96#define _TR_STATES_3(arg1, arg2, arg3) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, 0)
97#define _TR_STATES_4(arg1, arg2, arg3, arg4) _TR_STATES_DEFINE_ALL(arg1, arg2, arg3, arg4)
98
100
119#define TASK_STATES_DEFINE(...) \
120 _TR_GET_MACRO(__VA_ARGS__, _TR_STATES_4, _TR_STATES_3, _TR_STATES_2, _TR_STATES_1) \
121 (__VA_ARGS__)
122
132#define TASK_STATES_START_TIMEOUT(seconds) ((seconds) / 2)
133
139 uint8_t loggers;
141 uint8_t tdf_mask;
142} __packed;
143
152 uint8_t metadata;
154 uint8_t states[4];
155} __packed;
156
162#define TASK_RUNNER_LOCKOUT_IGNORE_FIRST BIT(31)
163
240
242BUILD_ASSERT(sizeof(union task_arguments) == 17);
243
253
263typedef void (*task_schedule_event_cb_t)(const struct task_schedule *schedule,
264 enum task_schedule_event event);
265
277 uint32_t last_run;
279 uint32_t runtime;
283 uint8_t task_idx;
284#ifdef CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE
286 uint8_t runtime_state[CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE];
287#endif /* CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE */
288};
289
291#define _TASK_SCHEDULE_MAX_SCHEDULES(schedules) \
292 COND_CODE_1(CONFIG_KV_STORE_KEY_TASK_SCHEDULES, \
293 (CONFIG_KV_STORE_KEY_TASK_SCHEDULES_RANGE), (ARRAY_SIZE(schedules)))
295
305#define TASK_SCHEDULE_STATES_DEFINE(name, schedules) \
306 static struct task_schedule_state name[_TASK_SCHEDULE_MAX_SCHEDULES(schedules)]
307
319bool task_schedule_validate(const struct task_schedule *schedule);
320
334bool task_schedule_should_start(const struct task_schedule *schedule,
335 struct task_schedule_state *state, atomic_t *app_states,
336 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
337
352 struct task_schedule_state *state, atomic_t *app_states,
353 uint32_t uptime, uint32_t epoch_time, uint8_t battery);
354
358
359#ifdef __cplusplus
360}
361#endif
362
363#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:263
task_runner_valid_type
Conditions under which a schedule is valid.
Definition schedule.h:33
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
Periodicity condition types for a schedule.
Definition schedule.h:53
task_schedule_event
Validate argument union hasn't expanded.
Definition schedule.h:245
@ 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:35
@ TASK_VALID_INACTIVE
Task is only valid when INFUSE_STATE_APPLICATION_ACTIVE is not set.
Definition schedule.h:43
@ TASK_VALID_NEVER
Task is never valid.
Definition schedule.h:37
@ TASK_PERIODICITY_FIXED
Task can only run on N second boundaries.
Definition schedule.h:55
@ TASK_PERIODICITY_LOCKOUT_DYNAMIC_BATTERY
TASK_PERIODICITY_LOCKOUT with a dynamic lockout based on battery charge
Definition schedule.h:61
@ TASK_PERIODICITY_AFTER
Task can only run N seconds after another schedule terminates.
Definition schedule.h:59
@ TASK_PERIODICITY_LOCKOUT
Task can only run N seconds after previous run started.
Definition schedule.h:57
@ TASK_SCHEDULE_STARTED
Task associated with the schedule has been started.
Definition schedule.h:247
@ TASK_SCHEDULE_STOPPED
Task associated with the schedule has stopped.
Definition schedule.h:251
@ TASK_SCHEDULE_TERMINATE_REQUEST
Task associated with the schedule has been requested to terminate.
Definition schedule.h:249
Autogenerated Task Runner Infuse-IoT task arguments.
Battery charge thresholds to start the task.
Definition schedule.h:181
uint8_t upper
Start task if <= this charge.
Definition schedule.h:185
uint8_t lower
Start task if >= this charge.
Definition schedule.h:183
Battery charge thresholds to terminate the task.
Definition schedule.h:188
uint8_t lower
Terminate task if <= this charge.
Definition schedule.h:190
uint8_t upper
Terminate task if >= this charge.
Definition schedule.h:192
Start N seconds after another task finishes.
Definition schedule.h:207
uint16_t duration_s
Delay after the linked schedule terminates (s)
Definition schedule.h:211
uint8_t schedule_idx
Index of the schedule to run after.
Definition schedule.h:209
Lockout for a variable duration based on battery state.
Definition schedule.h:218
uint8_t battery_max
Upper battery threshold.
Definition schedule.h:226
uint16_t lockout_min
Lockout between runs at <= battery_min.
Definition schedule.h:220
uint8_t battery_min
Lower battery threshold.
Definition schedule.h:224
uint16_t lockout_max
Lockout between runs at >= battery_max.
Definition schedule.h:222
Start N seconds after task last started.
Definition schedule.h:202
uint32_t lockout_s
Minimum duration between task starts (s)
Definition schedule.h:204
Start on global N second boundaries.
Definition schedule.h:197
uint32_t period_s
Period between task starts (s)
Definition schedule.h:199
Schedule state conditions.
Definition schedule.h:150
uint8_t metadata
Per-state metadata (bits 0-3: invert state, bits 4-7: OR with previous result)
Definition schedule.h:152
uint8_t states[4]
Array of states to test.
Definition schedule.h:154
State for a given task schedule.
Definition schedule.h:271
uint8_t runtime_state[CONFIG_TASK_RUNNER_PER_SCHEDULE_STORAGE]
Per schedule runtime state available for tasks to utilise.
Definition schedule.h:286
uint32_t last_run
System uptime that started the last run of this schedule.
Definition schedule.h:277
uint32_t last_terminate
System uptime at termination of last run of this schedule.
Definition schedule.h:281
uint32_t runtime
Duration of current run.
Definition schedule.h:279
uint8_t task_idx
Index into task array that corresponds with schedule task_id.
Definition schedule.h:283
struct task_schedule_state * linked
Linked schedule for TASK_PERIODICITY_AFTER.
Definition schedule.h:273
task_schedule_event_cb_t event_cb
Optional callback to be notified of schedule events.
Definition schedule.h:275
Control TDF logging output of a task.
Definition schedule.h:137
uint8_t loggers
TDF loggers to log to.
Definition schedule.h:139
uint8_t tdf_mask
TDFs to log (bitmask defined by the activity)
Definition schedule.h:141
Schedule for a given task.
Definition schedule.h:169
struct task_schedule::battery_start_thresholds battery_start
Battery charge thresholds to start the task.
struct task_schedule_tdf_logging task_logging[2]
Task logging configuration.
Definition schedule.h:236
uint8_t task_id
ID of the task this schedule runs.
Definition schedule.h:171
union task_arguments task_args
Task specific arguments.
Definition schedule.h:238
struct task_schedule_state_conditions states_terminate
Task termination state conditions.
Definition schedule.h:234
uint8_t periodicity_type
TASK_PERIODICITY_* value.
Definition schedule.h:175
uint16_t states_start_timeout_2x_s
states_start will evaluate as true 2x this many seconds after last run started
Definition schedule.h:230
uint8_t boot_lockout_minutes
Task will not start for the first N minutes after boot.
Definition schedule.h:177
uint32_t timeout_s
Duration after which task is requested to terminate.
Definition schedule.h:179
uint8_t validity
TASK_VALID_* value.
Definition schedule.h:173
union task_schedule::periodicity_args periodicity
Parameters for task_schedule::periodicity_type.
struct task_schedule::battery_terminate_thresholds battery_terminate
Battery charge thresholds to terminate the task.
struct task_schedule_state_conditions states_start
Task start state conditions.
Definition schedule.h:232
Arguments for any Infuse-IoT task.
Definition infuse_task_args.h:37
Periodicity parameters.
Definition schedule.h:195
struct task_schedule::periodicity_args::periodicity_lockout lockout
Parameters for TASK_PERIODICITY_LOCKOUT.
struct task_schedule::periodicity_args::periodicity_periodic fixed
Parameters for TASK_PERIODICITY_FIXED.
struct task_schedule::periodicity_args::periodicity_after after
Parameters for TASK_PERIODICITY_AFTER.
struct task_schedule::periodicity_args::periodicity_lockout_dynamic_battery lockout_dynamic_battery
Dynamic battery lockout parameters.