aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2016-03-22 14:02:36 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2016-03-22 14:02:36 +0000
commitf8c7e7e99cc005392dd099be9c3670e8386bd518 (patch)
tree31b0b157ab7fd2dd95a74f95fbd25fc6acfaa9a4
parent8b53874c73dabebaa1cf57c4fef45c1a3ccf4cc5 (diff)
downloadChibiOS-f8c7e7e99cc005392dd099be9c3670e8386bd518.tar.gz
ChibiOS-f8c7e7e99cc005392dd099be9c3670e8386bd518.tar.bz2
ChibiOS-f8c7e7e99cc005392dd099be9c3670e8386bd518.zip
Fixed shell dependencies on RT.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9150 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/various/shell/shell.c20
-rw-r--r--os/various/shell/shell_cmd.c17
-rw-r--r--os/various/shell/shell_cmd.h4
3 files changed, 36 insertions, 5 deletions
diff --git a/os/various/shell/shell.c b/os/various/shell/shell.c
index 69461e00e..a0998fbbe 100644
--- a/os/various/shell/shell.c
+++ b/os/various/shell/shell.c
@@ -134,8 +134,14 @@ THD_FUNCTION(shellThread, p) {
while (true) {
chprintf(chp, "ch> ");
if (shellGetLine(chp, line, sizeof(line))) {
+#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
chprintf(chp, "\r\nlogout");
break;
+#else
+ /* Putting a delay in order to avoid an endless loop trying to read
+ an unavailable stream.*/
+ osalThreadSleepMilliseconds(100);
+#endif
}
lp = parse_arguments(line, &tokp);
cmd = lp;
@@ -188,6 +194,7 @@ void shellInit(void) {
chEvtObjectInit(&shell_terminated);
}
+#if !defined(_CHIBIOS_NIL_) || defined(__DOXYGEN__)
/**
* @brief Terminates the shell.
* @note Must be invoked from the command handlers.
@@ -205,6 +212,7 @@ void shellExit(msg_t msg) {
chEvtBroadcastI(&shell_terminated);
chThdExitS(msg);
}
+#endif
/**
* @brief Reads a whole line from the input channel.
@@ -231,17 +239,19 @@ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
while (true) {
char c;
- if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
+ if (streamRead(chp, (uint8_t *)&c, 1) == 0)
return true;
+#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
if (c == 4) {
chprintf(chp, "^D");
return true;
}
+#endif
if ((c == 8) || (c == 127)) {
if (p != line) {
- chSequentialStreamPut(chp, c);
- chSequentialStreamPut(chp, 0x20);
- chSequentialStreamPut(chp, c);
+ streamPut(chp, c);
+ streamPut(chp, 0x20);
+ streamPut(chp, c);
p--;
}
continue;
@@ -254,7 +264,7 @@ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
if (c < 0x20)
continue;
if (p < line + size - 1) {
- chSequentialStreamPut(chp, c);
+ streamPut(chp, c);
*p++ = (char)c;
}
}
diff --git a/os/various/shell/shell_cmd.c b/os/various/shell/shell_cmd.c
index 29766422a..ce88aa3cb 100644
--- a/os/various/shell/shell_cmd.c
+++ b/os/various/shell/shell_cmd.c
@@ -59,6 +59,20 @@ static void usage(BaseSequentialStream *chp, char *p) {
chprintf(chp, "Usage: %s\r\n", p);
}
+#if ((SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)) || \
+ defined(__DOXYGEN__)
+static void cmd_exit(BaseSequentialStream *chp, int argc, char *argv[]) {
+
+ (void)argv;
+ if (argc > 0) {
+ usage(chp, "exit");
+ return;
+ }
+
+ shellExit(MSG_OK);
+}
+#endif
+
#if (SHELL_CMD_INFO_ENABLED == TRUE) || defined(__DOXYGEN__)
static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
@@ -184,6 +198,9 @@ static void cmd_test(BaseSequentialStream *chp, int argc, char *argv[]) {
* @brief Array of the default commands.
*/
ShellCommand shell_local_commands[] = {
+#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
+ {"exit", cmd_exit},
+#endif
#if SHELL_CMD_INFO_ENABLED == TRUE
{"info", cmd_info},
#endif
diff --git a/os/various/shell/shell_cmd.h b/os/various/shell/shell_cmd.h
index e81fa3646..1f9ad64b1 100644
--- a/os/various/shell/shell_cmd.h
+++ b/os/various/shell/shell_cmd.h
@@ -33,6 +33,10 @@
/* Module pre-compile time settings. */
/*===========================================================================*/
+#if !defined(SHELL_CMD_EXIT_ENABLED) || defined(__DOXYGEN__)
+#define SHELL_CMD_EXIT_ENABLED TRUE
+#endif
+
#if !defined(SHELL_CMD_INFO_ENABLED) || defined(__DOXYGEN__)
#define SHELL_CMD_INFO_ENABLED TRUE
#endif