diff options
author | Keith Packard <keithp@keithp.com> | 2009-11-01 20:57:03 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2009-11-01 20:57:03 -0800 |
commit | ca5d323a3d206050d95f52a61e92c69e1f54e7b5 (patch) | |
tree | ee9bb6903039953d6f0d1a70a6d53bbdbac9ab58 /src/ao_stdio.c | |
parent | 6c1a9ce16b966a21c885bf3be31cbcb85368b3fa (diff) |
Enable packet-based communcation to command processor
This splits the packet code into master/slave halves and hooks the
slave side up to the getchar/putchar/flush logic in ao_stdio.c
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/ao_stdio.c')
-rw-r--r-- | src/ao_stdio.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/ao_stdio.c b/src/ao_stdio.c index fb8ce093..7bc416e1 100644 --- a/src/ao_stdio.c +++ b/src/ao_stdio.c @@ -21,22 +21,56 @@ * Basic I/O functions to support SDCC stdio package */ +#define AO_NUM_STDIOS 2 + +static __xdata struct ao_stdio stdios[AO_NUM_STDIOS]; +static __data int8_t ao_cur_stdio; +static __data int8_t ao_num_stdios; + void putchar(char c) { if (c == '\n') - ao_usb_putchar('\r'); - ao_usb_putchar(c); + (*stdios[ao_cur_stdio].putchar)('\r'); + (*stdios[ao_cur_stdio].putchar)(c); } void flush(void) { - ao_usb_flush(); + stdios[ao_cur_stdio].flush(); } +__xdata uint8_t ao_stdin_ready; + char -getchar(void) +getchar(void) __reentrant +{ + char c; + int8_t stdio = ao_cur_stdio; + + for (;;) { + c = stdios[stdio].pollchar(); + if (c != AO_READ_AGAIN) + break; + if (++stdio == ao_num_stdios) + stdio = 0; + if (stdio == ao_cur_stdio) + ao_sleep(&ao_stdin_ready); + } + ao_cur_stdio = stdio; + return c; +} + +void +ao_add_stdio(char (*pollchar)(void), + void (*putchar)(char), + void (*flush)(void)) { - return ao_usb_getchar(); + 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_num_stdios++; } |