summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/Makefile8
-rw-r--r--common/circbuf.c110
-rw-r--r--common/cmd_load.c42
-rw-r--r--common/devices.c3
4 files changed, 138 insertions, 25 deletions
diff --git a/common/Makefile b/common/Makefile
index eccb4e46f0..4c94fc03a1 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -1,5 +1,5 @@
#
-# (C) Copyright 2000, 2001
+# (C) Copyright 2004
# Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#
# See file CREDITS for list of people who contributed to this
@@ -12,7 +12,7 @@
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
@@ -47,7 +47,7 @@ COBJS = main.o ACEX1K.o altera.o bedbug.o \
hush.o kgdb.o lists.o lynxkdi.o memsize.o miiphybb.o miiphyutil.o \
s_record.o soft_i2c.o soft_spi.o spartan2.o \
usb.o usb_kbd.o usb_storage.o \
- virtex2.o xilinx.o
+ virtex2.o xilinx.o circbuf.o
OBJS = $(AOBJS) $(COBJS)
@@ -55,7 +55,7 @@ CPPFLAGS += -I..
all: $(LIB) $(AOBJS)
-$(LIB): .depend $(OBJS)
+$(LIB): .depend $(OBJS)
$(AR) crv $@ $(OBJS)
environment.o: environment.c ../tools/envcrc
diff --git a/common/circbuf.c b/common/circbuf.c
new file mode 100644
index 0000000000..2332c63717
--- /dev/null
+++ b/common/circbuf.c
@@ -0,0 +1,110 @@
+/*
+ * (C) Copyright 2003
+ * Gerry Hamel, geh@ti.com, Texas Instruments
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include <common.h>
+#include <malloc.h>
+
+#include <circbuf.h>
+
+
+int buf_init (circbuf_t * buf, unsigned int size)
+{
+ assert (buf != NULL);
+
+ buf->size = 0;
+ buf->totalsize = size;
+ buf->data = (char *) malloc (sizeof (char) * size);
+ assert (buf->data != NULL);
+
+ buf->top = buf->data;
+ buf->tail = buf->data;
+ buf->end = &(buf->data[size]);
+
+ return 1;
+}
+
+int buf_free (circbuf_t * buf)
+{
+ assert (buf != NULL);
+ assert (buf->data != NULL);
+
+ free (buf->data);
+ memset (buf, 0, sizeof (circbuf_t));
+
+ return 1;
+}
+
+int buf_pop (circbuf_t * buf, char *dest, unsigned int len)
+{
+ unsigned int i;
+ char *p = buf->top;
+
+ assert (buf != NULL);
+ assert (dest != NULL);
+
+ /* Cap to number of bytes in buffer */
+ if (len > buf->size)
+ len = buf->size;
+
+ for (i = 0; i < len; i++) {
+ dest[i] = *p++;
+ /* Bounds check. */
+ if (p == buf->end) {
+ p = buf->data;
+ }
+ }
+
+ /* Update 'top' pointer */
+ buf->top = p;
+ buf->size -= len;
+
+ return len;
+}
+
+int buf_push (circbuf_t * buf, const char *src, unsigned int len)
+{
+ /* NOTE: this function allows push to overwrite old data. */
+ unsigned int i;
+ char *p = buf->tail;
+
+ assert (buf != NULL);
+ assert (src != NULL);
+
+ for (i = 0; i < len; i++) {
+ *p++ = src[i];
+ if (p == buf->end) {
+ p = buf->data;
+ }
+ /* Make sure pushing too much data just replaces old data */
+ if (buf->size < buf->totalsize) {
+ buf->size++;
+ } else {
+ buf->top++;
+ if (buf->top == buf->end) {
+ buf->top = buf->data;
+ }
+ }
+ }
+
+ /* Update 'tail' pointer */
+ buf->tail = p;
+
+ return len;
+}
diff --git a/common/cmd_load.c b/common/cmd_load.c
index 702cab6dc6..b85db69e13 100644
--- a/common/cmd_load.c
+++ b/common/cmd_load.c
@@ -1,5 +1,5 @@
/*
- * (C) Copyright 2000-2003
+ * (C) Copyright 2000-2004
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
* See file CREDITS for list of people who contributed to this
@@ -104,8 +104,8 @@ int do_load_serial (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
* box some time (100 * 1 ms)
*/
for (i=0; i<100; ++i) {
- if (serial_tstc()) {
- (void) serial_getc();
+ if (tstc()) {
+ (void) getc();
}
udelay(1000);
}
@@ -220,9 +220,9 @@ read_record (char *buf, ulong len)
--len; /* always leave room for terminating '\0' byte */
for (p=buf; p < buf+len; ++p) {
- c = serial_getc(); /* read character */
+ c = getc(); /* read character */
if (do_echo)
- serial_putc (c); /* ... and echo it */
+ putc (c); /* ... and echo it */
switch (c) {
case '\r':
@@ -237,7 +237,7 @@ read_record (char *buf, ulong len)
}
/* Check for the console hangup (if any different from serial) */
- if (gd->jt[XF_getc] != serial_getc) {
+ if (gd->jt[XF_getc] != getc) {
if (ctrlc()) {
return (-1);
}
@@ -387,7 +387,7 @@ write_record (char *buf)
char c;
while((c = *buf++))
- serial_putc(c);
+ putc(c);
/* Check for the console hangup (if any different from serial) */
@@ -531,8 +531,8 @@ static ulong load_serial_bin (ulong offset)
* box some time (100 * 1 ms)
*/
for (i=0; i<100; ++i) {
- if (serial_tstc()) {
- (void) serial_getc();
+ if (tstc()) {
+ (void) getc();
}
udelay(1000);
}
@@ -551,7 +551,7 @@ void send_pad (void)
int count = his_pad_count;
while (count-- > 0)
- serial_putc (his_pad_char);
+ putc (his_pad_char);
}
/* converts escaped kermit char to binary char */
@@ -579,7 +579,7 @@ void s1_sendpacket (char *packet)
{
send_pad ();
while (*packet) {
- serial_putc (*packet++);
+ putc (*packet++);
}
}
@@ -841,7 +841,7 @@ static int k_recv (void)
/* get a packet */
/* wait for the starting character or ^C */
for (;;) {
- switch (serial_getc ()) {
+ switch (getc ()) {
case START_CHAR: /* start packet */
goto START;
case ETX_CHAR: /* ^C waiting for packet */
@@ -853,13 +853,13 @@ static int k_recv (void)
START:
/* get length of packet */
sum = 0;
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
length = untochar (new_char);
/* get sequence number */
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -886,7 +886,7 @@ START:
/* END NEW CODE */
/* get packet type */
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -896,19 +896,19 @@ START:
if (length == -2) {
/* (length byte was 0, decremented twice) */
/* get the two length bytes */
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_hi = untochar (new_char);
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
len_lo = untochar (new_char);
length = len_hi * 95 + len_lo;
/* check header checksum */
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
@@ -918,7 +918,7 @@ START:
}
/* bring in rest of packet */
while (length > 1) {
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
sum += new_char & 0xff;
@@ -935,13 +935,13 @@ START:
}
}
/* get and validate checksum character */
- new_char = serial_getc ();
+ new_char = getc ();
if ((new_char & 0xE0) == 0)
goto packet_error;
if (new_char != tochar ((sum + ((sum >> 6) & 0x03)) & 0x3f))
goto packet_error;
/* get END_CHAR */
- new_char = serial_getc ();
+ new_char = getc ();
if (new_char != END_CHAR) {
packet_error:
/* restore state machines */
diff --git a/common/devices.c b/common/devices.c
index bf7486ac44..aa055339e8 100644
--- a/common/devices.c
+++ b/common/devices.c
@@ -194,6 +194,9 @@ int devices_init (void)
drv_logbuff_init ();
#endif
drv_system_init ();
+#ifdef CONFIG_USB_TTY
+ drv_usbtty_init ();
+#endif
return (0);
}