10#ifndef INFUSE_SDK_INCLUDE_INFUSE_TASK_RUNNER_TASK_H_
11#define INFUSE_SDK_INCLUDE_INFUSE_TASK_RUNNER_TASK_H_
13#include <zephyr/kernel.h>
14#include <zephyr/device.h>
42 struct k_poll_signal *terminate,
void *arg);
58 const struct device *
dev;
90 struct k_work_delayable
work;
116#define ___TASK_VAR_DEFINE(macro, ...) macro(1, 0, __VA_ARGS__)
117#define __TASK_VAR_DEFINE(...) ___TASK_VAR_DEFINE(__VA_ARGS__)
118#define _TASK_VAR_DEFINE(task) __TASK_VAR_DEFINE(__DEBRACKET task)
125#define ___TASK_CONFIG_DEFINE(macro, ...) macro(0, 1, __VA_ARGS__)
126#define __TASK_CONFIG_DEFINE(...) ___TASK_CONFIG_DEFINE(__VA_ARGS__)
127#define _TASK_CONFIG_DEFINE(task) __TASK_CONFIG_DEFINE(__DEBRACKET task)
181#define TASK_RUNNER_TASKS_DEFINE(config_name, data_name, ...) \
183 FOR_EACH_NONEMPTY_TERM(_TASK_VAR_DEFINE, (;), __VA_ARGS__); \
185 static const struct task_config config_name[] = { \
186 FOR_EACH_NONEMPTY_TERM(_TASK_CONFIG_DEFINE, (,), __VA_ARGS__) \
189 static struct task_data data_name[ARRAY_SIZE(config_name)]
202 struct k_work_delayable *dwork = k_work_delayable_from_work(work);
246 struct k_poll_event events[1] = {
247 K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
254 (void)k_poll(events, 1, timeout);
256 k_poll_signal_check(terminate_signal, &signaled, &result);
257 return signaled ? 1 : 0;
291 uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len,
293 uint64_t time, uint32_t idx_period,
const void *data)
297 tdf_num, format, time, idx_period, data);
301 tdf_num, format, time, idx_period, data);
318 uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len,
319 uint8_t tdf_num, uint64_t time, uint32_t period,
337 uint16_t tdf_id, uint8_t tdf_len, uint64_t time,
360#define TASK_SCHEDULE_TDF_LOG_ARRAY(schedule, tdf_mask, tdf_id, tdf_num, tdf_time, period, data) \
361 task_schedule_tdf_log_array(schedule, tdf_mask, tdf_id, sizeof(TDF_TYPE(tdf_id)), tdf_num, \
362 tdf_time, period, data); \
364 __maybe_unused const TDF_TYPE(tdf_id) *_data = data; \
381#define TASK_SCHEDULE_TDF_LOG(schedule, tdf_mask, tdf_id, tdf_time, data) \
382 task_schedule_tdf_log(schedule, tdf_mask, tdf_id, sizeof(TDF_TYPE(tdf_id)), tdf_time, \
385 __maybe_unused const TDF_TYPE(tdf_id) *_data = data; \
static bool task_schedule_tdf_requested(const struct task_schedule *schedule, uint8_t tdf_mask)
Determine if a given TDF was requested by the schedule.
Definition task.h:269
static void task_schedule_tdf_log_core(const struct task_schedule *schedule, uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len, uint8_t tdf_num, enum tdf_data_format format, uint64_t time, uint32_t idx_period, const void *data)
Log an array of TDFs as requested by a schedule as a diff array.
Definition task.h:290
static void task_schedule_tdf_log(const struct task_schedule *schedule, uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len, uint64_t time, const void *data)
Log a single TDF as requested by a schedule.
Definition task.h:336
static void task_schedule_tdf_log_array(const struct task_schedule *schedule, uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len, uint8_t tdf_num, uint64_t time, uint32_t period, const void *data)
Log an array of TDFs as requested by a schedule.
Definition task.h:317
uint8_t * task_schedule_persistent_storage(struct task_data *data)
Retrieve per-schedule persistent memory.
void(* task_runner_task_fn)(const struct task_schedule *schedule, struct k_poll_signal *terminate, void *arg)
Definition task.h:41
void task_workqueue_reschedule(struct task_data *task, k_timeout_t delay)
Reschedule the task to run again after a delay.
static int task_runner_task_block(struct k_poll_signal *terminate_signal, k_timeout_t timeout)
Block on the termination signal for a duration.
Definition task.h:243
static struct task_data * task_data_from_work(struct k_work *work)
Get the parent task_data struct from the work pointer.
Definition task.h:200
const struct task_schedule * task_schedule_from_data(struct task_data *data)
Retrieve the schedule associated with a task.
@ TASK_FLAG_ARG_IS_DEVICE
task_arg union is a device pointer
Definition task.h:38
@ TASK_EXECUTOR_WORKQUEUE
Task runs on the system workqueue.
Definition task.h:33
@ TASK_EXECUTOR_THREAD
Task runs on its own thread.
Definition task.h:31
tdf_data_format
Definition tdf.h:39
@ TDF_DATA_FORMAT_TIME_ARRAY
Time array with period.
Definition tdf.h:43
@ TDF_DATA_FORMAT_SINGLE
Single sample.
Definition tdf.h:41
void tdf_data_logger_log_core(uint8_t logger_mask, uint16_t tdf_id, uint8_t tdf_len, uint8_t tdf_num, enum tdf_data_format format, uint64_t time, uint32_t idx_period, const void *data)
Add multiple TDFs to multiple data loggers.
Task Runner task scheduling.
Constant task configuration.
Definition task.h:47
const struct device * dev
Definition task.h:58
uint8_t task_id
Task identifier.
Definition task.h:51
const void * const_arg
Definition task.h:59
void * arg
Definition task.h:60
union task_config::@38 task_arg
uint8_t exec_type
Execution context TASK_EXECUTOR_*
Definition task.h:53
k_work_handler_t worker_fn
Handler function.
Definition task.h:75
size_t stack_size
Size of stack memory.
Definition task.h:71
struct k_thread * thread
Thread state storage.
Definition task.h:65
k_thread_stack_t * stack
Pointer to stack memory for thread.
Definition task.h:69
uint8_t flags
Task flags of type TASK_FLAG_*
Definition task.h:55
void * state
Persistent state.
Definition task.h:77
const char * name
Task name.
Definition task.h:49
union task_config::@39 executor
task_runner_task_fn task_fn
Thread function.
Definition task.h:67
Task runtime state.
Definition task.h:85
union task_data::@42 executor
struct k_poll_signal terminate_signal
Thread termination signal.
Definition task.h:101
void * arg
Definition task.h:96
struct k_work_delayable work
Definition task.h:90
bool skip
Skip evaluation of task.
Definition task.h:107
int reschedule_counter
Definition task.h:92
struct task_data::@42::@43 workqueue
Workqueue state storage.
bool running
Task is currently running.
Definition task.h:105
uint8_t schedule_idx
Schedule that triggered the task to run.
Definition task.h:103
const void * const_arg
Definition task.h:95
union task_data::@42::@43::@44 task_arg
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_tdf_logging task_logging[2]
Task logging configuration.
Definition schedule.h:185