Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# bitbuf.h

Go to the documentation of this file.

    00001 /*! \file bitbuf.h \brief Multipurpose bit buffer structure and methods. */
    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  : 4
    00012 //
    00013 /// \ingroup general
    00014 /// \defgroup bitbuf Generic Bit-Buffer Structure and Function Library (bitbuf.c)
    00015 /// \code #include "bitbuf.h" \endcode
    00016 /// \par Overview
    00017 ///     This bit-buffer structure provides an easy and efficient way to store and
    00018 ///     process bits. You can create as many bit buffers as you like (within
    00019 ///     memory limits), and then use this common set of functions to access each
    00020 ///     buffer. Supported functions include sequential getting and storing of
    00021 ///     bits, array-like get, buffer flush (dump data), and reset-to-beginning.
    00022 ///     This buffer is not dynamically allocated, it has a user-defined fixed
    00023 ///     maximum size.
    00024 ///
    00025 // This code is distributed under the GNU Public License
    00026 //      which can be found at http://www.gnu.org/licenses/gpl.txt
    00027 //
    00028 //*****************************************************************************
    00029 //@{
    00030
    00031 #ifndef BITBUF_H
    00032 #define BITBUF_H
    00033
    00034 // structure/typdefs
    00035
    00036 // the BitBuffer structure
    00037 typedef struct struct_BitBuf
    00038 {
    00039     unsigned char *dataptr;         // the physical memory address where the buffer is stored
    00040     unsigned short  size;           // the allocated byte size of the buffer
    00041     unsigned short bytePos;         // current byte position
    00042     unsigned short bitPos;          // current bit position
    00043     unsigned short datalength;      // the length of the data (in bits) currently in the buffer
    00044     unsigned short dataindex;       // the index (in bits) into the buffer where the data starts
    00045 } BitBuf;
    00046
    00047 // function prototypes
    00048
    00049 //! initialize a buffer to start at a given address and have given size
    00050 void bitbufInit(BitBuf* bitBuffer, unsigned char *start, unsigned short bytesize);
    00051
    00052 //! get the bit at the current position in the buffer
    00053 unsigned char bitbufGet(BitBuf* bitBuffer);
    00054
    00055 //! get a bit at the specified index in the buffer (kind of like array access)
    00056 // ** note: this does not remove/delete the bit that was read
    00057 unsigned char bitbufGetAtIndex(BitBuf* bitBuffer, unsigned short bitIndex);
    00058
    00059 //! store a bit at the current position in the buffer
    00060 void bitbufStore(BitBuf* bitBuffer, unsigned char bit);
    00061
    00062 //! return the number of bits in the buffer
    00063 unsigned short bitbufGetDataLength(BitBuf* bitBuffer);
    00064
    00065 // check if the buffer is full/not full (returns non-zero value if not full)
    00066 //unsigned char  bitbufIsNotFull(cBuffer* buffer);
    00067
    00068 //! resets the read/write position of the buffer to beginning
    00069 void bitbufReset(BitBuf* bitBuffer);
    00070
    00071 //! flush (clear) the contents of the buffer
    00072 void bitbufFlush(BitBuf* bitBuffer);
    00073
    00074 #endif
    00075 //@}