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>
47#define TASK_RUNNER_TASK_U32_ID(task_id) (0x7A5A6600 | (task_id))
57 struct k_poll_signal *terminate,
void *arg);
74 const struct device *
dev;
140#define ___TASK_VAR_DEFINE(macro, ...) macro(1, 0, __VA_ARGS__)
141#define __TASK_VAR_DEFINE(...) ___TASK_VAR_DEFINE(__VA_ARGS__)
142#define _TASK_VAR_DEFINE(task) __TASK_VAR_DEFINE(__DEBRACKET task)
149#define ___TASK_CONFIG_DEFINE(macro, ...) macro(0, 1, __VA_ARGS__)
150#define __TASK_CONFIG_DEFINE(...) ___TASK_CONFIG_DEFINE(__VA_ARGS__)
151#define _TASK_CONFIG_DEFINE(task) __TASK_CONFIG_DEFINE(__DEBRACKET task)
205#define TASK_RUNNER_TASKS_DEFINE(config_name, data_name, ...) \
207 FOR_EACH_NONEMPTY_TERM(_TASK_VAR_DEFINE, (;), __VA_ARGS__); \
209 static const struct task_config config_name[] = { \
210 FOR_EACH_NONEMPTY_TERM(_TASK_CONFIG_DEFINE, (,), __VA_ARGS__) \
213 static struct task_data data_name[ARRAY_SIZE(config_name)]
226 struct k_work_delayable *dwork = k_work_delayable_from_work(work);
270 struct k_poll_event events[1] = {
271 K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY,
278 (void)k_poll(events, 1, timeout);
280 k_poll_signal_check(terminate_signal, &signaled, &result);
281 return signaled ? 1 : 0;
315 uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len,
317 uint64_t time, uint32_t idx_period,
const void *data)
321 tdf_num, format, time, idx_period, data);
325 tdf_num, format, time, idx_period, data);
342 uint8_t tdf_mask, uint16_t tdf_id, uint8_t tdf_len,
343 uint8_t tdf_num, uint64_t time, uint32_t period,
361 uint16_t tdf_id, uint8_t tdf_len, uint64_t time,
384#define TASK_SCHEDULE_TDF_LOG_ARRAY(schedule, tdf_mask, tdf_id, tdf_num, tdf_time, period, data) \
385 task_schedule_tdf_log_array(schedule, tdf_mask, tdf_id, sizeof(TDF_TYPE(tdf_id)), tdf_num, \
386 tdf_time, period, data); \
388 __maybe_unused const TDF_TYPE(tdf_id) *_data = data; \
405#define TASK_SCHEDULE_TDF_LOG(schedule, tdf_mask, tdf_id, tdf_time, data) \
406 task_schedule_tdf_log(schedule, tdf_mask, tdf_id, sizeof(TDF_TYPE(tdf_id)), tdf_time, \
409 __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:293
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:314
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:360
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:341
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)
Function run by a thread executor task.
Definition task.h:56
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:267
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:224
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:39
@ TASK_EXECUTOR_WORKQUEUE
Task runs on the system workqueue.
Definition task.h:34
@ TASK_EXECUTOR_THREAD
Task runs on its own thread.
Definition task.h:32
tdf_data_format
Format of the data in a TDF.
Definition tdf.h:42
@ TDF_DATA_FORMAT_TIME_ARRAY
Time array with period.
Definition tdf.h:46
@ TDF_DATA_FORMAT_SINGLE
Single sample.
Definition tdf.h:44
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:62
const struct device * dev
Argument as a device pointer (TASK_FLAG_ARG_IS_DEVICE)
Definition task.h:74
union task_config::@225067150370361177166166351327340264154013335120 task_arg
Task specific argument.
uint8_t task_id
Task identifier.
Definition task.h:66
const void * const_arg
Argument as a constant pointer.
Definition task.h:76
void * arg
Argument as a mutable pointer.
Definition task.h:78
uint8_t exec_type
Execution context TASK_EXECUTOR_*
Definition task.h:68
k_work_handler_t worker_fn
Handler function.
Definition task.h:96
size_t stack_size
Size of stack memory.
Definition task.h:91
union task_config::@246102301160106360140230353205072307124062022247 executor
Executor specific configuration.
struct k_thread * thread
Thread state storage.
Definition task.h:85
k_thread_stack_t * stack
Pointer to stack memory for thread.
Definition task.h:89
uint8_t flags
Task flags of type TASK_FLAG_*
Definition task.h:70
void * state
Persistent state.
Definition task.h:98
const char * name
Task name.
Definition task.h:64
task_runner_task_fn task_fn
Thread function.
Definition task.h:87
Task runtime state.
Definition task.h:106
struct task_data::@174101042313227056365276014012106006134230234354::@163121324307354322136206211317316074310326313007 workqueue
Workqueue state storage.
union task_data::@174101042313227056365276014012106006134230234354::@163121324307354322136206211317316074310326313007::@120365071263030125005141070164045340126227245342 task_arg
Compile-time argument.
struct k_poll_signal terminate_signal
Thread termination signal.
Definition task.h:125
void * arg
Argument as a mutable pointer.
Definition task.h:120
struct k_work_delayable work
Workqueue item.
Definition task.h:112
bool skip
Skip evaluation of task.
Definition task.h:131
int reschedule_counter
Number of times the work has been rescheduled this run.
Definition task.h:114
bool running
Task is currently running.
Definition task.h:129
uint8_t schedule_idx
Schedule that triggered the task to run.
Definition task.h:127
const void * const_arg
Argument as a constant pointer.
Definition task.h:118
union task_data::@174101042313227056365276014012106006134230234354 executor
Executor specific state.
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_tdf_logging task_logging[2]
Task logging configuration.
Definition schedule.h:236