diff options
author | Jack Rosenthal <jrosenth@chromium.org> | 2020-09-23 08:26:42 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-10-01 19:14:34 +0000 |
commit | ee4037ea734103169bd1cae24ab3b6a5e2e71f67 (patch) | |
tree | 9d5cee6b4d01b099e38822443bef181990cf81ce /zephyr/shim/include/zephyr_console_shim.h | |
parent | 1434fa7a1d5fed910c86f479aab75fee6521bb5d (diff) | |
download | chrome-ec-ee4037ea734103169bd1cae24ab3b6a5e2e71f67.tar.gz |
zephyr: shim in the zephyr shell as the EC console
This provides compatible macros for DECLARE_CONSOLE_COMMAND,
DECLARE_SAFE_CONSOLE_COMMAND, and DECLARE_CONSOLE_COMMAND_FLAGS.
Note: the concept of command flags and command restriction are not
enabled currently for Zephyr. We simply define everything for now.
These macros use the Zephyr shell subsystem as the backend for
commands. In addition, cprints, cprintf, and cputs have been
redirected to the shell for CC_CONSOLE channel outputs, and printk for
all other outputs. We will look at using Zephyr's logging subsystem
instead of printk for the other channels in the future.
BUG=b:167590251
BRANCH=none
TEST=run "gettime" and "timerinfo" commands with follow-up CLs
Signed-off-by: Jack Rosenthal <jrosenth@chromium.org>
Change-Id: I17caedcd0b84a21dd2b135312f683885eaf694af
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2427097
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'zephyr/shim/include/zephyr_console_shim.h')
-rw-r--r-- | zephyr/shim/include/zephyr_console_shim.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/zephyr/shim/include/zephyr_console_shim.h b/zephyr/shim/include/zephyr_console_shim.h new file mode 100644 index 0000000000..5f242b6830 --- /dev/null +++ b/zephyr/shim/include/zephyr_console_shim.h @@ -0,0 +1,58 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef __CROS_EC_ZEPHYR_CONSOLE_SHIM_H +#define __CROS_EC_ZEPHYR_CONSOLE_SHIM_H + +#include <shell/shell.h> + +/** + * zshim_run_ec_console_command() - Dispatch a CrOS EC console command + * using Zephyr's shell + * + * @handler: A CrOS EC shell command handler. + * @shell: The Zephyr shell to run on. + * @argc: The number of command line arguments. + * @argv: The NULL-terminated list of arguments. + * @help_str: The help string to display when "-h" is passed. + * @argdesc: The string describing the arguments to the command. + * + * Return: the return value from the handler. + */ +int zshim_run_ec_console_command(int (*handler)(int argc, char **argv), + const struct shell *shell, size_t argc, + char **argv, const char *help_str, + const char *argdesc); + +/* Internal wrappers for DECLARE_CONSOLE_COMMAND_* macros. */ +#define _ZEPHYR_SHELL_COMMAND_SHIM_2(NAME, ROUTINE_ID, ARGDESC, HELP, \ + WRAPPER_ID) \ + static int WRAPPER_ID(const struct shell *shell, size_t argc, \ + char **argv) \ + { \ + return zshim_run_ec_console_command(ROUTINE_ID, shell, argc, \ + argv, HELP, ARGDESC); \ + } \ + SHELL_CMD_ARG_REGISTER(NAME, NULL, HELP, WRAPPER_ID, 0, \ + SHELL_OPT_ARG_MAX) + +#define _ZEPHYR_SHELL_COMMAND_SHIM(NAME, ROUTINE_ID, ARGDESC, HELP) \ + _ZEPHYR_SHELL_COMMAND_SHIM_2(NAME, ROUTINE_ID, ARGDESC, HELP, \ + UTIL_CAT(zshim_wrapper_, ROUTINE_ID)) + +/* These macros mirror the macros provided by the CrOS EC. */ +#define DECLARE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, HELP) \ + _ZEPHYR_SHELL_COMMAND_SHIM(NAME, ROUTINE, ARGDESC, HELP) + +/* + * TODO(jrosenth): implement flags and restricted commands? We just + * discard this in the shim layer for now. + */ +#define DECLARE_CONSOLE_COMMAND_FLAGS(NAME, ROUTINE, ARGDESC, HELP, FLAGS) \ + _ZEPHYR_SHELL_COMMAND_SHIM(NAME, ROUTINE, ARGDESC, HELP) +#define DECLARE_SAFE_CONSOLE_COMMAND(NAME, ROUTINE, ARGDESC, HELP) \ + _ZEPHYR_SHELL_COMMAND_SHIM(NAME, ROUTINE, ARGDESC, HELP) + +#endif /* __CROS_EC_ZEPHYR_CONSOLE_SHIM_H */ |