From 75ad61f7ef9dfd7db053942819cb647e0267d1e4 Mon Sep 17 00:00:00 2001 From: Jakub Rzeszutko Date: Fri, 25 Jan 2019 09:48:09 +0100 Subject: [PATCH] shell: removed foreground command functionality Removed foreground command functionality from shell source files. Removed associated example. Removed enter/exit command functions from the Bluetooth example Updated project config files. Signed-off-by: Jakub Rzeszutko --- include/shell/shell.h | 26 +--- .../subsys/shell/shell_module/CMakeLists.txt | 1 - .../shell/shell_module/prj_minimal.conf | 6 +- .../shell/shell_module/src/foreground_cmd.c | 137 ------------------ subsys/net/ip/net_shell.c | 4 - subsys/shell/shell.c | 88 ++--------- 6 files changed, 23 insertions(+), 239 deletions(-) delete mode 100644 samples/subsys/shell/shell_module/src/foreground_cmd.c diff --git a/include/shell/shell.h b/include/shell/shell.h index b9882df21da..92bc2a9d992 100644 --- a/include/shell/shell.h +++ b/include/shell/shell.h @@ -247,7 +247,6 @@ enum shell_state { SHELL_STATE_UNINITIALIZED, SHELL_STATE_INITIALIZED, SHELL_STATE_ACTIVE, - SHELL_STATE_COMMAND, SHELL_STATE_PANIC_MODE_ACTIVE, /*!< Panic activated.*/ SHELL_STATE_PANIC_MODE_INACTIVE /*!< Panic requested, not supported.*/ }; @@ -391,7 +390,6 @@ enum shell_signal { SHELL_SIGNAL_RXRDY, SHELL_SIGNAL_LOG_MSG, SHELL_SIGNAL_KILL, - SHELL_SIGNAL_COMMAND_EXIT, SHELL_SIGNAL_TXDONE, SHELL_SIGNALS }; @@ -585,10 +583,8 @@ int shell_stop(const struct shell *shell); /** * @brief printf-like function which sends formatted data stream to the shell. * - * This function shall not be used outside of the shell command context unless - * command requested to stay in the foreground (see @ref shell_command_enter). - * In that case, function can be called from any thread context until command is - * terminated with CTRL+C or @ref shell_command_exit call. + * This function can be used from the command handler or from threads, but not + * from an interrupt context. * * @param[in] shell Pointer to the shell instance. * @param[in] color Printed text color. @@ -654,24 +650,6 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, */ void shell_process(const struct shell *shell); -/** - * @brief Indicate to shell that command stay in foreground, blocking the shell. - * - * Command in foreground is terminated by @ref shell_command_exit or CTRL+C. - * - * @param[in] shell Pointer to the shell instance. - */ -void shell_command_enter(const struct shell *shell); - -/** - * @brief Exit command in foreground state. - * - * See @ref shell_command_enter. - * - * @param[in] shell Pointer to the shell instance. - */ -void shell_command_exit(const struct shell *shell); - /** * @brief Change displayed shell prompt. * diff --git a/samples/subsys/shell/shell_module/CMakeLists.txt b/samples/subsys/shell/shell_module/CMakeLists.txt index 93929e424be..a2fd8620da6 100644 --- a/samples/subsys/shell/shell_module/CMakeLists.txt +++ b/samples/subsys/shell/shell_module/CMakeLists.txt @@ -3,5 +3,4 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(shell_module) target_sources(app PRIVATE src/main.c src/test_module.c) -target_sources_ifdef(CONFIG_SHELL_FOREGROUND_CMDS app PRIVATE src/foreground_cmd.c) target_sources_ifdef(CONFIG_SHELL_DYNAMIC_CMDS app PRIVATE src/dynamic_cmd.c src/qsort.c) diff --git a/samples/subsys/shell/shell_module/prj_minimal.conf b/samples/subsys/shell/shell_module/prj_minimal.conf index a378446e6c7..3c2a91c1741 100644 --- a/samples/subsys/shell/shell_module/prj_minimal.conf +++ b/samples/subsys/shell/shell_module/prj_minimal.conf @@ -12,6 +12,10 @@ CONFIG_SHELL_HISTORY=n CONFIG_SHELL_STACK_SIZE=1024 CONFIG_SHELL_CMD_BUFF_SIZE=128 CONFIG_SHELL_WILDCARD=n -CONFIG_SHELL_FOREGROUND_CMDS=n CONFIG_SHELL_DYNAMIC_CMDS=n +CONFIG_SHELL_PROMPT_LENGTH=10 +CONFIG_SHELL_VT100_COLORS=n +CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n +CONFIG_SHELL_STATS=n +CONFIG_SHELL_CMDS=n diff --git a/samples/subsys/shell/shell_module/src/foreground_cmd.c b/samples/subsys/shell/shell_module/src/foreground_cmd.c deleted file mode 100644 index 107a0286f6b..00000000000 --- a/samples/subsys/shell/shell_module/src/foreground_cmd.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#define FOREGROUND_TIMER_HELP \ - "Demo command showing printing to shell from various contexts" - -#define FOREGROUND_TIMER_START_HELP \ - "Start periodic timer. Timer handler prints to shell. CTRL+C" \ - " terminates printing. Timer keeps running in background." - -#define FOREGROUND_TIMER_STOP_HELP \ - "Stop timer." - -#define FOREGROUND_TIMER_SINGLE_SHOT_HELP \ - "Start single shot timer." - -struct timer_work_duo { - struct k_timer timer; - struct k_work work; - const struct shell *shell; - bool single_shot; - bool running; -}; - -static struct timer_work_duo data; - -static void timer_expired_work(struct k_work *work) -{ - struct timer_work_duo *data = - CONTAINER_OF(work, struct timer_work_duo, work); - - shell_print(data->shell, "Timer expired."); - - if (data->single_shot) { - shell_print(data->shell, "Single shot timer command exits."); - shell_command_exit(data->shell); - data->running = false; - } -} - -static void timer_handler(struct k_timer *timer) -{ - struct timer_work_duo *data = - CONTAINER_OF(timer, struct timer_work_duo, timer); - - k_work_submit(&data->work); -} - -static int start_timer(const struct shell *shell, bool single_shot) -{ - - if (data.running) { - shell_error(shell, "Timer is already started."); - return -ENOEXEC; - } - - k_timer_init(&data.timer, timer_handler, NULL); - k_work_init(&data.work, timer_expired_work); - data.shell = shell; - data.single_shot = single_shot; - data.running = true; - - k_timer_start(&data.timer, 1000, single_shot ? 0 : 1000); - - shell_command_enter(shell); - - return 0; - -} -static int cmd_fg_timer_start(const struct shell *shell, - size_t argc, char **argv) -{ - ARG_UNUSED(argc); - ARG_UNUSED(argv); - - int err; - - err = start_timer(shell, false); - - if (err == 0) { - shell_print(shell, "Periodic timer started."); - } - - return err; -} - -static int cmd_fg_timer_single_shot(const struct shell *shell, - size_t argc, char **argv) -{ - ARG_UNUSED(argc); - ARG_UNUSED(argv); - - int err; - - err = start_timer(shell, true); - - if (err == 0) { - shell_print(shell, "Single shot started."); - } - - return err; -} - -static int cmd_fg_timer_stop(const struct shell *shell, - size_t argc, char **argv) -{ - ARG_UNUSED(argc); - ARG_UNUSED(argv); - - k_timer_stop(&data.timer); - data.running = false; - - shell_print(shell, "Timer stopped."); - - return 0; -} - -SHELL_CREATE_STATIC_SUBCMD_SET(sub_foreground_timer) -{ - /* Alphabetically sorted. */ - SHELL_CMD_ARG(start, NULL, FOREGROUND_TIMER_START_HELP, - cmd_fg_timer_start, 1, 0), - SHELL_CMD_ARG(stop, NULL, FOREGROUND_TIMER_STOP_HELP, - cmd_fg_timer_stop, 1, 0), - SHELL_CMD_ARG(single_shot, NULL, FOREGROUND_TIMER_SINGLE_SHOT_HELP, - cmd_fg_timer_single_shot, 1, 0), - SHELL_SUBCMD_SET_END /* Array terminated. */ -}; - -SHELL_CMD_ARG_REGISTER(foreground_timer, &sub_foreground_timer, - FOREGROUND_TIMER_HELP, NULL, 1, 1); diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 3c6379250fc..d3f10e09b3a 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -3007,11 +3007,9 @@ static inline void _remove_ipv6_ping_handler(void) static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt) { - shell_command_enter(shell_for_ping); PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n", net_sprint_ipv6_addr(&NET_IPV6_HDR(pkt)->src), net_sprint_ipv6_addr(&NET_IPV6_HDR(pkt)->dst)); - shell_command_exit(shell_for_ping); k_sem_give(&ping_timeout); _remove_ipv6_ping_handler(); @@ -3082,11 +3080,9 @@ static inline void _remove_ipv4_ping_handler(void) static enum net_verdict _handle_ipv4_echo_reply(struct net_pkt *pkt) { - shell_command_enter(shell_for_ping); PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n", net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->src), net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->dst)); - shell_command_exit(shell_for_ping); k_sem_give(&ping_timeout); _remove_ipv4_ping_handler(); diff --git a/subsys/shell/shell.c b/subsys/shell/shell.c index 739ead70fc8..b2c59193e3e 100644 --- a/subsys/shell/shell.c +++ b/subsys/shell/shell.c @@ -887,22 +887,17 @@ static void state_collect(const struct shell *shell) switch (shell->ctx->receive_state) { case SHELL_RECEIVE_DEFAULT: if (process_nl(shell, data)) { - int err = 0; - if (!shell->ctx->cmd_buff_len) { history_mode_exit(shell); cursor_next_line_move(shell); } else { /* Command execution */ - err = execute(shell); + (void)execute(shell); } /* Function responsible for printing prompt * on received NL. */ - if (err || - shell->ctx->state != SHELL_STATE_COMMAND) { - state_set(shell, SHELL_STATE_ACTIVE); - } + state_set(shell, SHELL_STATE_ACTIVE); return; } @@ -1072,22 +1067,20 @@ static void shell_log_process(const struct shell *shell) processed = shell_log_backend_process(shell->log_backend); - if (shell->ctx->state != SHELL_STATE_COMMAND) { - struct k_poll_signal *signal = - &shell->ctx->signals[SHELL_SIGNAL_RXRDY]; + struct k_poll_signal *signal = + &shell->ctx->signals[SHELL_SIGNAL_RXRDY]; - cmd_line_print(shell); + cmd_line_print(shell); - /* Arbitrary delay added to ensure that prompt is - * readable and can be used to enter further commands. - */ - if (shell->ctx->cmd_buff_len) { - k_sleep(K_MSEC(15)); - } - - k_poll_signal_check(signal, &signaled, &result); + /* Arbitrary delay added to ensure that prompt is + * readable and can be used to enter further commands. + */ + if (shell->ctx->cmd_buff_len) { + k_sleep(K_MSEC(15)); } + k_poll_signal_check(signal, &signaled, &result); + if (shell->ctx->state < SHELL_STATE_PANIC_MODE_ACTIVE) { k_mutex_unlock(&shell->ctx->wr_mtx); } @@ -1184,11 +1177,6 @@ static void kill_handler(const struct shell *shell) k_thread_abort(k_current_get()); } -static void command_exit_handler(const struct shell *shell) -{ - state_set(shell, SHELL_STATE_ACTIVE); -} - void shell_thread(void *shell_handle, void *arg_log_backend, void *arg_log_level) { @@ -1219,26 +1207,16 @@ void shell_thread(void *shell_handle, void *arg_log_backend, if (shell->iface->api->update) { shell->iface->api->update(shell->iface); } - int num_events = (shell->ctx->state != SHELL_STATE_COMMAND) ? - SHELL_SIGNALS : SHELL_SIGNAL_TXDONE; - err = k_poll(shell->ctx->events, num_events, K_FOREVER); + err = k_poll(shell->ctx->events, SHELL_SIGNALS, K_FOREVER); if (err != 0) { + shell_error(shell, "Shell thread error: %d", err); return; } - /* Check for KILL request */ shell_signal_handle(shell, SHELL_SIGNAL_KILL, kill_handler); shell_signal_handle(shell, SHELL_SIGNAL_RXRDY, shell_process); - - if (shell->ctx->state == SHELL_STATE_COMMAND) { - shell_signal_handle(shell, SHELL_SIGNAL_COMMAND_EXIT, - command_exit_handler); - } else { - shell_signal_handle(shell, SHELL_SIGNAL_TXDONE, - shell_process); - } - + shell_signal_handle(shell, SHELL_SIGNAL_TXDONE, shell_process); if (IS_ENABLED(CONFIG_LOG)) { shell_signal_handle(shell, SHELL_SIGNAL_LOG_MSG, shell_log_process); @@ -1329,35 +1307,6 @@ int shell_stop(const struct shell *shell) return 0; } -void shell_command_enter(const struct shell *shell) -{ - state_set(shell, SHELL_STATE_COMMAND); -} - -void shell_command_exit(const struct shell *shell) -{ - struct k_poll_signal *signal = - &shell->ctx->signals[SHELL_SIGNAL_COMMAND_EXIT]; - - (void)k_poll_signal_raise(signal, 0); -} - -static void shell_state_command(const struct shell *shell) -{ - size_t count; - char data; - - (void)shell->iface->api->read(shell->iface, &data, - sizeof(data), &count); - if (count == 0) { - return; - } - - if (data == SHELL_VT100_ASCII_CTRL_C) { - state_set(shell, SHELL_STATE_ACTIVE); - } -} - void shell_process(const struct shell *shell) { __ASSERT_NO_MSG(shell); @@ -1380,10 +1329,6 @@ void shell_process(const struct shell *shell) case SHELL_STATE_ACTIVE: state_collect(shell); break; - case SHELL_STATE_COMMAND: - shell_state_command(shell); - break; - default: break; } @@ -1405,8 +1350,7 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color, va_list args = { 0 }; - if (k_current_get() != shell->ctx->tid && - shell->ctx->state != SHELL_STATE_COMMAND) { + if (k_current_get() != shell->ctx->tid) { return; }