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 DECLARE_GLOBAL_DATA_PTR;
31 void (*sconsole_putc) (char) = 0;
32 void (*sconsole_puts) (const char *) = 0;
33 int (*sconsole_getc) (void) = 0;
34 int (*sconsole_tstc) (void) = 0;
35 void (*sconsole_setbrg) (void) = 0;
37 int serial_init (void)
39 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
43 sb->baud = gd->baudrate;
44 sb->max_size = CFG_SCONSOLE_SIZE - sizeof (sconsole_buffer_t);
49 void serial_putc (char c)
54 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
57 sb->data[sb->pos++] = c;
58 if (sb->pos == sb->max_size) {
61 if (sb->size < sb->max_size) {
68 void serial_puts (const char *s)
73 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
76 sb->data[sb->pos++] = *s++;
77 if (sb->pos == sb->max_size) {
80 if (sb->size < sb->max_size) {
87 int serial_getc (void)
90 return (*sconsole_getc) ();
96 int serial_tstc (void)
99 return (*sconsole_tstc) ();
105 void serial_setbrg (void)
107 if (sconsole_setbrg) {
108 (*sconsole_setbrg) ();
110 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
112 sb->baud = gd->baudrate;
116 int sconsole_get_baudrate (void)
118 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
123 void sconsole_flush (void)
126 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
127 unsigned int end = sb->pos < sb->size
128 ? sb->pos + sb->max_size - sb->size
129 : sb->pos - sb->size;
132 (*sconsole_putc) (sb->data[end++]);
133 if (end == sb->max_size) {