diff options
Diffstat (limited to 'os/various')
-rw-r--r-- | os/various/chprintf.c | 21 | ||||
-rw-r--r-- | os/various/chprintf.h | 2 | ||||
-rw-r--r-- | os/various/shell.c | 36 | ||||
-rw-r--r-- | os/various/shell.h | 6 |
4 files changed, 38 insertions, 27 deletions
diff --git a/os/various/chprintf.c b/os/various/chprintf.c index 1b2c3329c..3cb66bf91 100644 --- a/os/various/chprintf.c +++ b/os/various/chprintf.c @@ -29,6 +29,11 @@ #define MAX_FILLER 11
#define FLOAT_PRECISION 100000
+static void _putc(BaseSequentialStream *chp, char c) {
+
+ chSequentialStreamWrite(chp, (const uint8_t *)&c, 1);
+}
+
static char *long_to_string_with_divisor(char *p,
long num,
unsigned radix,
@@ -83,7 +88,7 @@ static char *ftoa(char *p, double num) { /**
* @brief System formatted output function.
* @details This function implements a minimal @p printf() like functionality
- * with output on a @p BaseChannel.
+ * with output on a @p BaseSequentialStream.
* The general parameters format is: %[-][width|*][.precision|*][l|L]p.
* The following parameter types (p) are supported:
* - <b>x</b> hexadecimal integer.
@@ -98,10 +103,10 @@ static char *ftoa(char *p, double num) { * - <b>s</b> string.
* .
*
- * @param[in] chp pointer to a @p BaseChannel implementing object
+ * @param[in] chp pointer to a @p BaseSequentialStream implementing object
* @param[in] fmt formatting string
*/
-void chprintf(BaseChannel *chp, const char *fmt, ...) {
+void chprintf(BaseSequentialStream *chp, const char *fmt, ...) {
va_list ap;
char tmpbuf[MAX_FILLER + 1];
char *p, *s, c, filler;
@@ -120,7 +125,7 @@ void chprintf(BaseChannel *chp, const char *fmt, ...) { return;
}
if (c != '%') {
- chIOPut(chp, (uint8_t)c);
+ _putc(chp, (uint8_t)c);
continue;
}
p = tmpbuf;
@@ -235,18 +240,18 @@ unsigned_common: width = -width;
if (width < 0) {
if (*s == '-' && filler == '0') {
- chIOPut(chp, (uint8_t)*s++);
+ _putc(chp, (uint8_t)*s++);
i--;
}
do
- chIOPut(chp, (uint8_t)filler);
+ _putc(chp, (uint8_t)filler);
while (++width != 0);
}
while (--i >= 0)
- chIOPut(chp, (uint8_t)*s++);
+ _putc(chp, (uint8_t)*s++);
while (width) {
- chIOPut(chp, (uint8_t)filler);
+ _putc(chp, (uint8_t)filler);
width--;
}
}
diff --git a/os/various/chprintf.h b/os/various/chprintf.h index 866dfa067..039b23a6b 100644 --- a/os/various/chprintf.h +++ b/os/various/chprintf.h @@ -39,7 +39,7 @@ #ifdef __cplusplus
extern "C" {
#endif
- void chprintf(BaseChannel *chp, const char *fmt, ...);
+ void chprintf(BaseSequentialStream *chp, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
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;
}
}
diff --git a/os/various/shell.h b/os/various/shell.h index 17c3609ab..6da791110 100644 --- a/os/various/shell.h +++ b/os/various/shell.h @@ -46,7 +46,7 @@ /**
* @brief Command handler function type.
*/
-typedef void (*shellcmd_t)(BaseChannel *chp, int argc, char *argv[]);
+typedef void (*shellcmd_t)(BaseSequentialStream *chp, int argc, char *argv[]);
/**
* @brief Custom command entry type.
@@ -60,7 +60,7 @@ typedef struct { * @brief Shell descriptor type.
*/
typedef struct {
- BaseChannel *sc_channel; /**< @brief I/O channel associated
+ BaseSequentialStream *sc_channel; /**< @brief I/O channel associated
to the shell. */
const ShellCommand *sc_commands; /**< @brief Shell extra commands
table. */
@@ -77,7 +77,7 @@ extern "C" { Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
Thread *shellCreateStatic(const ShellConfig *scp, void *wsp,
size_t size, tprio_t prio);
- bool_t shellGetLine(BaseChannel *chp, char *line, unsigned size);
+ bool_t shellGetLine(BaseSequentialStream *chp, char *line, unsigned size);
#ifdef __cplusplus
}
#endif
|