00001 00002 //***************************************************************************** 00003 // 00004 // File Name : 'bitbuf.c' 00005 // Title : Multipurpose bit buffer structure and methods 00006 // Author : Pascal Stang - Copyright (C) 2001-2002 00007 // Created : 7/10/2002 00008 // Revised : 7/10/2002 00009 // Version : 0.5 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 BITBUF_H 00019 #define BITBUF_H 00020 00021 // structure/typdefs 00022 00023 // the BitBuffer structure 00024 typedef struct struct_BitBuf 00025 { 00026 unsigned char *dataptr; // the physical memory address where the buffer is stored 00027 unsigned short size; // the allocated byte size of the buffer 00028 unsigned short bytePos; // current byte position 00029 unsigned short bitPos; // current bit position 00030 unsigned short datalength; // the length of the data (in bits) currently in the buffer 00031 unsigned short dataindex; // the index (in bits) into the buffer where the data starts 00032 } BitBuf; 00033 00034 // function prototypes 00035 00036 // initialize a buffer to start at a given address and have given size 00037 void bitbufInit(BitBuf* bitBuffer, unsigned char *start, unsigned short bytesize); 00038 00039 // get the bit at the current position in the buffer 00040 unsigned char bitbufGet(BitBuf* bitBuffer); 00041 00042 // get a bit at the specified index in the buffer (kind of like array access) 00043 // ** note: this does not remove/delete the bit that was read 00044 unsigned char bitbufGetAtIndex(BitBuf* bitBuffer, unsigned short bitIndex); 00045 00046 // store a bit at the current position in the buffer 00047 void bitbufStore(BitBuf* bitBuffer, unsigned char bit); 00048 00049 // return the number of bits in the buffer 00050 unsigned short bitbufGetDataLength(BitBuf* bitBuffer); 00051 00052 // check if the buffer is full/not full (returns non-zero value if not full) 00053 //unsigned char bitbufIsNotFull(cBuffer* buffer); 00054 00055 // resets the read/write position of the buffer to beginning 00056 void bitbufReset(BitBuf* bitBuffer); 00057 00058 // flush (clear) the contents of the buffer 00059 void bitbufFlush(BitBuf* bitBuffer); 00060 00061 #endif 00062