From 3343af13117934611ce1a682acd1f99b8b10ed74 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 30 Sep 2022 11:53:59 -0700 Subject: console: Make chan command accept channel name Currently, chan command takes only mask in hex representation. This patch allows the command to accept channel name. For example, > chan pwm chan pwm disabled > chan pwm chan pwm enabled enables pwm channel if it's disabled or enables pwm channel if it's enabled. BUG=None BRANCH=None TEST=On Agah TEST=./twister --clobber -i -s zephyr/test/drivers/drivers.default Signed-off-by: Daisuke Nojiri Change-Id: I0cfc4beff54451d5bc211c5b3c30f5b0747e6d28 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3930855 Commit-Queue: Jeremy Bettis Code-Coverage: Zoss Reviewed-by: Jeremy Bettis --- common/console_output.c | 27 ++++++++++++++++++++------- zephyr/test/drivers/default/src/console.c | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/common/console_output.c b/common/console_output.c index 24bdb5aa3a..72e5c4daf1 100644 --- a/common/console_output.c +++ b/common/console_output.c @@ -167,12 +167,24 @@ static int command_ch(int argc, const char **argv) } else { /* Set the mask */ - int m = strtoi(argv[1], &e, 0); - if (*e) - return EC_ERROR_PARAM1; - - /* No disabling the command output channel */ - channel_mask = m | CC_MASK(CC_COMMAND); + int index = console_channel_name_to_index(argv[1]); + + if (index >= 0) { + if (console_channel_is_disabled(index)) { + console_channel_enable(argv[1]); + ccprintf("chan %s enabled\n", argv[1]); + } else { + console_channel_disable(argv[1]); + ccprintf("chan %s disabled\n", argv[1]); + } + } else { + int m = strtoi(argv[1], &e, 0); + if (*e) { + return EC_ERROR_PARAM1; + } + /* No disabling the command output channel */ + channel_mask = m | CC_MASK(CC_COMMAND); + } return EC_SUCCESS; } @@ -188,6 +200,7 @@ static int command_ch(int argc, const char **argv) } return EC_SUCCESS; }; -DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch, "[ save | restore | ]", +DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch, + "[ save | restore | | ]", "Save, restore, get or set console channel mask"); #endif /* CONFIG_CONSOLE_CHANNEL */ diff --git a/zephyr/test/drivers/default/src/console.c b/zephyr/test/drivers/default/src/console.c index a3df2fb03a..8c5acd7d74 100644 --- a/zephyr/test/drivers/default/src/console.c +++ b/zephyr/test/drivers/default/src/console.c @@ -104,6 +104,30 @@ ZTEST_USER(console, test_cmd_chan_set) zassert_true(console_channel_is_disabled(CC_CHARGER)); } +ZTEST_USER(console, test_cmd_chan_by_name) +{ + const char name[] = "charger"; + char cmd[100]; + + console_channel_enable(name); + + /* Toggle 'charger' off */ + zassert_true(crec_snprintf(cmd, sizeof(cmd), "chan %s", name) > 0, + "Failed to compose chan %s command.", name); + zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), + "Failed to execute chan %s command.", name); + zassert_true(console_channel_is_disabled(CC_CHARGER), + "Failed to enable %s channel.", name); + + /* Toggle 'charger' on */ + zassert_true(crec_snprintf(cmd, sizeof(cmd), "chan %s", name) > 0, + "Failed to compose chan %s command.", name); + zassert_ok(shell_execute_cmd(get_ec_shell(), cmd), + "Failed to execute chan %s command.", name); + zassert_false(console_channel_is_disabled(CC_CHARGER), + "Failed to disable %s channel.", name); +} + ZTEST_USER(console, test_cmd_chan_show) { const struct shell *shell_zephyr = get_ec_shell(); -- cgit v1.2.1