Fixed shell dependencies on RT.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9150 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
Giovanni Di Sirio 2016-03-22 14:02:36 +00:00
parent 8b53874c73
commit f8c7e7e99c
3 changed files with 36 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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

View File

@ -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