?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

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: buffer.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&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>buffer.c</h1><a href="buffer_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file buffer.c \brief Multipurpose byte buffer structure and methods. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'buffer.c'</span>
12 00005 <span class="comment">// Title : Multipurpose byte buffer structure and methods</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2001-2002</span>
14 00007 <span class="comment">// Created : 9/23/2001</span>
15 00008 <span class="comment">// Revised : 9/23/2001</span>
16 00009 <span class="comment">// Version : 1.0</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="buffer_8h.html">buffer.h</a>"</span>
26 00019 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
27 00020 <span class="preprocessor">#include "avr/io.h"</span>
28 00021
29 00022 <span class="preprocessor">#ifndef CRITICAL_SECTION_START</span>
30 00023 <span class="preprocessor"></span><span class="preprocessor">#define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()</span>
31 00024 <span class="preprocessor"></span><span class="preprocessor">#define CRITICAL_SECTION_END SREG = _sreg</span>
32 00025 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
33 00026 <span class="preprocessor"></span>
34 00027 <span class="comment">// global variables</span>
35 00028
36 00029 <span class="comment">// initialization</span>
37 00030
38 <a name="l00031"></a><a class="code" href="group__buffer.html#ga1">00031</a> <span class="keywordtype">void</span> <a class="code" href="group__buffer.html#ga1">bufferInit</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *start, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> size)
39 00032 {
40 00033 <span class="comment">// begin critical section</span>
41 00034 CRITICAL_SECTION_START;
42 00035 <span class="comment">// set start pointer of the buffer</span>
43 00036 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o0">dataptr</a> = start;
44 00037 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a> = size;
45 00038 <span class="comment">// initialize index and length</span>
46 00039 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> = 0;
47 00040 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;
48 00041 <span class="comment">// end critical section</span>
49 00042 CRITICAL_SECTION_END;
50 00043 }
51 00044
52 00045 <span class="comment">// access routines</span>
53 <a name="l00046"></a><a class="code" href="group__buffer.html#ga2">00046</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__buffer.html#ga2">bufferGetFromFront</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer)
54 00047 {
55 00048 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data = 0;
56 00049 <span class="comment">// begin critical section</span>
57 00050 CRITICAL_SECTION_START;
58 00051 <span class="comment">// check to see if there's data in the buffer</span>
59 00052 <span class="keywordflow">if</span>(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)
60 00053 {
61 00054 <span class="comment">// get the first character from buffer</span>
62 00055 data = buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o0">dataptr</a>[buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a>];
63 00056 <span class="comment">// move index down and decrement length</span>
64 00057 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a>++;
65 00058 <span class="keywordflow">if</span>(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> &gt;= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>)
66 00059 {
67 00060 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> -= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>;
68 00061 }
69 00062 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>--;
70 00063 }
71 00064 <span class="comment">// end critical section</span>
72 00065 CRITICAL_SECTION_END;
73 00066 <span class="comment">// return</span>
74 00067 <span class="keywordflow">return</span> data;
75 00068 }
76 00069
77 <a name="l00070"></a><a class="code" href="group__buffer.html#ga3">00070</a> <span class="keywordtype">void</span> <a class="code" href="group__buffer.html#ga3">bufferDumpFromFront</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> numbytes)
78 00071 {
79 00072 <span class="comment">// begin critical section</span>
80 00073 CRITICAL_SECTION_START;
81 00074 <span class="comment">// dump numbytes from the front of the buffer</span>
82 00075 <span class="comment">// are we dumping less than the entire buffer?</span>
83 00076 <span class="keywordflow">if</span>(numbytes &lt; buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)
84 00077 {
85 00078 <span class="comment">// move index down by numbytes and decrement length by numbytes</span>
86 00079 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> += numbytes;
87 00080 <span class="keywordflow">if</span>(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> &gt;= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>)
88 00081 {
89 00082 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> -= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>;
90 00083 }
91 00084 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> -= numbytes;
92 00085 }
93 00086 <span class="keywordflow">else</span>
94 00087 {
95 00088 <span class="comment">// flush the whole buffer</span>
96 00089 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;
97 00090 }
98 00091 <span class="comment">// end critical section</span>
99 00092 CRITICAL_SECTION_END;
100 00093 }
101 00094
102 <a name="l00095"></a><a class="code" href="group__buffer.html#ga4">00095</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__buffer.html#ga4">bufferGetAtIndex</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> index)
103 00096 {
104 00097 <span class="comment">// begin critical section</span>
105 00098 CRITICAL_SECTION_START;
106 00099 <span class="comment">// return character at index in buffer</span>
107 00100 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data = buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o0">dataptr</a>[(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a>+index)%(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>)];
108 00101 <span class="comment">// end critical section</span>
109 00102 CRITICAL_SECTION_END;
110 00103 <span class="keywordflow">return</span> data;
111 00104 }
112 00105
113 <a name="l00106"></a><a class="code" href="group__buffer.html#ga5">00106</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__buffer.html#ga5">bufferAddToEnd</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data)
114 00107 {
115 00108 <span class="comment">// begin critical section</span>
116 00109 CRITICAL_SECTION_START;
117 00110 <span class="comment">// make sure the buffer has room</span>
118 00111 <span class="keywordflow">if</span>(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> &lt; buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>)
119 00112 {
120 00113 <span class="comment">// save data byte at end of buffer</span>
121 00114 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o0">dataptr</a>[(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> + buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>) % buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>] = data;
122 00115 <span class="comment">// increment the length</span>
123 00116 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>++;
124 00117 <span class="comment">// end critical section</span>
125 00118 CRITICAL_SECTION_END;
126 00119 <span class="comment">// return success</span>
127 00120 <span class="keywordflow">return</span> -1;
128 00121 }
129 00122 <span class="comment">// end critical section</span>
130 00123 CRITICAL_SECTION_END;
131 00124 <span class="comment">// return failure</span>
132 00125 <span class="keywordflow">return</span> 0;
133 00126 }
134 00127
135 <a name="l00128"></a><a class="code" href="group__buffer.html#ga6">00128</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="group__buffer.html#ga6">bufferIsNotFull</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer)
136 00129 {
137 00130 <span class="comment">// begin critical section</span>
138 00131 CRITICAL_SECTION_START;
139 00132 <span class="comment">// check to see if the buffer has room</span>
140 00133 <span class="comment">// return true if there is room</span>
141 00134 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> bytesleft = (buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a> - buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>);
142 00135 <span class="comment">// end critical section</span>
143 00136 CRITICAL_SECTION_END;
144 00137 <span class="keywordflow">return</span> bytesleft;
145 00138 }
146 00139
147 <a name="l00140"></a><a class="code" href="group__buffer.html#ga7">00140</a> <span class="keywordtype">void</span> <a class="code" href="group__buffer.html#ga7">bufferFlush</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer)
148 00141 {
149 00142 <span class="comment">// begin critical section</span>
150 00143 CRITICAL_SECTION_START;
151 00144 <span class="comment">// flush contents of the buffer</span>
152 00145 buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;
153 00146 <span class="comment">// end critical section</span>
154 00147 CRITICAL_SECTION_END;
155 00148 }
156 00149
157 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
158 <a href="http://www.doxygen.org/index.html">
159 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
160 </body>
161 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3