⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffer_8c-source.html

📁 国外牛人公开的AVR代码
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Procyon AVRlib: buffer.c Source File</title><link href="dox.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><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><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>00002 <span class="comment">//*****************************************************************************</span>00003 <span class="comment">//</span>00004 <span class="comment">// File Name    : 'buffer.c'</span>00005 <span class="comment">// Title        : Multipurpose byte buffer structure and methods</span>00006 <span class="comment">// Author       : Pascal Stang - Copyright (C) 2001-2002</span>00007 <span class="comment">// Created      : 9/23/2001</span>00008 <span class="comment">// Revised      : 9/23/2001</span>00009 <span class="comment">// Version      : 1.0</span>00010 <span class="comment">// Target MCU   : any</span>00011 <span class="comment">// Editor Tabs  : 4</span>00012 <span class="comment">//</span>00013 <span class="comment">// This code is distributed under the GNU Public License</span>00014 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>00015 <span class="comment">//</span>00016 <span class="comment">//*****************************************************************************</span>00017 00018 <span class="preprocessor">#include "<a class="code" href="buffer_8h.html">buffer.h</a>"</span>00019 00020 <span class="comment">// global variables</span>00021 00022 <span class="comment">// initialization</span>00023 <a name="l00024"></a><a class="code" href="group__buffer.html#ga1">00024</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)00025 {00026     <span class="comment">// set start pointer of the buffer</span>00027     buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o0">dataptr</a> = start;00028     buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a> = size;00029     <span class="comment">// initialize index and length</span>00030     buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> = 0;00031     buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;00032 }00033 00034 <span class="comment">// access routines</span><a name="l00035"></a><a class="code" href="group__buffer.html#ga2">00035</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)00036 {00037     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data = 0;00038     00039     <span class="comment">// check to see if there's data in the buffer</span>00040     <span class="keywordflow">if</span>(buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)00041     {00042         <span class="comment">// get the first character from buffer</span>00043         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>];00044         <span class="comment">// move index down and decrement length</span>00045         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a>++;00046         <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>)00047         {00048             buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> %= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>;00049         }00050         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>--;00051     }00052     <span class="comment">// return</span>00053     <span class="keywordflow">return</span> data;00054 }00055 <a name="l00056"></a><a class="code" href="group__buffer.html#ga3">00056</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)00057 {00058     <span class="comment">// dump numbytes from the front of the buffer</span>00059     <span class="comment">// are we dumping less than the entire buffer?</span>00060     <span class="keywordflow">if</span>(numbytes &lt; buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>)00061     {00062         <span class="comment">// move index down by numbytes and decrement length by numbytes</span>00063         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> += numbytes;00064         <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>)00065         {00066             buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o3">dataindex</a> %= buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o1">size</a>;00067         }00068         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> -= numbytes;00069     }00070     <span class="keywordflow">else</span>00071     {00072         <span class="comment">// flush the whole buffer</span>00073         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;00074     }00075 }00076 <a name="l00077"></a><a class="code" href="group__buffer.html#ga4">00077</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)00078 {00079     <span class="comment">// return character at index in buffer</span>00080     <span class="keywordflow">return</span> 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>)];00081 }00082 <a name="l00083"></a><a class="code" href="group__buffer.html#ga5">00083</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)00084 {00085     <span class="comment">// make sure the buffer has room</span>00086     <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>)00087     {00088         <span class="comment">// save data byte at end of buffer</span>00089         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;00090         <span class="comment">// increment the length</span>00091         buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a>++;00092         <span class="comment">// return success</span>00093         <span class="keywordflow">return</span> -1;00094     }00095     <span class="keywordflow">else</span> <span class="keywordflow">return</span> 0;00096 }00097 <a name="l00098"></a><a class="code" href="group__buffer.html#ga6">00098</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="group__buffer.html#ga6">bufferIsNotFull</a>(<a class="code" href="structstruct__cBuffer.html">cBuffer</a>* buffer)00099 {00100     <span class="comment">// check to see if the buffer has room</span>00101     <span class="comment">// return true if there is room</span>00102     <span class="keywordflow">return</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>);00103 }00104 <a name="l00105"></a><a class="code" href="group__buffer.html#ga7">00105</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)00106 {00107     <span class="comment">// flush contents of the buffer</span>00108     buffer-&gt;<a class="code" href="structstruct__cBuffer.html#o2">datalength</a> = 0;00109 }00110 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 24 16:03:54 2005 for Procyon AVRlib by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -