Skip to content

Commit 75ad61f

Browse files
Jakub Rzeszutkocarlescufi
authored andcommitted
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 <[email protected]>
1 parent c8eeb91 commit 75ad61f

File tree

6 files changed

+23
-239
lines changed

6 files changed

+23
-239
lines changed

include/shell/shell.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ enum shell_state {
247247
SHELL_STATE_UNINITIALIZED,
248248
SHELL_STATE_INITIALIZED,
249249
SHELL_STATE_ACTIVE,
250-
SHELL_STATE_COMMAND,
251250
SHELL_STATE_PANIC_MODE_ACTIVE, /*!< Panic activated.*/
252251
SHELL_STATE_PANIC_MODE_INACTIVE /*!< Panic requested, not supported.*/
253252
};
@@ -391,7 +390,6 @@ enum shell_signal {
391390
SHELL_SIGNAL_RXRDY,
392391
SHELL_SIGNAL_LOG_MSG,
393392
SHELL_SIGNAL_KILL,
394-
SHELL_SIGNAL_COMMAND_EXIT,
395393
SHELL_SIGNAL_TXDONE,
396394
SHELL_SIGNALS
397395
};
@@ -585,10 +583,8 @@ int shell_stop(const struct shell *shell);
585583
/**
586584
* @brief printf-like function which sends formatted data stream to the shell.
587585
*
588-
* This function shall not be used outside of the shell command context unless
589-
* command requested to stay in the foreground (see @ref shell_command_enter).
590-
* In that case, function can be called from any thread context until command is
591-
* terminated with CTRL+C or @ref shell_command_exit call.
586+
* This function can be used from the command handler or from threads, but not
587+
* from an interrupt context.
592588
*
593589
* @param[in] shell Pointer to the shell instance.
594590
* @param[in] color Printed text color.
@@ -654,24 +650,6 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
654650
*/
655651
void shell_process(const struct shell *shell);
656652

657-
/**
658-
* @brief Indicate to shell that command stay in foreground, blocking the shell.
659-
*
660-
* Command in foreground is terminated by @ref shell_command_exit or CTRL+C.
661-
*
662-
* @param[in] shell Pointer to the shell instance.
663-
*/
664-
void shell_command_enter(const struct shell *shell);
665-
666-
/**
667-
* @brief Exit command in foreground state.
668-
*
669-
* See @ref shell_command_enter.
670-
*
671-
* @param[in] shell Pointer to the shell instance.
672-
*/
673-
void shell_command_exit(const struct shell *shell);
674-
675653
/**
676654
* @brief Change displayed shell prompt.
677655
*

samples/subsys/shell/shell_module/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
33
project(shell_module)
44

55
target_sources(app PRIVATE src/main.c src/test_module.c)
6-
target_sources_ifdef(CONFIG_SHELL_FOREGROUND_CMDS app PRIVATE src/foreground_cmd.c)
76
target_sources_ifdef(CONFIG_SHELL_DYNAMIC_CMDS app PRIVATE src/dynamic_cmd.c src/qsort.c)

samples/subsys/shell/shell_module/prj_minimal.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ CONFIG_SHELL_HISTORY=n
1212
CONFIG_SHELL_STACK_SIZE=1024
1313
CONFIG_SHELL_CMD_BUFF_SIZE=128
1414
CONFIG_SHELL_WILDCARD=n
15-
CONFIG_SHELL_FOREGROUND_CMDS=n
1615
CONFIG_SHELL_DYNAMIC_CMDS=n
16+
CONFIG_SHELL_PROMPT_LENGTH=10
17+
CONFIG_SHELL_VT100_COLORS=n
18+
CONFIG_SHELL_HELP_ON_WRONG_ARGUMENT_COUNT=n
19+
CONFIG_SHELL_STATS=n
20+
CONFIG_SHELL_CMDS=n
1721

samples/subsys/shell/shell_module/src/foreground_cmd.c

Lines changed: 0 additions & 137 deletions
This file was deleted.

subsys/net/ip/net_shell.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,11 +3007,9 @@ static inline void _remove_ipv6_ping_handler(void)
30073007

30083008
static enum net_verdict _handle_ipv6_echo_reply(struct net_pkt *pkt)
30093009
{
3010-
shell_command_enter(shell_for_ping);
30113010
PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n",
30123011
net_sprint_ipv6_addr(&NET_IPV6_HDR(pkt)->src),
30133012
net_sprint_ipv6_addr(&NET_IPV6_HDR(pkt)->dst));
3014-
shell_command_exit(shell_for_ping);
30153013
k_sem_give(&ping_timeout);
30163014
_remove_ipv6_ping_handler();
30173015

@@ -3082,11 +3080,9 @@ static inline void _remove_ipv4_ping_handler(void)
30823080

30833081
static enum net_verdict _handle_ipv4_echo_reply(struct net_pkt *pkt)
30843082
{
3085-
shell_command_enter(shell_for_ping);
30863083
PR_SHELL(shell_for_ping, "Received echo reply from %s to %s\n",
30873084
net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->src),
30883085
net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->dst));
3089-
shell_command_exit(shell_for_ping);
30903086
k_sem_give(&ping_timeout);
30913087
_remove_ipv4_ping_handler();
30923088

subsys/shell/shell.c

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -887,22 +887,17 @@ static void state_collect(const struct shell *shell)
887887
switch (shell->ctx->receive_state) {
888888
case SHELL_RECEIVE_DEFAULT:
889889
if (process_nl(shell, data)) {
890-
int err = 0;
891-
892890
if (!shell->ctx->cmd_buff_len) {
893891
history_mode_exit(shell);
894892
cursor_next_line_move(shell);
895893
} else {
896894
/* Command execution */
897-
err = execute(shell);
895+
(void)execute(shell);
898896
}
899897
/* Function responsible for printing prompt
900898
* on received NL.
901899
*/
902-
if (err ||
903-
shell->ctx->state != SHELL_STATE_COMMAND) {
904-
state_set(shell, SHELL_STATE_ACTIVE);
905-
}
900+
state_set(shell, SHELL_STATE_ACTIVE);
906901
return;
907902
}
908903

@@ -1072,22 +1067,20 @@ static void shell_log_process(const struct shell *shell)
10721067

10731068
processed = shell_log_backend_process(shell->log_backend);
10741069

1075-
if (shell->ctx->state != SHELL_STATE_COMMAND) {
1076-
struct k_poll_signal *signal =
1077-
&shell->ctx->signals[SHELL_SIGNAL_RXRDY];
1078-
1079-
cmd_line_print(shell);
1070+
struct k_poll_signal *signal =
1071+
&shell->ctx->signals[SHELL_SIGNAL_RXRDY];
10801072

1081-
/* Arbitrary delay added to ensure that prompt is
1082-
* readable and can be used to enter further commands.
1083-
*/
1084-
if (shell->ctx->cmd_buff_len) {
1085-
k_sleep(K_MSEC(15));
1086-
}
1073+
cmd_line_print(shell);
10871074

1088-
k_poll_signal_check(signal, &signaled, &result);
1075+
/* Arbitrary delay added to ensure that prompt is
1076+
* readable and can be used to enter further commands.
1077+
*/
1078+
if (shell->ctx->cmd_buff_len) {
1079+
k_sleep(K_MSEC(15));
10891080
}
10901081

1082+
k_poll_signal_check(signal, &signaled, &result);
1083+
10911084
if (shell->ctx->state < SHELL_STATE_PANIC_MODE_ACTIVE) {
10921085
k_mutex_unlock(&shell->ctx->wr_mtx);
10931086
}
@@ -1184,11 +1177,6 @@ static void kill_handler(const struct shell *shell)
11841177
k_thread_abort(k_current_get());
11851178
}
11861179

1187-
static void command_exit_handler(const struct shell *shell)
1188-
{
1189-
state_set(shell, SHELL_STATE_ACTIVE);
1190-
}
1191-
11921180
void shell_thread(void *shell_handle, void *arg_log_backend,
11931181
void *arg_log_level)
11941182
{
@@ -1219,26 +1207,16 @@ void shell_thread(void *shell_handle, void *arg_log_backend,
12191207
if (shell->iface->api->update) {
12201208
shell->iface->api->update(shell->iface);
12211209
}
1222-
int num_events = (shell->ctx->state != SHELL_STATE_COMMAND) ?
1223-
SHELL_SIGNALS : SHELL_SIGNAL_TXDONE;
12241210

1225-
err = k_poll(shell->ctx->events, num_events, K_FOREVER);
1211+
err = k_poll(shell->ctx->events, SHELL_SIGNALS, K_FOREVER);
12261212
if (err != 0) {
1213+
shell_error(shell, "Shell thread error: %d", err);
12271214
return;
12281215
}
12291216

1230-
/* Check for KILL request */
12311217
shell_signal_handle(shell, SHELL_SIGNAL_KILL, kill_handler);
12321218
shell_signal_handle(shell, SHELL_SIGNAL_RXRDY, shell_process);
1233-
1234-
if (shell->ctx->state == SHELL_STATE_COMMAND) {
1235-
shell_signal_handle(shell, SHELL_SIGNAL_COMMAND_EXIT,
1236-
command_exit_handler);
1237-
} else {
1238-
shell_signal_handle(shell, SHELL_SIGNAL_TXDONE,
1239-
shell_process);
1240-
}
1241-
1219+
shell_signal_handle(shell, SHELL_SIGNAL_TXDONE, shell_process);
12421220
if (IS_ENABLED(CONFIG_LOG)) {
12431221
shell_signal_handle(shell, SHELL_SIGNAL_LOG_MSG,
12441222
shell_log_process);
@@ -1329,35 +1307,6 @@ int shell_stop(const struct shell *shell)
13291307
return 0;
13301308
}
13311309

1332-
void shell_command_enter(const struct shell *shell)
1333-
{
1334-
state_set(shell, SHELL_STATE_COMMAND);
1335-
}
1336-
1337-
void shell_command_exit(const struct shell *shell)
1338-
{
1339-
struct k_poll_signal *signal =
1340-
&shell->ctx->signals[SHELL_SIGNAL_COMMAND_EXIT];
1341-
1342-
(void)k_poll_signal_raise(signal, 0);
1343-
}
1344-
1345-
static void shell_state_command(const struct shell *shell)
1346-
{
1347-
size_t count;
1348-
char data;
1349-
1350-
(void)shell->iface->api->read(shell->iface, &data,
1351-
sizeof(data), &count);
1352-
if (count == 0) {
1353-
return;
1354-
}
1355-
1356-
if (data == SHELL_VT100_ASCII_CTRL_C) {
1357-
state_set(shell, SHELL_STATE_ACTIVE);
1358-
}
1359-
}
1360-
13611310
void shell_process(const struct shell *shell)
13621311
{
13631312
__ASSERT_NO_MSG(shell);
@@ -1380,10 +1329,6 @@ void shell_process(const struct shell *shell)
13801329
case SHELL_STATE_ACTIVE:
13811330
state_collect(shell);
13821331
break;
1383-
case SHELL_STATE_COMMAND:
1384-
shell_state_command(shell);
1385-
break;
1386-
13871332
default:
13881333
break;
13891334
}
@@ -1405,8 +1350,7 @@ void shell_fprintf(const struct shell *shell, enum shell_vt100_color color,
14051350

14061351
va_list args = { 0 };
14071352

1408-
if (k_current_get() != shell->ctx->tid &&
1409-
shell->ctx->state != SHELL_STATE_COMMAND) {
1353+
if (k_current_get() != shell->ctx->tid) {
14101354
return;
14111355
}
14121356

0 commit comments

Comments
 (0)