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

📄 main__demo_8c-example.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 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>Example Documentation</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>main_demo.c</h1><p>This is an example main.c file demonstrating basically two things: initialization sequence and main loop organization.<dl compact><dt><b>Initialization sequence</b></dt><dd> When performing initialization, all OpenTCP initialization functions must be invoked, starting from the lowest-level modules and continuing upwards (because it may be assumed that higher-level modules might already rely during their initialization on proper functioning of  lower-level modules). Usual Initialization sequence looks something like:<ul><li>hardware initialization<li>timer pool initialization<li>OpenTCP network layers initialization<li>Application layer initialization</ul></dl><dl compact><dt><b>Main loop organization</b></dt><dd> In main program loop three things must be accomplished:<ul><li>constant checking of Ethernet controller for new Etherner packets and, if new packets found, their further processing and in the end discarding. Network buffer overflows must also be checked periodically.<li>Application layer main loop functions must be invoked to enable their proper functioning<li>OpenTCP network layer periodic functions must be invoked to ensure proper resource management and behaviour.</ul></dl>More details about this example:<p><div class="fragment"><pre><span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="config_8h.html">inet/arch/config.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="timers_8h.html">inet/timers.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="ethernet_8h.html">inet/ethernet.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="ip_8h.html">inet/ip.h</a>&gt;</span><span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span><span class="comment">/* Network Interface definition. Must be somewhere so why not here? :-)*/</span><span class="keyword">struct </span><a name="_a0"></a><a class="code" href="structnetif.html">netif</a> localmachine;<span class="comment">/* main stuff */</span><span class="keywordtype">void</span> main(<span class="keywordtype">void</span>){        UINT16 len;                <span class="comment">/* initialize processor-dependant stuff (I/O ports, timers...).</span><span class="comment">         * This will normally be some function under the arch/xxxMCU dir. Most</span><span class="comment">         * important things to do in this function as far as the TCP/IP stack</span><span class="comment">         * is concerned is to:</span><span class="comment">         *  - initialize some timer so it executes decrement_timers</span><span class="comment">         *      on every 10ms (TODO: Throw out this dependency from several files</span><span class="comment">         *      so that frequency can be adjusted more freely!!!)</span><span class="comment">         *  - not mess too much with ports allocated for Ethernet controller</span><span class="comment">         */</span>        init();                 <span class="comment">/* Set our network information. This is for static configuration.</span><span class="comment">        * if using BOOTP or DHCP this will be a bit different.</span><span class="comment">        */</span>                <span class="comment">/* IP address */</span>        localmachine.<a name="a1"></a><a class="code" href="structnetif.html#m0">localip</a> = 0xAC1006E9;      <span class="comment">/* 172.16.6.233 */</span>        <span class="comment">/* Default gateway */</span>        localmachine.<a name="a2"></a><a class="code" href="structnetif.html#m2">defgw</a> =    0xAC100101;        <span class="comment">/* Subnet mask */</span>        localmachine.<a name="a3"></a><a class="code" href="structnetif.html#m3">netmask</a> = 0xFFFF0000;        <span class="comment">/* Ethernet (MAC) address */</span>        localmachine.<a name="a4"></a><a class="code" href="structnetif.html#m1">localHW</a>[5] = 0x00;        localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[4] = 0x06;        localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[3] = 0x70;        localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[2] = 0xBA;        localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[1] = 0xBE;        localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[0] = 0xEE;                <span class="comment">/* Init system services         */</span>            <a name="a5"></a><a class="code" href="group__core__initializer.html#a3">timer_pool_init</a>();                        <span class="comment">/*interrupts can be enabled AFTER timer pool has been initialized */</span>                <span class="comment">/* Initialize all network layers        */</span>        <a name="a6"></a><a class="code" href="group__core__initializer.html#a1">NE2000Init</a>(&amp;localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[0]);        <a name="a7"></a><a class="code" href="group__core__initializer.html#a0">arp_init</a>();        <a name="a8"></a><a class="code" href="group__core__initializer.html#a4">udp_init</a>();        <a name="a9"></a><a class="code" href="group__core__initializer.html#a2">tcp_init</a>();        <span class="comment">/* Initialize applications      */</span>        udp_demo_init();        tpcc_demo_init();        tcps_demo_init();            DEBUGOUT(<span class="stringliteral">"&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;Entering to MAIN LOOP&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;\n\r"</span>);          <span class="comment">/***    MAIN LOOP       ***/</span>            <span class="keywordflow">while</span>(1) {                <span class="comment">/* take care of watchdog stuff */</span>                                        <span class="comment">/* do some stuff here</span><span class="comment">                * .........</span><span class="comment">                */</span>                                      <span class="comment">/* Try to receive Ethernet Frame        */</span>                        <span class="keywordflow">if</span>( <a name="a10"></a><a class="code" href="group__periodic__functions.html#a7">NETWORK_CHECK_IF_RECEIVED</a>() == <a class="code" href="system_8h.html#a1">TRUE</a> )       {                                                        <span class="keywordflow">switch</span>( received_frame.protocol) {                                                        <span class="keywordflow">case</span> <a class="code" href="ethernet_8h.html#a5">PROTOCOL_ARP</a>:                                        <a name="a11"></a><a class="code" href="arp_8c.html#a2">process_arp</a>(&amp;received_frame);                                           <span class="keywordflow">break</span>;                                                                                <span class="keywordflow">case</span> <a class="code" href="ethernet_8h.html#a4">PROTOCOL_IP</a>:                                                               len = <a name="a12"></a><a class="code" href="group__periodic__functions.html#a3">process_ip_in</a>(&amp;received_frame);                                                                        <span class="keywordflow">if</span>(len &lt; 0)                                                <span class="keywordflow">break</span>;                                                                        <span class="keywordflow">switch</span>(received_ip_packet.protocol){                                                <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a1">IP_ICMP</a>:                                                        <a name="a13"></a><a class="code" href="group__periodic__functions.html#a2">process_icmp_in</a> (&amp;received_ip_packet, len);                                                                                             <span class="keywordflow">break</span>;                                                <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a2">IP_UDP</a>:                                                        <a name="a14"></a><a class="code" href="group__periodic__functions.html#a6">process_udp_in</a> (&amp;received_ip_packet,len);                                                        <span class="keywordflow">break</span>;                                                <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a3">IP_TCP</a>:                                                        <a name="a15"></a><a class="code" href="group__periodic__functions.html#a5">process_tcp_in</a> (&amp;received_ip_packet, len);                                                                                      <span class="keywordflow">break</span>;                                                <span class="keywordflow">default</span>:                                                        <span class="keywordflow">break</span>;                                        }                        <span class="keywordflow">break</span>;                        <span class="keywordflow">default</span>:                                                        <span class="keywordflow">break</span>;                }                                <span class="comment">/* discard received frame */</span>                                    <a name="a16"></a><a class="code" href="group__periodic__functions.html#a8">NETWORK_RECEIVE_END</a>();        }                 <span class="comment">/* Application main loops */</span>        <span class="comment">/* Do not forget this!!! These don't get invoked magically :-) */</span>        udp_demo_run();        tcpc_demo_run();        tcps_demo_run();                <span class="comment">/* TCP/IP stack Periodic tasks  */</span>        <span class="comment">/* Check possible overflow in Ethernet controller */</span>        <a name="a17"></a><a class="code" href="group__periodic__functions.html#a1">NE2000CheckOverFlow</a>();        <span class="comment">/* manage arp cache tables */</span>        <a name="a18"></a><a class="code" href="group__periodic__functions.html#a0">arp_manage</a>();        <span class="comment">/* manage opened TCP connections (retransmissions, timeouts,...)*/</span>        <a name="a19"></a><a class="code" href="group__periodic__functions.html#a4">tcp_poll</a>();    }    }</pre></div><hr><address style="align: right;"><small>Generated on Sun Aug 3 20:32:59 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 + -