summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2023-02-01 10:59:47 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-02 16:32:50 +0000
commit1e8199a5dfdaa7973c41579b2262d7a36b54634d (patch)
treea7c84b64d595db36999bd5b08b6b050f3eab02f6 /zephyr
parent21dad832cc379794a9e3000c2ffb576b6fdf1bf9 (diff)
downloadchrome-ec-1e8199a5dfdaa7973c41579b2262d7a36b54634d.tar.gz
tasks: Add extra SHELL task id
Add TASK_ID_SHELL to extra non-shimmed tasks list. get_shell_thread method also added to allow mapping between shell task id and shell thread. BUG=b:267470086 BRANCH=None TEST=Task unit tests Change-Id: Id49f983e2ae8b9e7359d5e5887f128985ea87786 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4214559 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/shim/include/shimmed_task_id.h3
-rw-r--r--zephyr/shim/include/shimmed_tasks.h5
-rw-r--r--zephyr/shim/include/zephyr_console_shim.h7
-rw-r--r--zephyr/shim/src/console.c8
-rw-r--r--zephyr/shim/src/tasks.c8
-rw-r--r--zephyr/test/tasks/extra_tasks.c12
6 files changed, 43 insertions, 0 deletions
diff --git a/zephyr/shim/include/shimmed_task_id.h b/zephyr/shim/include/shimmed_task_id.h
index 9c8e03e493..eda18aa47b 100644
--- a/zephyr/shim/include/shimmed_task_id.h
+++ b/zephyr/shim/include/shimmed_task_id.h
@@ -234,6 +234,9 @@ enum {
#define CROS_EC_EXTRA_TASKS(fn) \
COND_CODE_1(CONFIG_TASK_HOSTCMD_THREAD_MAIN, (fn(HOSTCMD)), \
(fn(MAIN))) \
+ COND_CODE_1(CONFIG_SHELL_BACKEND_SERIAL, (fn(SHELL)), \
+ (COND_CODE_1(CONFIG_SHELL_BACKEND_DUMMY, (fn(SHELL)), \
+ ()))) \
fn(SYSWORKQ) \
fn(IDLE)
/* clang-format on */
diff --git a/zephyr/shim/include/shimmed_tasks.h b/zephyr/shim/include/shimmed_tasks.h
index 7a55531180..2d2704542c 100644
--- a/zephyr/shim/include/shimmed_tasks.h
+++ b/zephyr/shim/include/shimmed_tasks.h
@@ -51,6 +51,11 @@
#define HAS_TASK_MAIN 1
#endif /* CONFIG_TASK_HOSTCMD_THREAD_DEDICATED */
+#if (defined(CONFIG_SHELL_BACKEND_SERIAL) || \
+ defined(CONFIG_SHELL_BACKEND_DUMMY))
+#define HAS_TASK_SHELL 1
+#endif
+
/* These non-shimmed (extra) tasks are always present */
#define HAS_TASK_IDLE 1
#define HAS_TASK_SYSWORKQ 1
diff --git a/zephyr/shim/include/zephyr_console_shim.h b/zephyr/shim/include/zephyr_console_shim.h
index 42ac3e693b..6db39db204 100644
--- a/zephyr/shim/include/zephyr_console_shim.h
+++ b/zephyr/shim/include/zephyr_console_shim.h
@@ -81,4 +81,11 @@ int zshim_run_ec_console_command(const struct zephyr_console_command *command,
*/
size_t console_buf_notify_chars(const char *s, size_t len);
+/**
+ * get_shell_thread() - Get the thread id for the shell backend
+ *
+ * @returns Backend shell thread id or NULL if not enabled
+ */
+k_tid_t get_shell_thread(void);
+
#endif /* __CROS_EC_ZEPHYR_CONSOLE_SHIM_H */
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c
index ce5c801069..2a82571065 100644
--- a/zephyr/shim/src/console.c
+++ b/zephyr/shim/src/console.c
@@ -308,6 +308,14 @@ const struct shell *get_ec_shell(void)
}
#endif
+k_tid_t get_shell_thread(void)
+{
+ if (shell_zephyr == NULL) {
+ return NULL;
+ }
+ return shell_zephyr->thread;
+}
+
void uart_tx_start(void)
{
}
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index d283671f98..8d00475fd1 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -8,6 +8,7 @@
#include "host_command.h"
#include "task.h"
#include "timer.h"
+#include "zephyr_console_shim.h"
#include <zephyr/init.h>
#include <zephyr/kernel.h>
@@ -141,6 +142,9 @@ k_tid_t task_id_to_thread_id(task_id_t task_id)
case TASK_ID_IDLE:
return get_idle_thread();
+
+ case TASK_ID_SHELL:
+ return get_shell_thread();
}
}
__ASSERT(false, "Failed to map task %d to thread", task_id);
@@ -174,6 +178,10 @@ task_id_t thread_id_to_task_id(k_tid_t thread_id)
return TASK_ID_IDLE;
}
+ if (get_shell_thread() == thread_id) {
+ return TASK_ID_SHELL;
+ }
+
for (size_t i = 0; i < TASK_ID_COUNT; ++i) {
if (task_to_k_tid[i] == thread_id) {
return i;
diff --git a/zephyr/test/tasks/extra_tasks.c b/zephyr/test/tasks/extra_tasks.c
index d9c75f4cfe..47b653dfb2 100644
--- a/zephyr/test/tasks/extra_tasks.c
+++ b/zephyr/test/tasks/extra_tasks.c
@@ -6,6 +6,7 @@
#include "ec_tasks.h"
#include "host_command.h"
#include "task.h"
+#include "zephyr_console_shim.h"
#include <zephyr/kernel.h>
#include <zephyr/kernel/thread.h>
@@ -116,6 +117,17 @@ ZTEST_USER(extra_tasks, test_idle_thread_mapping)
zassert_equal(task_id_to_thread_id(TASK_ID_IDLE), idle_thread);
}
+ZTEST_USER(extra_tasks, test_shell_thread_to_task_mapping)
+{
+ k_tid_t shell_thread;
+
+ shell_thread = find_thread_by_name("shell_uart");
+ zassert_not_null(shell_thread);
+ zassert_equal(shell_thread, get_shell_thread());
+ zassert_equal(TASK_ID_SHELL, thread_id_to_task_id(shell_thread));
+ zassert_equal(task_id_to_thread_id(TASK_ID_SHELL), shell_thread);
+}
+
ZTEST_USER(extra_tasks, test_invalid_task_id)
{
k_tid_t thread_id;