| Line No. | Rev | Author | Line | 
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | 
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> | ||
| 3 | <title>Procyon AVRlib: bitbuf.c Source File</title> | ||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> | ||
| 5 | </head><body> | ||
| 6 | <!-- Generated by Doxygen 1.4.2 --> | ||
| 7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> | ||
| 8 | <h1>bitbuf.c</h1><a href="bitbuf_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file bitbuf.c \brief Multipurpose bit buffer structure and methods. */</span> | ||
| 9 | 00002 <span class="comment">//*****************************************************************************</span> | ||
| 10 | 00003 <span class="comment">//</span> | ||
| 11 | 00004 <span class="comment">// File Name    : 'bitbuf.c'</span> | ||
| 12 | 00005 <span class="comment">// Title        : Multipurpose bit buffer structure and methods</span> | ||
| 13 | 00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2001-2002</span> | ||
| 14 | 00007 <span class="comment">// Created      : 7/10/2002</span> | ||
| 15 | 00008 <span class="comment">// Revised      : 7/10/2002</span> | ||
| 16 | 00009 <span class="comment">// Version      : 0.5</span> | ||
| 17 | 00010 <span class="comment">// Target MCU   : any</span> | ||
| 18 | 00011 <span class="comment">// Editor Tabs  : 4</span> | ||
| 19 | 00012 <span class="comment">//</span> | ||
| 20 | 00013 <span class="comment">// This code is distributed under the GNU Public License</span> | ||
| 21 | 00014 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span> | ||
| 22 | 00015 <span class="comment">//</span> | ||
| 23 | 00016 <span class="comment">//*****************************************************************************</span> | ||
| 24 | 00017  | ||
| 25 | 00018 <span class="preprocessor">#include "<a class="code" href="bitbuf_8h.html">bitbuf.h</a>"</span> | ||
| 26 | 00019  | ||
| 27 | 00020 <span class="comment">// global variables</span> | ||
| 28 | 00021 <span class="comment"></span> | ||
| 29 | 00022 <span class="comment">//! Initialize the bit buffer</span> | ||
| 30 | 00023 <span class="comment"></span><span class="comment">//  sets the start location and size of the buffer in memory</span> | ||
| 31 | <a name="l00024"></a><a class="code" href="group__bitbuf.html#ga1">00024</a> <span class="keywordtype">void</span> <a class="code" href="group__bitbuf.html#ga1">bitbufInit</a>(BitBuf* bitBuffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *start, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> bytesize) | ||
| 32 | 00025 { | ||
| 33 | 00026     <span class="comment">// set start pointer of the buffer</span> | ||
| 34 | 00027     bitBuffer->dataptr = start; | ||
| 35 | 00028     bitBuffer->size = bytesize; | ||
| 36 | 00029     <span class="comment">// initialize indexing and length</span> | ||
| 37 | 00030     bitBuffer->dataindex = 0; | ||
| 38 | 00031     <a class="code" href="group__bitbuf.html#ga7">bitbufFlush</a>(bitBuffer); | ||
| 39 | 00032 } | ||
| 40 | 00033  | ||
| 41 | 00034 <span class="comment">// access routines</span> | ||
| 42 | 00035 <span class="comment"></span> | ||
| 43 | 00036 <span class="comment">//! Get a bit from the current position in the buffer</span> | ||
| 44 | 00037 <span class="comment"></span><span class="comment">//  returns the bit at the current position in the buffer</span> | ||
| 45 | 00038 <span class="comment">//  and increments the bit position</span> | ||
| 46 | <a name="l00039"></a><a class="code" href="group__bitbuf.html#ga2">00039</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__bitbuf.html#ga2">bitbufGet</a>(BitBuf* bitBuffer) | ||
| 47 | 00040 { | ||
| 48 | 00041     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> byte; | ||
| 49 | 00042     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> bit; | ||
| 50 | 00043      | ||
| 51 | 00044     <span class="comment">// get current working byte</span> | ||
| 52 | 00045     byte = bitBuffer->dataptr[bitBuffer->bytePos]; | ||
| 53 | 00046     <span class="comment">// read data bit</span> | ||
| 54 | 00047     bit = (byte & (1<<bitBuffer->bitPos))?(1):(0); | ||
| 55 | 00048  | ||
| 56 | 00049     <span class="comment">// increment bit counter</span> | ||
| 57 | 00050     <span class="keywordflow">if</span>(bitBuffer->bitPos < 7) | ||
| 58 | 00051     { | ||
| 59 | 00052         bitBuffer->bitPos++; | ||
| 60 | 00053     } | ||
| 61 | 00054     <span class="keywordflow">else</span> | ||
| 62 | 00055     { | ||
| 63 | 00056         <span class="comment">// increment byte counter</span> | ||
| 64 | 00057         bitBuffer->bitPos = 0; | ||
| 65 | 00058         bitBuffer->bytePos++; | ||
| 66 | 00059     } | ||
| 67 | 00060  | ||
| 68 | 00061     <span class="comment">// return bit value</span> | ||
| 69 | 00062     <span class="keywordflow">return</span> bit; | ||
| 70 | 00063 } | ||
| 71 | 00064 <span class="comment"></span> | ||
| 72 | 00065 <span class="comment">//! Get a bit from a given index into the buffer</span> | ||
| 73 | 00066 <span class="comment"></span><span class="comment">//  returns the bit at position [bitIndex] in the buffer</span> | ||
| 74 | <a name="l00067"></a><a class="code" href="group__bitbuf.html#ga3">00067</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__bitbuf.html#ga3">bitbufGetAtIndex</a>(BitBuf* bitBuffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> bitIndex) | ||
| 75 | 00068 { | ||
| 76 | 00069     <span class="comment">// return bit at index in buffer</span> | ||
| 77 | 00070     <span class="keywordflow">return</span> (bitBuffer->dataptr[bitIndex>>3] & (1<<(bitIndex & 0x07)))?(1):(0); | ||
| 78 | 00071 } | ||
| 79 | 00072 <span class="comment"></span> | ||
| 80 | 00073 <span class="comment">//! Store a bit at the current position in the buffer</span> | ||
| 81 | 00074 <span class="comment"></span><span class="comment">//  stores the bit at the current position in the buffer</span> | ||
| 82 | 00075 <span class="comment">//  and increments the bit position</span> | ||
| 83 | <a name="l00076"></a><a class="code" href="group__bitbuf.html#ga4">00076</a> <span class="keywordtype">void</span> <a class="code" href="group__bitbuf.html#ga4">bitbufStore</a>(BitBuf* bitBuffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> bit) | ||
| 84 | 00077 { | ||
| 85 | 00078     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> byte; | ||
| 86 | 00079     <span class="comment">// get current working byte</span> | ||
| 87 | 00080     byte = bitBuffer->dataptr[bitBuffer->bytePos]; | ||
| 88 | 00081     <span class="comment">// apply data bit</span> | ||
| 89 | 00082     <span class="keywordflow">if</span>(bit) | ||
| 90 | 00083         byte |=  (1<<bitBuffer->bitPos); | ||
| 91 | 00084     <span class="keywordflow">else</span> | ||
| 92 | 00085         byte &= ~(1<<bitBuffer->bitPos); | ||
| 93 | 00086     <span class="comment">// store data</span> | ||
| 94 | 00087     bitBuffer->dataptr[bitBuffer->bytePos] = byte; | ||
| 95 | 00088     bitBuffer->datalength++; | ||
| 96 | 00089  | ||
| 97 | 00090     <span class="comment">// increment bit counter</span> | ||
| 98 | 00091     <span class="keywordflow">if</span>(bitBuffer->bitPos < 7) | ||
| 99 | 00092     { | ||
| 100 | 00093         bitBuffer->bitPos++; | ||
| 101 | 00094     } | ||
| 102 | 00095     <span class="keywordflow">else</span> | ||
| 103 | 00096     { | ||
| 104 | 00097         <span class="comment">// increment byte counter</span> | ||
| 105 | 00098         bitBuffer->bitPos = 0; | ||
| 106 | 00099         bitBuffer->bytePos++; | ||
| 107 | 00100     } | ||
| 108 | 00101 } | ||
| 109 | 00102  | ||
| 110 | <a name="l00103"></a><a class="code" href="group__bitbuf.html#ga6">00103</a> <span class="keywordtype">void</span> <a class="code" href="group__bitbuf.html#ga6">bitbufReset</a>(BitBuf* bitBuffer) | ||
| 111 | 00104 { | ||
| 112 | 00105     <span class="comment">// reset counters</span> | ||
| 113 | 00106     bitBuffer->bytePos = 0; | ||
| 114 | 00107     bitBuffer->bitPos = 0; | ||
| 115 | 00108 } | ||
| 116 | 00109  | ||
| 117 | <a name="l00110"></a><a class="code" href="group__bitbuf.html#ga7">00110</a> <span class="keywordtype">void</span> <a class="code" href="group__bitbuf.html#ga7">bitbufFlush</a>(BitBuf* bitBuffer) | ||
| 118 | 00111 { | ||
| 119 | 00112     <span class="comment">// flush contents of the buffer</span> | ||
| 120 | 00113     bitBuffer->datalength = 0; | ||
| 121 | 00114     <span class="comment">// reset indexing</span> | ||
| 122 | 00115     <a class="code" href="group__bitbuf.html#ga6">bitbufReset</a>(bitBuffer); | ||
| 123 | 00116 } | ||
| 124 | 00117  | ||
| 125 | <a name="l00118"></a><a class="code" href="group__bitbuf.html#ga5">00118</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="group__bitbuf.html#ga5">bitbufGetDataLength</a>(BitBuf* bitBuffer) | ||
| 126 | 00119 { | ||
| 127 | 00120     <span class="keywordflow">return</span> bitBuffer->datalength; | ||
| 128 | 00121 } | ||
| 129 | 00122  | ||
| 130 | 00123 <span class="comment">/*</span> | ||
| 131 | 00124 <span class="comment">unsigned char bitbufIsNotFull(cBuffer* buffer)</span> | ||
| 132 | 00125 <span class="comment">{</span> | ||
| 133 | 00126 <span class="comment">    // check to see if the buffer has room</span> | ||
| 134 | 00127 <span class="comment">    // return true if there is room</span> | ||
| 135 | 00128 <span class="comment">    return (buffer->datalength < buffer->size);</span> | ||
| 136 | 00129 <span class="comment">}</span> | ||
| 137 | 00130 <span class="comment">*/</span> | ||
| 138 | 00131  | ||
| 139 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by  | ||
| 140 | <a href="http://www.doxygen.org/index.html"> | ||
| 141 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> | ||
| 142 | </body> | ||
| 143 | </html> | 
Powered by WebSVN v2.8.3