Change boot command to boot kernel from 0xc1028380
[u-boot-m93030.git] / board / pcippc2 / sconsole.c
blob3b190699f08557a9f79c40a658fb7969ec1b7a92
1 /*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
6 * project.
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,
21 * MA 02111-1307 USA
24 #include <config.h>
25 #include <common.h>
27 #include "sconsole.h"
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;
41 sb->pos = 0;
42 sb->size = 0;
43 sb->baud = gd->baudrate;
44 sb->max_size = CFG_SCONSOLE_SIZE - sizeof (sconsole_buffer_t);
46 return (0);
49 void serial_putc (char c)
51 if (sconsole_putc) {
52 (*sconsole_putc) (c);
53 } else {
54 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
56 if (c) {
57 sb->data[sb->pos++] = c;
58 if (sb->pos == sb->max_size) {
59 sb->pos = 0;
61 if (sb->size < sb->max_size) {
62 sb->size++;
68 void serial_puts (const char *s)
70 if (sconsole_puts) {
71 (*sconsole_puts) (s);
72 } else {
73 sconsole_buffer_t *sb = SCONSOLE_BUFFER;
75 while (*s) {
76 sb->data[sb->pos++] = *s++;
77 if (sb->pos == sb->max_size) {
78 sb->pos = 0;
80 if (sb->size < sb->max_size) {
81 sb->size++;
87 int serial_getc (void)
89 if (sconsole_getc) {
90 return (*sconsole_getc) ();
91 } else {
92 return 0;
96 int serial_tstc (void)
98 if (sconsole_tstc) {
99 return (*sconsole_tstc) ();
100 } else {
101 return 0;
105 void serial_setbrg (void)
107 if (sconsole_setbrg) {
108 (*sconsole_setbrg) ();
109 } else {
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;
120 return sb->baud;
123 void sconsole_flush (void)
125 if (sconsole_putc) {
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;
131 while (sb->size) {
132 (*sconsole_putc) (sb->data[end++]);
133 if (end == sb->max_size) {
134 end = 0;
136 sb->size--;