2 * Copyright © 2009 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 * Basic I/O functions to support SDCC stdio package
24 #define AO_NUM_STDIOS (HAS_USB + PACKET_HAS_SLAVE + USE_SERIAL_STDIN)
26 __xdata struct ao_stdio ao_stdios[AO_NUM_STDIOS];
27 __pdata int8_t ao_cur_stdio;
28 __pdata int8_t ao_num_stdios;
35 extern void ao_debug_out(char c);
43 (*ao_stdios[ao_cur_stdio].putchar)('\r');
44 (*ao_stdios[ao_cur_stdio].putchar)(c);
50 if (ao_stdios[ao_cur_stdio].flush)
51 ao_stdios[ao_cur_stdio].flush();
54 __xdata uint8_t ao_stdin_ready;
57 getchar(void) __reentrant __critical
60 int8_t stdio = ao_cur_stdio;
63 c = ao_stdios[stdio].pollchar();
64 if (c != AO_READ_AGAIN)
66 if (++stdio == ao_num_stdios)
68 if (stdio == ao_cur_stdio)
69 ao_sleep(&ao_stdin_ready);
78 return ao_stdios[ao_cur_stdio].echo;
82 ao_add_stdio(char (*pollchar)(void),
83 void (*putchar)(char),
84 void (*flush)(void)) __reentrant
86 if (ao_num_stdios == AO_NUM_STDIOS)
87 ao_panic(AO_PANIC_STDIO);
88 ao_stdios[ao_num_stdios].pollchar = pollchar;
89 ao_stdios[ao_num_stdios].putchar = putchar;
90 ao_stdios[ao_num_stdios].flush = flush;
91 ao_stdios[ao_num_stdios].echo = 1;
92 return ao_num_stdios++;