From 7cc09b36208b6881bf631d5f31c165a8cd7e3713 Mon Sep 17 00:00:00 2001 From: "Dobrowolski, PawelX" Date: Thu, 21 Dec 2023 15:56:47 +0100 Subject: [PATCH] loadable: adding ifndef for building loadable --- src/audio/up_down_mixer/up_down_mixer.c | 26 +- src/include/ipc/topology.h | 2 + src/include/sof/audio/audio_stream.h | 2 + src/include/sof/audio/buffer.h | 4 +- src/include/sof/audio/component.h | 44 +++- .../audio/module_adapter/iadk/adsp_stddef.h | 4 +- .../sof/audio/module_adapter/module/generic.h | 5 +- src/include/sof/audio/pipeline-trace.h | 161 ++++++------ xtos/include/sof/lib/mailbox.h | 2 + zephyr/include/rtos/alloc.h | 4 +- zephyr/include/rtos/bit.h | 50 ++-- zephyr/include/rtos/cache.h | 4 +- zephyr/include/rtos/panic.h | 50 ++-- zephyr/include/rtos/task.h | 229 +++++++++--------- 14 files changed, 322 insertions(+), 265 deletions(-) diff --git a/src/audio/up_down_mixer/up_down_mixer.c b/src/audio/up_down_mixer/up_down_mixer.c index 120241102b8c..52f36360302c 100644 --- a/src/audio/up_down_mixer/up_down_mixer.c +++ b/src/audio/up_down_mixer/up_down_mixer.c @@ -15,6 +15,11 @@ #include "up_down_mixer_coef.h" #include "up_down_mixer.h" +#include +#include +#include +#include + //LOG_MODULE_REGISTER(up_down_mixer, CONFIG_SOF_LOG_LEVEL); // ///* these ids aligns windows driver requirement to support windows driver */ @@ -29,7 +34,8 @@ #define comp_err(...) #define comp_dbg(...) -static const struct native_system_agent* native_sys_agent; +static struct native_system_service_api* system_service; +uint32_t heap_mem[2048] __attribute__((section(".heap_mem"))) __attribute__((aligned(4096))); int32_t custom_coeffs[UP_DOWN_MIX_COEFFS_LENGTH]; @@ -43,7 +49,7 @@ static int set_downmix_coefficients(struct processing_module *mod, int ret; if (cd->downmix_coefficients) { - ret = memcpy_s(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients, + ret = system_service->safe_memcpy(&custom_coeffs, sizeof(custom_coeffs), downmix_coefficients, sizeof(int32_t) * UP_DOWN_MIX_COEFFS_LENGTH); if (ret < 0) @@ -321,9 +327,9 @@ static int up_down_mixer_free(struct processing_module *mod) { struct up_down_mixer_data *cd = module_get_private_data(mod); - rfree(cd->buf_in); - rfree(cd->buf_out); - rfree(cd); + free(cd->buf_in); + free(cd->buf_out); + free(cd); return 0; } @@ -337,16 +343,16 @@ static int up_down_mixer_init(struct processing_module *mod) struct up_down_mixer_data *cd; int ret; - cd = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM, sizeof(*cd)); + cd = malloc(sizeof(struct up_down_mixer_data)); if (!cd) { - comp_free(dev); + //comp_free(dev); return -ENOMEM; } mod_data->private = cd; - cd->buf_in = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.ibs); - cd->buf_out = rballoc(0, SOF_MEM_CAPS_RAM, mod->priv.cfg.base_cfg.obs); + cd->buf_in = malloc(mod->priv.cfg.base_cfg.ibs); + cd->buf_out = malloc(mod->priv.cfg.base_cfg.obs); if (!cd->buf_in || !cd->buf_out) { ret = -ENOMEM; goto err; @@ -447,7 +453,7 @@ DECLARE_LOADABLE_MODULE_API_VERSION(udm); static void* entry_point(void* mod_cfg, void* parent_ppl, void** mod_ptr) { - native_sys_agent = *(const struct native_system_agent**)mod_ptr; + system_service = *(const struct native_system_agent**)mod_ptr; return &up_down_mixer_interface; } diff --git a/src/include/ipc/topology.h b/src/include/ipc/topology.h index a12f8610f734..c9ddee97fbb9 100644 --- a/src/include/ipc/topology.h +++ b/src/include/ipc/topology.h @@ -77,6 +77,8 @@ struct sof_ipc_comp { /* * SOF memory capabilities, add new ones at the end */ +#define BIT(b) (1UL << (b)) + #define SOF_MEM_CAPS_RAM BIT(0) #define SOF_MEM_CAPS_ROM BIT(1) #define SOF_MEM_CAPS_EXT BIT(2) /**< external */ diff --git a/src/include/sof/audio/audio_stream.h b/src/include/sof/audio/audio_stream.h index 09bfb68a038d..ddcfaf5cb9ba 100644 --- a/src/include/sof/audio/audio_stream.h +++ b/src/include/sof/audio/audio_stream.h @@ -20,8 +20,10 @@ #include #include #include +#ifndef MODULE_PRIVAT #include #include +#endif #include #include #include diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index e636771f9f93..614c1f6f91c5 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -7,7 +7,7 @@ #ifndef __SOF_AUDIO_BUFFER_H__ #define __SOF_AUDIO_BUFFER_H__ - +#ifndef MODULE_PRIVAT #include #include #include @@ -26,7 +26,7 @@ #include #include #include - +#endif #include #include #include diff --git a/src/include/sof/audio/component.h b/src/include/sof/audio/component.h index 5c43c94b3434..b1c731ec9516 100644 --- a/src/include/sof/audio/component.h +++ b/src/include/sof/audio/component.h @@ -23,19 +23,57 @@ #include #include #include -#else #include #endif #include - +#include +#include #include - +#include struct comp_dev; struct sof_ipc_stream_posn; struct dai_hw_params; struct timestamp_data; struct dai_ts_data; +/* types of component */ +enum sof_comp_type { + SOF_COMP_NONE = 0, + SOF_COMP_HOST, + SOF_COMP_DAI, + SOF_COMP_SG_HOST, /**< scatter gather variant */ + SOF_COMP_SG_DAI, /**< scatter gather variant */ + SOF_COMP_VOLUME, + SOF_COMP_MIXER, + SOF_COMP_MUX, + SOF_COMP_SRC, + SOF_COMP_DEPRECATED0, /* Formerly SOF_COMP_SPLITTER */ + SOF_COMP_TONE, + SOF_COMP_DEPRECATED1, /* Formerly SOF_COMP_SWITCH */ + SOF_COMP_BUFFER, + SOF_COMP_EQ_IIR, + SOF_COMP_EQ_FIR, + SOF_COMP_KEYWORD_DETECT, + SOF_COMP_KPB, /* A key phrase buffer component */ + SOF_COMP_SELECTOR, /**< channel selector component */ + SOF_COMP_DEMUX, + SOF_COMP_ASRC, /**< Asynchronous sample rate converter */ + SOF_COMP_DCBLOCK, + SOF_COMP_SMART_AMP, /**< smart amplifier component */ + SOF_COMP_MODULE_ADAPTER, /**< module adapter */ + /* keep FILEREAD/FILEWRITE as the last ones */ + SOF_COMP_FILEREAD = 10000, /**< host test based file IO */ + SOF_COMP_FILEWRITE = 10001, /**< host test based file IO */ +}; + +/** + * Trace context. + */ +struct tr_ctx { + const struct sof_uuid_entry* uuid_p; /**< UUID pointer, use SOF_UUID() to init */ + uint32_t level; /**< Default log level */ +}; + /** \addtogroup component_api Component API * @{ */ diff --git a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h index ff328d84d789..9e0a16d1915e 100644 --- a/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h +++ b/src/include/sof/audio/module_adapter/iadk/adsp_stddef.h @@ -11,8 +11,10 @@ #include #include -#ifdef __ZEPHYR__ && !defined MODULE_PRIVAT +#ifdef __ZEPHYR__ +#ifndef MODULE_PRIVAT #include +#endif #endif /* __ZEPHYR__ */ #ifdef __XTENSA__ diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index d73ae757a61f..40ee4ad18580 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -13,14 +13,15 @@ #ifndef __SOF_AUDIO_MODULE_GENERIC__ #define __SOF_AUDIO_MODULE_GENERIC__ -#ifndef MODULE_PRIVAT #include +#ifndef MODULE_PRIVAT #include #include +#include #endif //MODULE_PRIVAT #include #include -#include + #include "module_interface.h" #ifndef MODULE_PRIVAT #if CONFIG_INTEL_MODULES diff --git a/src/include/sof/audio/pipeline-trace.h b/src/include/sof/audio/pipeline-trace.h index d1f89583ad45..1224f9d5bab3 100644 --- a/src/include/sof/audio/pipeline-trace.h +++ b/src/include/sof/audio/pipeline-trace.h @@ -1,80 +1,81 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2016 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __SOF_AUDIO_PIPELINE_TRACE_H__ -#define __SOF_AUDIO_PIPELINE_TRACE_H__ - -#include -#include -#include -#include -#include -#include - -/* pipeline tracing */ -extern struct tr_ctx pipe_tr; - -#define trace_pipe_get_tr_ctx(pipe_p) (&(pipe_p)->tctx) -#define trace_pipe_get_id(pipe_p) ((pipe_p)->pipeline_id) -#define trace_pipe_get_subid(pipe_p) ((pipe_p)->comp_id) - -/* class (driver) level (no device object) tracing */ - -#define pipe_cl_err(__e, ...) \ - tr_err(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_warn(__e, ...) \ - tr_warn(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_info(__e, ...) \ - tr_info(&pipe_tr, __e, ##__VA_ARGS__) - -#define pipe_cl_dbg(__e, ...) \ - tr_dbg(&pipe_tr, __e, ##__VA_ARGS__) - -/* device tracing */ -#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) - -#if CONFIG_IPC_MAJOR_4 -#define __PIPE_FMT "pipe:%u %#x " -#else -#define __PIPE_FMT "pipe:%u.%u " -#endif - -#define pipe_err(pipe_p, __e, ...) LOG_ERR(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_warn(pipe_p, __e, ...) LOG_WRN(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_info(pipe_p, __e, ...) LOG_INF(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#define pipe_dbg(pipe_p, __e, ...) LOG_DBG(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ - trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) - -#else - -#define pipe_err(pipe_p, __e, ...) \ - trace_dev_err(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_warn(pipe_p, __e, ...) \ - trace_dev_warn(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_info(pipe_p, __e, ...) \ - trace_dev_info(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#define pipe_dbg(pipe_p, __e, ...) \ - trace_dev_dbg(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ - trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) - -#endif /* #if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) */ - -#endif +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2016 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __SOF_AUDIO_PIPELINE_TRACE_H__ +#define __SOF_AUDIO_PIPELINE_TRACE_H__ +#ifndef MODULE_PRIVAT +#include +#include +#include +#include +#endif +#include +#include + +/* pipeline tracing */ +extern struct tr_ctx pipe_tr; + +#define trace_pipe_get_tr_ctx(pipe_p) (&(pipe_p)->tctx) +#define trace_pipe_get_id(pipe_p) ((pipe_p)->pipeline_id) +#define trace_pipe_get_subid(pipe_p) ((pipe_p)->comp_id) + +/* class (driver) level (no device object) tracing */ + +#define pipe_cl_err(__e, ...) \ + tr_err(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_warn(__e, ...) \ + tr_warn(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_info(__e, ...) \ + tr_info(&pipe_tr, __e, ##__VA_ARGS__) + +#define pipe_cl_dbg(__e, ...) \ + tr_dbg(&pipe_tr, __e, ##__VA_ARGS__) + +/* device tracing */ +#if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) + +#if CONFIG_IPC_MAJOR_4 +#define __PIPE_FMT "pipe:%u %#x " +#else +#define __PIPE_FMT "pipe:%u.%u " +#endif + +#define pipe_err(pipe_p, __e, ...) LOG_ERR(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_warn(pipe_p, __e, ...) LOG_WRN(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_info(pipe_p, __e, ...) LOG_INF(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#define pipe_dbg(pipe_p, __e, ...) LOG_DBG(__PIPE_FMT __e, trace_pipe_get_id(pipe_p), \ + trace_pipe_get_subid(pipe_p), ##__VA_ARGS__) + +#else + +#define pipe_err(pipe_p, __e, ...) \ + trace_dev_err(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_warn(pipe_p, __e, ...) \ + trace_dev_warn(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_info(pipe_p, __e, ...) \ + trace_dev_info(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#define pipe_dbg(pipe_p, __e, ...) \ + trace_dev_dbg(trace_pipe_get_tr_ctx, trace_pipe_get_id, \ + trace_pipe_get_subid, pipe_p, __e, ##__VA_ARGS__) + +#endif /* #if defined(__ZEPHYR__) && defined(CONFIG_ZEPHYR_LOG) */ + +#endif diff --git a/xtos/include/sof/lib/mailbox.h b/xtos/include/sof/lib/mailbox.h index 06e2659a5847..4e325fb3b3cc 100644 --- a/xtos/include/sof/lib/mailbox.h +++ b/xtos/include/sof/lib/mailbox.h @@ -12,8 +12,10 @@ #include #include #include +#ifndef MODULE_PRIVAT #include #include +#endif #include #include #include diff --git a/zephyr/include/rtos/alloc.h b/zephyr/include/rtos/alloc.h index 509c691e3964..41b7cb535064 100644 --- a/zephyr/include/rtos/alloc.h +++ b/zephyr/include/rtos/alloc.h @@ -5,12 +5,12 @@ #ifndef __ZEPHYR_RTOS_ALLOC_H__ #define __ZEPHYR_RTOS_ALLOC_H__ - +#ifndef MODULE_PRIVAT #include #include #include #include - +#endif #include #include diff --git a/zephyr/include/rtos/bit.h b/zephyr/include/rtos/bit.h index 133ca5424d87..4a49bc05229d 100644 --- a/zephyr/include/rtos/bit.h +++ b/zephyr/include/rtos/bit.h @@ -1,25 +1,25 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2018 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_BIT_H__ -#define __ZEPHYR_RTOS_BIT_H__ - -#include - -/* TODO: align with Zephyr BIT APIs */ - -#define MASK(b_hi, b_lo) \ - (((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo)) -#define SET_BIT(b, x) (((x) & 1) << (b)) -#define SET_BITS(b_hi, b_lo, x) \ - (((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo)) -#define GET_BIT(b, x) \ - (((x) & (1ULL << (b))) >> (b)) -#define GET_BITS(b_hi, b_lo, x) \ - (((x) & MASK(b_hi, b_lo)) >> (b_lo)) - -#endif /* __ZEPHYR_RTOS_BIT_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2018 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_BIT_H__ +#define __ZEPHYR_RTOS_BIT_H__ +#ifndef MODULE_PRIVAT +#include +#endif +/* TODO: align with Zephyr BIT APIs */ + +#define MASK(b_hi, b_lo) \ + (((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL) << (b_lo)) +#define SET_BIT(b, x) (((x) & 1) << (b)) +#define SET_BITS(b_hi, b_lo, x) \ + (((x) & ((1ULL << ((b_hi) - (b_lo) + 1ULL)) - 1ULL)) << (b_lo)) +#define GET_BIT(b, x) \ + (((x) & (1ULL << (b))) >> (b)) +#define GET_BITS(b_hi, b_lo, x) \ + (((x) & MASK(b_hi, b_lo)) >> (b_lo)) + +#endif /* __ZEPHYR_RTOS_BIT_H__ */ diff --git a/zephyr/include/rtos/cache.h b/zephyr/include/rtos/cache.h index 576e1c5bea3d..246461c58a59 100644 --- a/zephyr/include/rtos/cache.h +++ b/zephyr/include/rtos/cache.h @@ -9,10 +9,10 @@ #define __SOF_LIB_CACHE_H__ #if !defined(__ASSEMBLER__) && !defined(LINKER) - +#ifndef MODULE_PRIVAT #include #include - +#endif #if defined(CONFIG_XTENSA) && defined(CONFIG_INTEL) /* definitions required by xtensa-based Intel platforms. diff --git a/zephyr/include/rtos/panic.h b/zephyr/include/rtos/panic.h index e065498a5ba5..f25907362b4e 100644 --- a/zephyr/include/rtos/panic.h +++ b/zephyr/include/rtos/panic.h @@ -1,25 +1,25 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright 2023 NXP - * Copyright(c) 2018 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_PANIC_H__ -#define __ZEPHYR_RTOS_PANIC_H__ - -#include - -#ifndef __ZEPHYR__ -#error "This file should only be included in Zephyr builds." -#endif /* __ZEPHYR__ */ - -#define sof_panic(x) k_panic() -#define assert(x) __ASSERT_NO_MSG(x) - -/* To print the asserted expression on failure: - * #define assert(x) __ASSERT(x, #x) - */ - -#endif /* __ZEPHYR_RTOS_PANIC_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright 2023 NXP + * Copyright(c) 2018 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_PANIC_H__ +#define __ZEPHYR_RTOS_PANIC_H__ +#ifndef MODULE_PRIVAT +#include +#endif +#ifndef __ZEPHYR__ +#error "This file should only be included in Zephyr builds." +#endif /* __ZEPHYR__ */ + +#define sof_panic(x) k_panic() +#define assert(x) __ASSERT_NO_MSG(x) + +/* To print the asserted expression on failure: + * #define assert(x) __ASSERT(x, #x) + */ + +#endif /* __ZEPHYR_RTOS_PANIC_H__ */ diff --git a/zephyr/include/rtos/task.h b/zephyr/include/rtos/task.h index 9fcc202c1e2e..c37f5f34c2d7 100644 --- a/zephyr/include/rtos/task.h +++ b/zephyr/include/rtos/task.h @@ -1,113 +1,116 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2016 Intel Corporation. All rights reserved. - * - * Author: Liam Girdwood - */ - -#ifndef __ZEPHYR_RTOS_TASK_H__ -#define __ZEPHYR_RTOS_TASK_H__ - -#include -#include -#include -#include -#include -#include - -struct comp_dev; -struct sof; - -/** \brief Predefined LL task priorities. */ -#define SOF_TASK_PRI_HIGH 0 /* priority level 0 - high */ -#define SOF_TASK_PRI_MED 4 /* priority level 4 - medium */ -#define SOF_TASK_PRI_LOW 9 /* priority level 9 - low */ - -/** \brief Predefined EDF task deadlines. */ -#define SOF_TASK_DEADLINE_IDLE UINT64_MAX -#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1) -#define SOF_TASK_DEADLINE_NOW 0 - -/** \brief Task counter initial value. */ -#define SOF_TASK_SKIP_COUNT 0xFFFFu - -/** \brief Task states. */ -enum task_state { - SOF_TASK_STATE_INIT = 0, - SOF_TASK_STATE_QUEUED, - SOF_TASK_STATE_PENDING, - SOF_TASK_STATE_RUNNING, - SOF_TASK_STATE_PREEMPTED, - SOF_TASK_STATE_COMPLETED, - SOF_TASK_STATE_FREE, - SOF_TASK_STATE_CANCEL, - SOF_TASK_STATE_RESCHEDULE, -}; - -/** \brief Task operations. */ -struct task_ops { - enum task_state (*run)(void *data); /**< task's main operation */ - void (*complete)(void *data); /**< executed on completion */ - uint64_t (*get_deadline)(void *data); /**< returns current deadline */ -}; - -/** \brief Task used by schedulers. */ -struct task { - uint64_t start; /**< start time in [ms] since now (LL only) */ - const struct sof_uuid_entry *uid; /**< Uuid */ - uint16_t type; /**< type of the task (LL or EDF) */ - uint16_t priority; /**< priority of the task (used by LL) */ - uint16_t core; /**< execution core */ - uint16_t flags; /**< custom flags */ - enum task_state state; /**< current state */ - void *data; /**< custom data passed to all ops */ - struct list_item list; /**< used by schedulers to hold tasks */ - void *priv_data; /**< task private data */ - struct task_ops ops; /**< task operations */ - struct k_work_delayable z_delayed_work; - uint32_t cycles_sum; - uint32_t cycles_max; - uint32_t cycles_cnt; -#if CONFIG_PERFORMANCE_COUNTERS - struct perf_cnt_data pcd; -#endif -}; - -static inline bool task_is_active(struct task *task) -{ - switch (task->state) { - case SOF_TASK_STATE_QUEUED: - case SOF_TASK_STATE_PENDING: - case SOF_TASK_STATE_RUNNING: - case SOF_TASK_STATE_PREEMPTED: - case SOF_TASK_STATE_RESCHEDULE: - return true; - default: - return false; - } -} - -static inline enum task_state task_run(struct task *task) -{ - assert(task->ops.run); - - return task->ops.run(task->data); -} - -static inline void task_complete(struct task *task) -{ - if (task->ops.complete) - task->ops.complete(task->data); -} - -static inline uint64_t task_get_deadline(struct task *task) -{ - assert(task->ops.get_deadline); - - return task->ops.get_deadline(task->data); -} - -int task_main_start(struct sof *sof); -int start_complete(void); - -#endif /* __ZEPHYR_RTOS_TASK_H__ */ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2016 Intel Corporation. All rights reserved. + * + * Author: Liam Girdwood + */ + +#ifndef __ZEPHYR_RTOS_TASK_H__ +#define __ZEPHYR_RTOS_TASK_H__ +#ifndef MODULE_PRIVAT +#include +#endif +#include +#include +#include +#ifndef MODULE_PRIVAT +#include +#include +#endif + +struct comp_dev; +struct sof; + +/** \brief Predefined LL task priorities. */ +#define SOF_TASK_PRI_HIGH 0 /* priority level 0 - high */ +#define SOF_TASK_PRI_MED 4 /* priority level 4 - medium */ +#define SOF_TASK_PRI_LOW 9 /* priority level 9 - low */ + +/** \brief Predefined EDF task deadlines. */ +#define SOF_TASK_DEADLINE_IDLE UINT64_MAX +#define SOF_TASK_DEADLINE_ALMOST_IDLE (SOF_TASK_DEADLINE_IDLE - 1) +#define SOF_TASK_DEADLINE_NOW 0 + +/** \brief Task counter initial value. */ +#define SOF_TASK_SKIP_COUNT 0xFFFFu + +/** \brief Task states. */ +enum task_state { + SOF_TASK_STATE_INIT = 0, + SOF_TASK_STATE_QUEUED, + SOF_TASK_STATE_PENDING, + SOF_TASK_STATE_RUNNING, + SOF_TASK_STATE_PREEMPTED, + SOF_TASK_STATE_COMPLETED, + SOF_TASK_STATE_FREE, + SOF_TASK_STATE_CANCEL, + SOF_TASK_STATE_RESCHEDULE, +}; + +/** \brief Task operations. */ +struct task_ops { + enum task_state (*run)(void *data); /**< task's main operation */ + void (*complete)(void *data); /**< executed on completion */ + uint64_t (*get_deadline)(void *data); /**< returns current deadline */ +}; + +/** \brief Task used by schedulers. */ +struct task { + uint64_t start; /**< start time in [ms] since now (LL only) */ + const struct sof_uuid_entry *uid; /**< Uuid */ + uint16_t type; /**< type of the task (LL or EDF) */ + uint16_t priority; /**< priority of the task (used by LL) */ + uint16_t core; /**< execution core */ + uint16_t flags; /**< custom flags */ + enum task_state state; /**< current state */ + void *data; /**< custom data passed to all ops */ + struct list_item list; /**< used by schedulers to hold tasks */ + void *priv_data; /**< task private data */ + struct task_ops ops; /**< task operations */ + struct k_work_delayable z_delayed_work; + uint32_t cycles_sum; + uint32_t cycles_max; + uint32_t cycles_cnt; +#if CONFIG_PERFORMANCE_COUNTERS + struct perf_cnt_data pcd; +#endif +}; + +static inline bool task_is_active(struct task *task) +{ + switch (task->state) { + case SOF_TASK_STATE_QUEUED: + case SOF_TASK_STATE_PENDING: + case SOF_TASK_STATE_RUNNING: + case SOF_TASK_STATE_PREEMPTED: + case SOF_TASK_STATE_RESCHEDULE: + return true; + default: + return false; + } +} + +static inline enum task_state task_run(struct task *task) +{ + assert(task->ops.run); + + return task->ops.run(task->data); +} + +static inline void task_complete(struct task *task) +{ + if (task->ops.complete) + task->ops.complete(task->data); +} + +static inline uint64_t task_get_deadline(struct task *task) +{ + assert(task->ops.get_deadline); + + return task->ops.get_deadline(task->data); +} + +int task_main_start(struct sof *sof); +int start_complete(void); + +#endif /* __ZEPHYR_RTOS_TASK_H__ */