diff options
author | Peter Tyser <ptyser@xes-inc.com> | 2009-11-09 15:17:50 -0600 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2009-12-02 23:19:32 +0100 |
commit | 9ef78511cda39987e5fc10febf386fd19f58ecf7 (patch) | |
tree | 138195677feb52131cf7f4074739901a7be101cf /common | |
parent | 604f7ce55ad74694ef8743ad2e99933dc0265e46 (diff) | |
download | u-boot-imx-9ef78511cda39987e5fc10febf386fd19f58ecf7.zip u-boot-imx-9ef78511cda39987e5fc10febf386fd19f58ecf7.tar.gz u-boot-imx-9ef78511cda39987e5fc10febf386fd19f58ecf7.tar.bz2 |
circbuf: Move to lib_generic and conditionally compile
circbuf could be used as a generic library and is only currently
needed when CONFIG_USB_TTY is defined.
Signed-off-by: Peter Tyser <ptyser@xes-inc.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/Makefile | 1 | ||||
-rw-r--r-- | common/circbuf.c | 110 |
2 files changed, 0 insertions, 111 deletions
diff --git a/common/Makefile b/common/Makefile index 3781738..47f6a71 100644 --- a/common/Makefile +++ b/common/Makefile @@ -29,7 +29,6 @@ AOBJS = # core COBJS-y += main.o -COBJS-y += circbuf.o COBJS-y += console.o COBJS-y += command.o COBJS-y += dlmalloc.o diff --git a/common/circbuf.c b/common/circbuf.c deleted file mode 100644 index 2332c63..0000000 --- a/common/circbuf.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * (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; -} |