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

📄 system_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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/system.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> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>/opentcp/system.c</h1><a href="system_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 &lt;http://www.opentcp.org&gt;.</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"> *&lt;http://www.violasystems.com/&gt;.</span>00052 <span class="comment"> */</span>00053 00069 <span class="preprocessor">#include &lt;<a class="code" href="config_8h.html">inet/arch/config.h</a>&gt;</span>00070 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00071 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00072 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00073 <a name="l00074"></a><a class="code" href="system_8c.html#a0">00074</a> UINT32 <a class="code" href="system_8c.html#a0">base_timer</a>;              <a name="l00076"></a><a class="code" href="system_8c.html#a1">00076</a> UINT8 <a class="code" href="system_8c.html#a1">sleep_mode</a> = 0;   <a name="l00099"></a><a class="code" href="system_8c.html#a2">00099</a> UINT8 <a class="code" href="system_8c.html#a2">net_buf</a>[<a class="code" href="group__opentcp__config.html#a4">NETWORK_TX_BUFFER_SIZE</a>];  <span class="comment">/* Network transmit buffer      */</span>00100 00101 <span class="comment">/********************************************************************************</span>00102 <span class="comment">Function:               strlen</span>00103 <span class="comment"></span>00104 <span class="comment">Parameters:             UINT8* str - start address of string buffer</span>00105 <span class="comment">                                UINT16 len - buffer length</span>00106 <span class="comment">                                </span>00107 <span class="comment">Return val:             INT16 - (-1) Not a string</span>00108 <span class="comment">                                                (&gt;=0) Length of string</span>00109 <span class="comment">                                </span>00110 <span class="comment">Date:                   12.8.2002</span>00111 <span class="comment"></span>00112 <span class="comment">Desc:                   Calculates the length of given string</span>00113 <span class="comment">*********************************************************************************/</span>00114 00115 00116 INT16 strlen (UINT8* buf, UINT16 len)00117 {00118         UINT16 i;00119         00120         <span class="keywordflow">for</span>(i=0; i&lt;len; i++) {00121                 <span class="keywordflow">if</span>(*buf == <span class="charliteral">'\0'</span>)00122                         <span class="keywordflow">return</span>( i );00123                 00124                 buf++;00125         }00126         00127         <span class="comment">/* Not found    */</span>00128         00129         <span class="keywordflow">return</span>(-1);00130 00131 00132 }00133 00134 00135 <span class="comment">/********************************************************************************</span>00136 <span class="comment">Function:               bufsearch</span>00137 <span class="comment"></span>00138 <span class="comment">Parameters:             UINT8* startadr - start address of given buffer</span>00139 <span class="comment">                                UINT16 len - buffer length</span>00140 <span class="comment">                                UINT8* str - given searchstring</span>00141 <span class="comment">                                </span>00142 <span class="comment">Return val:             INT16 - (-1) Not found</span>00143 <span class="comment">                                                (&gt;=0) Start of matched string from startadr</span>00144 <span class="comment">                                </span>00145 <span class="comment">Date:                   12.7.2002</span>00146 <span class="comment"></span>00147 <span class="comment">Desc:                   Seeks given string from given buffer</span>00148 <span class="comment">*********************************************************************************/</span>00149 00150 INT16 bufsearch (UINT8* startadr, UINT16 len, UINT8* str)00151 {00152         UINT16 i;00153         INT16 position;00154         UINT8 matchesneeded;00155         UINT8 matchesnow;00156         UINT8* target;00157         UINT8* key;00158         00159         target = startadr;00160         position = -1;00161         key = str;00162         matchesnow = 0;00163         matchesneeded = 0;00164         00165         <span class="comment">/* How many matches we need?    */</span>00166         00167         <span class="keywordflow">while</span>( *key++ != <span class="charliteral">'\0'</span> ) {00168                 <span class="comment">/* Break possible deadlock      */</span>00169                 00170                 matchesneeded++;00171                 <span class="keywordflow">if</span>(matchesneeded &gt; 30)00172                         <span class="keywordflow">return</span>(-1);00173         }00174         00175         <span class="comment">/* Search for first mark and continue searching if found        */</span>00176         00177         key = str;00178         00179         <span class="keywordflow">for</span>(i=0; i&lt;len; i++) {00180                 <span class="keywordflow">if</span>( *target == *key) {00181                         <span class="comment">/* We found matching character          */</span>00182                         00183                         matchesnow++;00184                         00185                         <span class="comment">/* Move to next character of key        */</span>00186                         00187                         key++;00188                         target++;00189                         00190                         <span class="keywordflow">if</span>(matchesnow == 1) {00191                                 <span class="comment">/* First character match        */</span>00192                                 00193                                 position = i;00194                         }00195                         00196                         <span class="keywordflow">if</span>(matchesneeded == matchesnow) {00197                                 <span class="comment">/* Whole string matched */</span>00198                                 00199                                 <span class="keywordflow">return</span>(position);00200                         }00201                         00202                 } <span class="keywordflow">else</span> {00203                 00204                         <span class="keywordflow">if</span>( matchesnow != 0) {00205                                 <span class="comment">/* It wasn't a complete match...                                */</span>00206                                 <span class="comment">/* Initialize counters and start again                  */</span>00207                         00208                                 matchesnow = 0;00209                                 key = str;00210                         00211                                 <span class="comment">/* Move to next character of target after               */</span>00212                                 <span class="comment">/* previous matching character                                  */</span>00213                         00214                                 target = startadr;00215                                 target += position;00216                                 target += 1;00217                         00218                                 i = position;00219                         } <span class="keywordflow">else</span> {00220                                 <span class="comment">/* Just continue searching the first match              */</span>00221                                 target++;00222                         }00223                 }00224         00225         }00226         00227         <span class="comment">/* No matches found...  */</span>00228         00229         <span class="keywordflow">return</span>(-1);00230         00231 }00232 00233 00234 <span class="comment">/********************************************************************************</span>00235 <span class="comment">Function:               tolower</span>00236 <span class="comment"></span>00237 <span class="comment">Parameters:             UINT8 ch - ASCII character to be converted lowercase</span>00238 <span class="comment">                                </span>00239 <span class="comment">Return val:             UINT8 - converted character</span>00240 <span class="comment">                                </span>00241 <span class="comment">Date:                   21.8.2002</span>00242 <span class="comment"></span>00243 <span class="comment">Desc:                   If ch is UPPERCASE letter it is converted to lowercase and </span>00244 <span class="comment">                                returned. Otherwise original character is returned</span>00245 <span class="comment">*********************************************************************************/</span>00246 00247 UINT8 tolower (UINT8 ch)00248 {00249         <span class="keywordflow">if</span>( (ch &lt; 91) &amp;&amp; (ch &gt; 64) )00250                 <span class="keywordflow">return</span>(ch + 32);00251         00252         <span class="keywordflow">return</span>(ch); 00253 00254 }00255 00256 00257 <span class="comment">/********************************************************************************</span>00258 <span class="comment">Function:               toupper</span>00259 <span class="comment"></span>00260 <span class="comment">Parameters:             UINT8 ch - ASCII character to be converted UPPERCASE</span>00261 <span class="comment">                                </span>00262 <span class="comment">Return val:             UINT8 - converted character</span>00263 <span class="comment">                                </span>00264 <span class="comment">Date:                   21.8.2002</span>00265 <span class="comment"></span>00266 <span class="comment">Desc:                   If ch is lowercase letter it is converted to UPPERCASE and </span>00267 <span class="comment">                                returned. Otherwise original character is returned</span>00268 <span class="comment">*********************************************************************************/</span>00269 00270 UINT8 toupper (UINT8 ch)00271 {00272         <span class="keywordflow">if</span>( (ch &lt; 123) &amp;&amp; (ch &gt; 96) )00273                 <span class="keywordflow">return</span>(ch - 32);00274         00275         <span class="keywordflow">return</span>(ch); 00276 00277 }00278 00279 <span class="comment">/* Is the given ASCII code numerical    */</span>00280 <span class="comment">/* e.g. '0','1','2' ... '9'                             */</span>00281 00282 UINT8 isnumeric (UINT8 ch)00283 {00284         <span class="keywordflow">if</span>( (ch &lt; 58) &amp;&amp; (ch &gt; 47) )00285                 <span class="keywordflow">return</span>(1);00286         <span class="keywordflow">return</span>(0);00287 }00288 00289 00290 <span class="comment">/* HexToAscii - Take one byte and return its two ASCII  */</span>00291 <span class="comment">/* values for both nibbles                                                              */</span>00292 00293 UINT16 hextoascii (UINT8 c)00294 {00295         UINT8 ch = c;00296         UINT8 as1;00297         UINT8 as2;00298 00299         <span class="comment">/* take the char and turn it to ASCII */</span>00300         00301         as1 = ch;00302         as1 &gt;&gt;= 4;00303         as1 &amp;= 0x0F;00304         <span class="keywordflow">if</span> ( as1&lt;10 )00305                 as1 += 48;00306         <span class="keywordflow">else</span>00307                 as1 += 55;00308                 00309         as2 = ch;00310         as2 &amp;= 0x0F;

⌨️ 快捷键说明

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