summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-09-30 11:53:59 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-05 19:13:26 +0000
commit3343af13117934611ce1a682acd1f99b8b10ed74 (patch)
treee5b4e0b0ef6a7b6302db95091f18fa13e43cdc12
parente000ea82e086d3d671180ca23feee1faea1537dd (diff)
downloadchrome-ec-3343af13117934611ce1a682acd1f99b8b10ed74.tar.gz
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 <dnojiri@chromium.org> Change-Id: I0cfc4beff54451d5bc211c5b3c30f5b0747e6d28 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3930855 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--common/console_output.c27
-rw-r--r--zephyr/test/drivers/default/src/console.c24
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 | <mask> ]",
+DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch,
+ "[ save | restore | <mask> | <name> ]",
"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();