aboutsummaryrefslogtreecommitdiffstats
path: root/os/various/shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/various/shell.c')
-rw-r--r--os/various/shell.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/os/various/shell.c b/os/various/shell.c
index bd0359052..fd9451f2e 100644
--- a/os/various/shell.c
+++ b/os/various/shell.c
@@ -38,6 +38,11 @@
*/
EventSource shell_terminated;
+static void _putc(BaseSequentialStream *chp, char c) {
+
+ chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
+}
+
static char *_strtok(char *str, const char *delim, char **saveptr) {
char *token;
if (str)
@@ -55,12 +60,12 @@ static char *_strtok(char *str, const char *delim, char **saveptr) {
return *token ? token : NULL;
}
-static void usage(BaseChannel *chp, char *p) {
+static void usage(BaseSequentialStream *chp, char *p) {
chprintf(chp, "Usage: %s\r\n", p);
}
-static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
+static void list_commands(BaseSequentialStream *chp, const ShellCommand *scp) {
while (scp->sc_name != NULL) {
chprintf(chp, "%s ", scp->sc_name);
@@ -68,7 +73,7 @@ static void list_commands(BaseChannel *chp, const ShellCommand *scp) {
}
}
-static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
+static void cmd_info(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@@ -100,7 +105,7 @@ static void cmd_info(BaseChannel *chp, int argc, char *argv[]) {
#endif
}
-static void cmd_systime(BaseChannel *chp, int argc, char *argv[]) {
+static void cmd_systime(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argv;
if (argc > 0) {
@@ -119,7 +124,7 @@ static ShellCommand local_commands[] = {
{NULL, NULL}
};
-static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
+static bool_t cmdexec(const ShellCommand *scp, BaseSequentialStream *chp,
char *name, int argc, char *argv[]) {
while (scp->sc_name != NULL) {
@@ -135,7 +140,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
/**
* @brief Shell thread function.
*
- * @param[in] p pointer to a @p BaseChannel object
+ * @param[in] p pointer to a @p BaseSequentialStream object
* @return Termination reason.
* @retval RDY_OK terminated by command.
* @retval RDY_RESET terminated by reset condition on the I/O channel.
@@ -143,7 +148,7 @@ static bool_t cmdexec(const ShellCommand *scp, BaseChannel *chp,
static msg_t shell_thread(void *p) {
int n;
msg_t msg = RDY_OK;
- BaseChannel *chp = ((ShellConfig *)p)->sc_channel;
+ BaseSequentialStream *chp = ((ShellConfig *)p)->sc_channel;
const ShellCommand *scp = ((ShellConfig *)p)->sc_commands;
char *lp, *cmd, *tokp, line[SHELL_MAX_LINE_LENGTH];
char *args[SHELL_MAX_ARGUMENTS + 1];
@@ -245,19 +250,20 @@ Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
/**
* @brief Reads a whole line from the input channel.
*
- * @param[in] chp pointer to a @p BaseChannel object
+ * @param[in] chp pointer to a @p BaseSequentialStream object
* @param[in] line pointer to the line buffer
* @param[in] size buffer maximum length
* @return The operation status.
* @retval TRUE the channel was reset or CTRL-D pressed.
* @retval FALSE operation successful.
*/
-bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
+bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size) {
char *p = line;
while (TRUE) {
- short c = (short)chIOGet(chp);
- if (c < 0)
+ char c;
+
+ if (chSequentialStreamRead(chp, (uint8_t *)&c, 1) == 0)
return TRUE;
if (c == 4) {
chprintf(chp, "^D");
@@ -265,9 +271,9 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
}
if (c == 8) {
if (p != line) {
- chIOPut(chp, (uint8_t)c);
- chIOPut(chp, 0x20);
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, c);
+ _putc(chp, 0x20);
+ _putc(chp, c);
p--;
}
continue;
@@ -280,7 +286,7 @@ bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size) {
if (c < 0x20)
continue;
if (p < line + size - 1) {
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, c);
*p++ = (char)c;
}
}