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:
parent
8b53874c73
commit
f8c7e7e99c
|
@ -134,8 +134,14 @@ THD_FUNCTION(shellThread, p) {
|
||||||
while (true) {
|
while (true) {
|
||||||
chprintf(chp, "ch> ");
|
chprintf(chp, "ch> ");
|
||||||
if (shellGetLine(chp, line, sizeof(line))) {
|
if (shellGetLine(chp, line, sizeof(line))) {
|
||||||
|
#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
|
||||||
chprintf(chp, "\r\nlogout");
|
chprintf(chp, "\r\nlogout");
|
||||||
break;
|
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);
|
lp = parse_arguments(line, &tokp);
|
||||||
cmd = lp;
|
cmd = lp;
|
||||||
|
@ -188,6 +194,7 @@ void shellInit(void) {
|
||||||
chEvtObjectInit(&shell_terminated);
|
chEvtObjectInit(&shell_terminated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(_CHIBIOS_NIL_) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Terminates the shell.
|
* @brief Terminates the shell.
|
||||||
* @note Must be invoked from the command handlers.
|
* @note Must be invoked from the command handlers.
|
||||||
|
@ -205,6 +212,7 @@ void shellExit(msg_t msg) {
|
||||||
chEvtBroadcastI(&shell_terminated);
|
chEvtBroadcastI(&shell_terminated);
|
||||||
chThdExitS(msg);
|
chThdExitS(msg);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reads a whole line from the input channel.
|
* @brief Reads a whole line from the input channel.
|
||||||
|
@ -231,17 +239,19 @@ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
|
||||||
while (true) {
|
while (true) {
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
|
if (streamRead(chp, (uint8_t *)&c, 1) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
|
||||||
if (c == 4) {
|
if (c == 4) {
|
||||||
chprintf(chp, "^D");
|
chprintf(chp, "^D");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if ((c == 8) || (c == 127)) {
|
if ((c == 8) || (c == 127)) {
|
||||||
if (p != line) {
|
if (p != line) {
|
||||||
chSequentialStreamPut(chp, c);
|
streamPut(chp, c);
|
||||||
chSequentialStreamPut(chp, 0x20);
|
streamPut(chp, 0x20);
|
||||||
chSequentialStreamPut(chp, c);
|
streamPut(chp, c);
|
||||||
p--;
|
p--;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -254,7 +264,7 @@ bool shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
|
||||||
if (c < 0x20)
|
if (c < 0x20)
|
||||||
continue;
|
continue;
|
||||||
if (p < line + size - 1) {
|
if (p < line + size - 1) {
|
||||||
chSequentialStreamPut(chp, c);
|
streamPut(chp, c);
|
||||||
*p++ = (char)c;
|
*p++ = (char)c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,20 @@ static void usage(BaseSequentialStream *chp, char *p) {
|
||||||
chprintf(chp, "Usage: %s\r\n", 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__)
|
#if (SHELL_CMD_INFO_ENABLED == TRUE) || defined(__DOXYGEN__)
|
||||||
static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
|
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.
|
* @brief Array of the default commands.
|
||||||
*/
|
*/
|
||||||
ShellCommand shell_local_commands[] = {
|
ShellCommand shell_local_commands[] = {
|
||||||
|
#if (SHELL_CMD_EXIT_ENABLED == TRUE) && !defined(_CHIBIOS_NIL_)
|
||||||
|
{"exit", cmd_exit},
|
||||||
|
#endif
|
||||||
#if SHELL_CMD_INFO_ENABLED == TRUE
|
#if SHELL_CMD_INFO_ENABLED == TRUE
|
||||||
{"info", cmd_info},
|
{"info", cmd_info},
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
/* Module pre-compile time settings. */
|
/* 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__)
|
#if !defined(SHELL_CMD_INFO_ENABLED) || defined(__DOXYGEN__)
|
||||||
#define SHELL_CMD_INFO_ENABLED TRUE
|
#define SHELL_CMD_INFO_ENABLED TRUE
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue