3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 void (*sconsole_putc) (char) = 0;
30 void (*sconsole_puts) (const char *) = 0;
31 int (*sconsole_getc) (void) = 0;
32 int (*sconsole_tstc) (void) = 0;
33 void (*sconsole_setbrg) (void) = 0;
35 int serial_init (void)
37 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
41 sb->max_size = CFG_SCONSOLE_SIZE - sizeof (sconsole_buffer_t);
46 void serial_putc (char c)
51 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
54 sb->data[sb->pos++] = c;
55 if (sb->pos == sb->max_size) {
58 if (sb->size < sb->max_size) {
65 void serial_puts (const char *s)
70 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
73 sb->data[sb->pos++] = *s++;
74 if (sb->pos == sb->max_size) {
77 if (sb->size < sb->max_size) {
84 int serial_getc (void)
87 return (*sconsole_getc) ();
93 int serial_tstc (void)
96 return (*sconsole_tstc) ();
102 void serial_setbrg (void)
104 if (sconsole_setbrg) {
105 (*sconsole_setbrg) ();
109 void sconsole_flush (void)
112 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
113 unsigned int end = sb->pos < sb->size
114 ? sb->pos + sb->max_size - sb->size
115 : sb->pos - sb->size;
118 (*sconsole_putc) (sb->data[end++]);
119 if (end == sb->max_size) {