Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file bitbuf.h \brief Multipurpose bit buffer structure and methods. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'bitbuf.c' |
||
5 | // Title : Multipurpose bit buffer structure and methods |
||
6 | // Author : Pascal Stang - Copyright (C) 2001-2002 |
||
7 | // Created : 7/10/2002 |
||
8 | // Revised : 7/10/2002 |
||
9 | // Version : 0.5 |
||
10 | // Target MCU : any |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | /// \ingroup general |
||
14 | /// \defgroup bitbuf Generic Bit-Buffer Structure and Function Library (bitbuf.c) |
||
15 | /// \code #include "bitbuf.h" \endcode |
||
16 | /// \par Overview |
||
17 | /// This bit-buffer structure provides an easy and efficient way to store and |
||
18 | /// process bits. You can create as many bit buffers as you like (within |
||
19 | /// memory limits), and then use this common set of functions to access each |
||
20 | /// buffer. Supported functions include sequential getting and storing of |
||
21 | /// bits, array-like get, buffer flush (dump data), and reset-to-beginning. |
||
22 | /// This buffer is not dynamically allocated, it has a user-defined fixed |
||
23 | /// maximum size. |
||
24 | /// |
||
25 | // This code is distributed under the GNU Public License |
||
26 | // which can be found at http://www.gnu.org/licenses/gpl.txt |
||
27 | // |
||
28 | //***************************************************************************** |
||
29 | //@{ |
||
30 | |||
31 | #ifndef BITBUF_H |
||
32 | #define BITBUF_H |
||
33 | |||
34 | // structure/typdefs |
||
35 | |||
36 | // the BitBuffer structure |
||
37 | typedef struct struct_BitBuf |
||
38 | { |
||
39 | unsigned char *dataptr; // the physical memory address where the buffer is stored |
||
40 | unsigned short size; // the allocated byte size of the buffer |
||
41 | unsigned short bytePos; // current byte position |
||
42 | unsigned short bitPos; // current bit position |
||
43 | unsigned short datalength; // the length of the data (in bits) currently in the buffer |
||
44 | unsigned short dataindex; // the index (in bits) into the buffer where the data starts |
||
45 | } BitBuf; |
||
46 | |||
47 | // function prototypes |
||
48 | |||
49 | //! initialize a buffer to start at a given address and have given size |
||
50 | void bitbufInit(BitBuf* bitBuffer, unsigned char *start, unsigned short bytesize); |
||
51 | |||
52 | //! get the bit at the current position in the buffer |
||
53 | unsigned char bitbufGet(BitBuf* bitBuffer); |
||
54 | |||
55 | //! get a bit at the specified index in the buffer (kind of like array access) |
||
56 | // ** note: this does not remove/delete the bit that was read |
||
57 | unsigned char bitbufGetAtIndex(BitBuf* bitBuffer, unsigned short bitIndex); |
||
58 | |||
59 | //! store a bit at the current position in the buffer |
||
60 | void bitbufStore(BitBuf* bitBuffer, unsigned char bit); |
||
61 | |||
62 | //! return the number of bits in the buffer |
||
63 | unsigned short bitbufGetDataLength(BitBuf* bitBuffer); |
||
64 | |||
65 | // check if the buffer is full/not full (returns non-zero value if not full) |
||
66 | //unsigned char bitbufIsNotFull(cBuffer* buffer); |
||
67 | |||
68 | //! resets the read/write position of the buffer to beginning |
||
69 | void bitbufReset(BitBuf* bitBuffer); |
||
70 | |||
71 | //! flush (clear) the contents of the buffer |
||
72 | void bitbufFlush(BitBuf* bitBuffer); |
||
73 | |||
74 | #endif |
||
75 | //@} |
Powered by WebSVN v2.8.3