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 // This code is distributed under the GNU Public License 00014 // which can be found at http://www.gnu.org/licenses/gpl.txt 00015 // 00016 //***************************************************************************** 00017 00018 #ifndef BUFFER_H 00019 #define BUFFER_H 00020 00021 // structure/typdefs 00022 00023 // the cBuffer structure 00024 typedef struct struct_cBuffer 00025 { 00026 unsigned char *dataptr; // the physical memory address where the buffer is stored 00027 unsigned short size; // the allocated size of the buffer 00028 unsigned short datalength; // the length of the data currently in the buffer 00029 unsigned short dataindex; // the index into the buffer where the data starts 00030 } cBuffer; 00031 00032 // function prototypes 00033 00034 //! initialize a buffer to start at a given address and have given size 00035 void bufferInit(cBuffer* buffer, unsigned char *start, unsigned short size); 00036 00037 //! get the first byte from the front of the buffer 00038 unsigned char bufferGetFromFront(cBuffer* buffer); 00039 00040 //! dump (discard) the first numbytes from the front of the buffer 00041 void bufferDumpFromFront(cBuffer* buffer, unsigned short numbytes); 00042 00043 //! get a byte at the specified index in the buffer (kind of like array access) 00044 // ** note: this does not remove the byte that was read from the buffer 00045 unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index); 00046 00047 //! add a byte to the end of the buffer 00048 unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data); 00049 00050 //! check if the buffer is full/not full (returns non-zero value if not full) 00051 unsigned char bufferIsNotFull(cBuffer* buffer); 00052 00053 //! flush (clear) the contents of the buffer 00054 void bufferFlush(cBuffer* buffer); 00055 00056 #endif