diff options
Diffstat (limited to 'zephyr/shim/src/tasks.c')
-rw-r--r-- | zephyr/shim/src/tasks.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c index 95fe952976..9c6f655a5c 100644 --- a/zephyr/shim/src/tasks.c +++ b/zephyr/shim/src/tasks.c @@ -83,6 +83,7 @@ struct task_ctx_dyn { #endif /* CONFIG_THREAD_NAME */ #define TASK_TEST(_name, _entry, _parameter, _size) \ CROS_EC_TASK(_name, _entry, _parameter, _size) +/* Note: no static entry is required for sysworkq, as it isn't started here */ const static struct task_ctx_static shimmed_tasks_static[TASK_ID_COUNT] = { CROS_EC_TASK_LIST #ifdef TEST_BUILD @@ -90,7 +91,10 @@ const static struct task_ctx_static shimmed_tasks_static[TASK_ID_COUNT] = { #endif }; -static struct task_ctx_dyn shimmed_tasks_dyn[TASK_ID_COUNT]; +/* In dynamic tasks, allocate one extra spot for the sysworkq */ +static struct task_ctx_dyn shimmed_tasks_dyn[TASK_ID_COUNT + 1]; + +#define TASK_ID_SYSWORKQ TASK_ID_COUNT static int tasks_started; #undef CROS_EC_TASK @@ -98,18 +102,12 @@ static int tasks_started; task_id_t task_get_current(void) { - for (size_t i = 0; i < TASK_ID_COUNT; ++i) { + /* Include sysworkq entry in search for the task ID */ + for (size_t i = 0; i < TASK_ID_COUNT + 1; ++i) { if (shimmed_tasks_dyn[i].zephyr_tid == k_current_get()) return i; } -#if defined(HAS_TASK_HOOKS) - /* Hooks ID should be returned for deferred calls */ - if (k_current_get() == &k_sys_work_q.thread) { - return TASK_ID_HOOKS; - } -#endif /* HAS_TASK_HOOKS */ - __ASSERT(false, "Task index out of bound"); return 0; } @@ -287,6 +285,7 @@ void set_test_runner_tid(void) void start_ec_tasks(void) { + /* Initialize all EC tasks, which does not include the sysworkq entry */ for (size_t i = 0; i < TASK_ID_COUNT; ++i) { struct task_ctx_dyn *const ctx_dyn = &shimmed_tasks_dyn[i]; const struct task_ctx_static *const ctx_static = @@ -318,6 +317,10 @@ void start_ec_tasks(void) 0, K_NO_WAIT); } + + /* Create an entry for sysworkq we can send events to */ + shimmed_tasks_dyn[TASK_ID_COUNT].zephyr_tid = &k_sys_work_q.thread; + tasks_started = 1; } @@ -330,10 +333,10 @@ int init_signals(const struct device *unused) { ARG_UNUSED(unused); - for (size_t i = 0; i < TASK_ID_COUNT; ++i) { + /* Initialize event structures for all entries, including sysworkq */ + for (size_t i = 0; i < TASK_ID_COUNT + 1; ++i) { struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[i]; - /* Initialize the new_event structure */ k_poll_signal_init(&ctx->new_event); } @@ -363,11 +366,19 @@ void task_enable_irq(int irq) arch_irq_enable(irq); } -inline int in_interrupt_context(void) +inline bool in_interrupt_context(void) { return k_is_in_isr(); } +inline bool in_deferred_context(void) +{ + /* + * Deferred calls run in the sysworkq. + */ + return (task_get_current() == TASK_ID_SYSWORKQ); +} + #if IS_ENABLED(CONFIG_KERNEL_SHELL) && IS_ENABLED(CONFIG_THREAD_MONITOR) static int taskinfo(const struct shell *shell, size_t argc, char **argv) { |