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 <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
parent
c8eeb91222
commit
75ad61f7ef
6 changed files with 23 additions and 239 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Nordic Semiconductor ASA
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <shell/shell.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#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);
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1072,7 +1067,6 @@ 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];
|
||||
|
||||
|
@ -1086,7 +1080,6 @@ static void shell_log_process(const struct shell *shell)
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue