📄 timers_8c-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/timers.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><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="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> <a class="qindex" href="examples.html">Examples</a> </center><hr><h1>/opentcp/timers.c</h1><a href="timers_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> * "This product includes software developed by Viola </span>00019 <span class="comment"> * Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see <http://www.opentcp.org>.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *<http://www.violasystems.com/>.</span>00052 <span class="comment"> */</span>00053 00074 <span class="preprocessor">#include <<a class="code" href="debug_8h.html">inet/debug.h</a>></span>00075 <span class="preprocessor">#include <<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>></span>00076 <span class="preprocessor">#include <<a class="code" href="timers_8h.html">inet/timers.h</a>></span>00077 <span class="preprocessor">#include <<a class="code" href="system_8h.html">inet/system.h</a>></span>00078 00086 <span class="keyword">struct</span>00087 <span class="keyword"></span>{00088 UINT32 value;00089 UINT8 free;00090 } <a class="code" href="timers_8c.html#a2">timer_pool</a>[<a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>];00091 <a name="l00105"></a><a class="code" href="timers_8c.html#a3">00105</a> <span class="keywordtype">void</span> <a class="code" href="group__core__initializer.html#a3">timer_pool_init</a> (<span class="keywordtype">void</span>)00106 {00107 UINT8 i;00108 00109 <span class="keywordflow">for</span>( i=0; i < <a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>; i++) {00110 <a class="code" href="timers_8c.html#a2">timer_pool</a>[i].value = 0;00111 <a class="code" href="timers_8c.html#a2">timer_pool</a>[i].free = <a class="code" href="system_8h.html#a1">TRUE</a>;00112 00113 }00114 00115 00116 }00117 00118 <a name="l00131"></a><a class="code" href="timers_8c.html#a4">00131</a> UINT8 <a class="code" href="timers_8c.html#a2">get_timer</a> (<span class="keywordtype">void</span>)00132 {00133 00134 UINT8 i;00135 UINT8 first_match;00136 00137 00138 <span class="keywordflow">for</span>( i=0; i < <a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>; i++) {00139 <span class="keywordflow">if</span>( <a class="code" href="timers_8c.html#a2">timer_pool</a>[i].free == <a class="code" href="system_8h.html#a1">TRUE</a> ) {00140 <span class="comment">/* We found a free timer! */</span>00141 <span class="comment">/* Mark is reserved */</span>00142 00143 <a class="code" href="timers_8c.html#a2">timer_pool</a>[i].free = <a class="code" href="system_8h.html#a2">FALSE</a>;00144 first_match = i;00145 <span class="keywordflow">return</span> first_match; <span class="comment">/* Return Handle */</span>00146 }00147 00148 }00149 00150 <span class="comment">/* Error Check */</span>00151 00152 TMR_DEBUGOUT(<span class="stringliteral">"No Timers, Resetting..\n\r"</span>);00153 <a class="code" href="system_8h.html#a6">RESET_SYSTEM</a>();00154 00155 00156 }00157 00158 <a name="l00169"></a><a class="code" href="timers_8c.html#a5">00169</a> <span class="keywordtype">void</span> <a class="code" href="timers_8c.html#a5">free_timer</a> (UINT8 nbr)00170 {00171 <span class="comment">/* Make a simple check */</span>00172 00173 <span class="keywordflow">if</span>( nbr > (<a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>-1) ) 00174 <span class="keywordflow">return</span>; 00175 00176 <a class="code" href="timers_8c.html#a2">timer_pool</a>[nbr].free = <a class="code" href="system_8h.html#a1">TRUE</a>;00177 00178 }00179 00180 <a name="l00194"></a><a class="code" href="timers_8c.html#a6">00194</a> <span class="keywordtype">void</span> <a class="code" href="timers_8c.html#a6">init_timer</a> ( UINT8 nbr, UINT32 tout )00195 {00196 <span class="comment">/* Make a simple check */</span>00197 00198 UINT32 val;00199 00200 <span class="keywordflow">if</span>( nbr > (<a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>-1) ) 00201 <span class="keywordflow">return</span>; 00202 00203 <span class="keywordflow">if</span>( <a class="code" href="timers_8c.html#a2">timer_pool</a>[nbr].free == <a class="code" href="system_8h.html#a1">TRUE</a> ) 00204 <span class="keywordflow">return</span>;00205 00206 <span class="comment">/* All OK */</span>00207 00208 val = tout;00209 00210 <a class="code" href="system_8h.html#a7">OS_EnterCritical</a>();00211 00212 <span class="comment">/* Normalize seconds to timer tics */</span>00213 00214 <a class="code" href="timers_8c.html#a2">timer_pool</a>[nbr].value = val;00215 00216 <a class="code" href="system_8h.html#a8">OS_ExitCritical</a>();00217 00218 } 00219 <a name="l00233"></a><a class="code" href="timers_8c.html#a7">00233</a> UINT32 <a class="code" href="timers_8c.html#a7">check_timer</a> (UINT8 nbr)00234 {00235 00236 <span class="keywordflow">return</span> <a class="code" href="timers_8c.html#a2">timer_pool</a>[nbr].value;00237 00238 }00239 00240 <a name="l00248"></a><a class="code" href="timers_8c.html#a8">00248</a> <span class="keywordtype">void</span> <a class="code" href="timers_8c.html#a7">decrement_timers</a> (<span class="keywordtype">void</span>)00249 {00250 UINT8 i;00251 00252 <span class="comment">/* Go Through Timers */</span>00253 00254 <span class="keywordflow">for</span>( i=0; i<<a class="code" href="group__opentcp__config.html#a15">NUMTIMERS</a>; i++ ) {00255 <span class="keywordflow">if</span>( (<a class="code" href="timers_8c.html#a2">timer_pool</a>[i].free == <a class="code" href="system_8h.html#a2">FALSE</a>) && (<a class="code" href="timers_8c.html#a2">timer_pool</a>[i].value != 0))00256 <a class="code" href="timers_8c.html#a2">timer_pool</a>[i].value --;00257 }00258 }</pre></div><hr><address style="align: right;"><small>Generated on Sun Aug 3 20:33:00 2003 for OpenTCP by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -