00001 /*! \file buffer.h \brief Multipurpose byte buffer structure and methods. */ 00002 //***************************************************************************** 00003 // 00004 // File Name : 'buffer.h' 00005 // Title : Multipurpose byte buffer structure and methods 00006 // Author : Pascal Stang - Copyright (C) 2001-2002 00007 // Created : 9/23/2001 00008 // Revised : 11/16/2002 00009 // Version : 1.1 00010 // Target MCU : any 00011 // Editor Tabs : 4 00012 // 00013 /// \ingroup general 00014 /// \defgroup buffer Circular Byte-Buffer Structure and Function Library (buffer.c) 00015 /// \code #include "buffer.h" \endcode 00016 /// \par Overview 00017 /// This byte-buffer structure provides an easy and efficient way to store 00018 /// and process a stream of bytes. You can create as many buffers as you 00019 /// like (within memory limits), and then use this common set of functions to 00020 /// access each buffer. The buffers are designed for FIFO operation (first 00021 /// in, first out). This means that the first byte you put in the buffer 00022 /// will be the first one you get when you read out the buffer. Supported 00023 /// functions include buffer initialize, get byte from front of buffer, add 00024 /// byte to end of buffer, check if buffer is full, and flush buffer. The 00025 /// buffer uses a circular design so no copying of data is ever necessary. 00026 /// This buffer is not dynamically allocated, it has a user-defined fixed 00027 /// maximum size. This buffer is used in many places in the avrlib code. 00028 // 00029 // This code is distributed under the GNU Public License 00030 // which can be found at http://www.gnu.org/licenses/gpl.txt 00031 // 00032 //***************************************************************************** 00033 //@{ 00034 00035 #ifndef BUFFER_H 00036 #define BUFFER_H 00037 00038 // structure/typdefs 00039 00040 //! cBuffer structure 00041 typedef struct struct_cBuffer 00042 { 00043 unsigned char *dataptr; ///< the physical memory address where the buffer is stored 00044 unsigned short size; ///< the allocated size of the buffer 00045 unsigned short datalength; ///< the length of the data currently in the buffer 00046 unsigned short dataindex; ///< the index into the buffer where the data starts 00047 } cBuffer; 00048 00049 // function prototypes 00050 00051 //! initialize a buffer to start at a given address and have given size 00052 void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size); 00053 00054 //! get the first byte from the front of the buffer 00055 unsigned char bufferGetFromFront(cBuffer* buffer); 00056 00057 //! dump (discard) the first numbytes from the front of the buffer 00058 void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes); 00059 00060 //! get a byte at the specified index in the buffer (kind of like array access) 00061 // ** note: this does not remove the byte that was read from the buffer 00062 unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index); 00063 00064 //! add a byte to the end of the buffer 00065 unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data); 00066 00067 //! check if the buffer is full/not full (returns zero value if full) 00068 unsigned short bufferIsNotFull(cBuffer* buffer); 00069 00070 //! flush (clear) the contents of the buffer 00071 void bufferFlush(cBuffer* buffer); 00072 00073 #endif 00074 //@}