From: Keith Packard Date: Sat, 2 Apr 2011 00:25:07 +0000 (-0700) Subject: altos: Make cmd echo per-connection instead of global X-Git-Tag: 0.9.3~68 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=a5d60fdb9c969c1516feb76a16001c9688112c4c;hp=4e2c18249e16c98cf5f7dccdf8d3b84bc473863a altos: Make cmd echo per-connection instead of global Allow different connections to use different echo values, permitting the packet link to turn off echo while the USB link still has it on. Signed-off-by: Keith Packard --- diff --git a/src/ao.h b/src/ao.h index b92e623f..9b375894 100644 --- a/src/ao.h +++ b/src/ao.h @@ -1178,8 +1178,10 @@ struct ao_stdio { char (*pollchar)(void); void (*putchar)(char c) __reentrant; void (*flush)(void); + uint8_t echo; }; +extern __xdata struct ao_stdio ao_stdios[]; extern __data int8_t ao_cur_stdio; extern __data int8_t ao_num_stdios; @@ -1188,6 +1190,9 @@ flush(void); extern __xdata uint8_t ao_stdin_ready; +uint8_t +ao_echo(void); + void ao_add_stdio(char (*pollchar)(void), void (*putchar)(char) __reentrant, diff --git a/src/ao_cmd.c b/src/ao_cmd.c index 50d5b96f..c738a3e0 100644 --- a/src/ao_cmd.c +++ b/src/ao_cmd.c @@ -21,7 +21,6 @@ __xdata uint16_t ao_cmd_lex_i; __xdata uint32_t ao_cmd_lex_u32; __xdata char ao_cmd_lex_c; __xdata enum ao_cmd_status ao_cmd_status; -static __xdata uint8_t lex_echo; #define CMD_LEN 32 @@ -41,7 +40,7 @@ static void readline(void) { __xdata char c; - if (lex_echo) + if (ao_echo()) put_string("> "); cmd_len = 0; for (;;) { @@ -50,7 +49,7 @@ readline(void) /* backspace/delete */ if (c == '\010' || c == '\177') { if (cmd_len != 0) { - if (lex_echo) + if (ao_echo()) put_string("\010 \010"); --cmd_len; } @@ -60,7 +59,7 @@ readline(void) /* ^U */ if (c == '\025') { while (cmd_len != 0) { - if (lex_echo) + if (ao_echo()) put_string("\010 \010"); --cmd_len; } @@ -72,18 +71,18 @@ readline(void) c = '\n'; if (c == '\n') { - if (lex_echo) + if (ao_echo()) putchar('\n'); break; } if (cmd_len >= CMD_LEN - 2) { - if (lex_echo) + if (ao_echo()) putchar('\007'); continue; } cmd_line[cmd_len++] = c; - if (lex_echo) + if (ao_echo()) putchar(c); } cmd_line[cmd_len++] = '\n'; @@ -198,7 +197,8 @@ static void echo(void) { ao_cmd_hex(); - lex_echo = ao_cmd_lex_i != 0; + if (ao_cmd_status == ao_cmd_success) + ao_stdios[ao_cur_stdio].echo = ao_cmd_lex_i != 0; } static void @@ -272,7 +272,6 @@ ao_cmd(void) __code struct ao_cmds * __xdata cs; void (*__xdata func)(void); - lex_echo = 1; for (;;) { readline(); #if HAS_CMD_FILTER diff --git a/src/ao_stdio.c b/src/ao_stdio.c index 3dd457f7..ec3b6607 100644 --- a/src/ao_stdio.c +++ b/src/ao_stdio.c @@ -23,7 +23,7 @@ #define AO_NUM_STDIOS (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN) -static __xdata struct ao_stdio stdios[AO_NUM_STDIOS]; +__xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS]; __data int8_t ao_cur_stdio; __data int8_t ao_num_stdios; @@ -31,15 +31,15 @@ void putchar(char c) { if (c == '\n') - (*stdios[ao_cur_stdio].putchar)('\r'); - (*stdios[ao_cur_stdio].putchar)(c); + (*ao_stdios[ao_cur_stdio].putchar)('\r'); + (*ao_stdios[ao_cur_stdio].putchar)(c); } void flush(void) { - if (stdios[ao_cur_stdio].flush) - stdios[ao_cur_stdio].flush(); + if (ao_stdios[ao_cur_stdio].flush) + ao_stdios[ao_cur_stdio].flush(); } __xdata uint8_t ao_stdin_ready; @@ -51,7 +51,7 @@ getchar(void) __reentrant __critical int8_t stdio = ao_cur_stdio; for (;;) { - c = stdios[stdio].pollchar(); + c = ao_stdios[stdio].pollchar(); if (c != AO_READ_AGAIN) break; if (++stdio == ao_num_stdios) @@ -63,6 +63,12 @@ getchar(void) __reentrant __critical return c; } +uint8_t +ao_echo(void) +{ + return ao_stdios[ao_cur_stdio].echo; +} + void ao_add_stdio(char (*pollchar)(void), void (*putchar)(char), @@ -70,8 +76,9 @@ ao_add_stdio(char (*pollchar)(void), { if (ao_num_stdios == AO_NUM_STDIOS) ao_panic(AO_PANIC_STDIO); - stdios[ao_num_stdios].pollchar = pollchar; - stdios[ao_num_stdios].putchar = putchar; - stdios[ao_num_stdios].flush = flush; + ao_stdios[ao_num_stdios].pollchar = pollchar; + ao_stdios[ao_num_stdios].putchar = putchar; + ao_stdios[ao_num_stdios].flush = flush; + ao_stdios[ao_num_stdios].echo = 1; ao_num_stdios++; }