00001 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 : 9/23/2001 00009 // Version : 1.0 00010 // Target MCU : any 00011 // Editor Tabs : 3 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 // get a byte at the specified index in the buffer (kind of like array access) 00041 // ** note: this does not remove the byte that was read 00042 unsigned char bufferGetAtIndex(cBuffer* buffer, unsigned short index); 00043 00044 // add a byte to the end of the buffer 00045 unsigned char bufferAddToEnd(cBuffer* buffer, unsigned char data); 00046 00047 // check if the buffer is full/not full (returns non-zero value if not full) 00048 unsigned char bufferIsNotFull(cBuffer* buffer); 00049 00050 // flush (clear) the contents of the buffer 00051 void bufferFlush(cBuffer* buffer); 00052 00053 #endif