summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-02-26 11:01:00 -0700
committerCommit Bot <commit-bot@chromium.org>2021-02-26 21:47:02 +0000
commit6719c67cd4d81be791e231ba8e495a67fc482edc (patch)
treed32eb907ef2baef25e4ea0ac10f455c2dcb6ad49
parent6c2c8963fcf9973bc67ba784f5a5e0b82c3ecbf4 (diff)
downloadchrome-ec-6719c67cd4d81be791e231ba8e495a67fc482edc.tar.gz
zephyr: console: add functions to enable/disable the shell
Adds functions that will allow us to temporarily take over the uart from the shell. Note that for platform/ec code without Zephyr, these functions are stubs so they are safe to call from common code, though we'll most likely need other logic (such as turning off the console task). This isn't done in these functions because the Zephyr shell behaves differently from the task and in the example of efs2 needs to be turned off earlier than the platform/ec console task. BRANCH=none BUG=b:164421798 TEST=zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I75fc8fe2ca9214f216561ded97818880dda247d5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2723495 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
-rw-r--r--include/console.h19
-rw-r--r--zephyr/shim/src/console.c25
2 files changed, 44 insertions, 0 deletions
diff --git a/include/console.h b/include/console.h
index 47c2113ec3..f517d3e074 100644
--- a/include/console.h
+++ b/include/console.h
@@ -16,6 +16,25 @@
#endif
/*
+ * Define uart_shell_stop() and uart_shell_start() functions to start/stop the
+ * running shell. To avoid having a guard on the build type, non-Zephyr builds
+ * will have a stubbed function for these which is safe to call. These functions
+ * will stop/start the Zephyr shell from processing, they should be used for
+ * briefly taking control of the uart.
+ */
+#ifdef CONFIG_ZEPHYR
+void uart_shell_stop(void);
+void uart_shell_start(void);
+#else
+static inline void uart_shell_stop(void)
+{
+}
+static inline void uart_shell_start(void)
+{
+}
+#endif
+
+/*
* The EC code base has been using %h to print a hex buffer. Encode the
* parameters to do that in a pointer to a structure that's passed as the
* printf argument. This is done rather than something like %.123ph because
diff --git a/zephyr/shim/src/console.c b/zephyr/shim/src/console.c
index 58260cf755..f07b3ca83a 100644
--- a/zephyr/shim/src/console.c
+++ b/zephyr/shim/src/console.c
@@ -28,6 +28,31 @@ static int init_uart_dev(const struct device *unused)
SYS_INIT(init_uart_dev, POST_KERNEL, 50);
#endif
+void uart_shell_stop(void)
+{
+ /* Disable interrupts for the uart. */
+ if (uart_dev) {
+ uart_irq_tx_disable(uart_dev);
+ uart_irq_rx_disable(uart_dev);
+ }
+
+ /* Stop the shell and process all pending operations. */
+ shell_stop(shell_backend_uart_get_ptr());
+ shell_process(shell_backend_uart_get_ptr());
+}
+
+void uart_shell_start(void)
+{
+ /* Restart the shell. */
+ shell_start(shell_backend_uart_get_ptr());
+
+ /* Re-enable interrupts for the uart. */
+ if (uart_dev) {
+ uart_irq_rx_enable(uart_dev);
+ uart_irq_tx_enable(uart_dev);
+ }
+}
+
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,