📄 main__demo_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/demo/main_demo.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/demo/main_demo.c</h1><a href="main__demo_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 00016 <span class="preprocessor">#include <<a class="code" href="debug_8h.html">inet/debug.h</a>></span>00017 <span class="preprocessor">#include <<a class="code" href="debug_8h.html">inet/debug.h</a>></span>00018 <span class="preprocessor">#include <<a class="code" href="config_8h.html">inet/arch/config.h</a>></span>00019 <span class="preprocessor">#include <<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>></span>00020 <span class="preprocessor">#include <<a class="code" href="timers_8h.html">inet/timers.h</a>></span>00021 <span class="preprocessor">#include <<a class="code" href="system_8h.html">inet/system.h</a>></span>00022 <span class="preprocessor">#include <<a class="code" href="ethernet_8h.html">inet/ethernet.h</a>></span>00023 <span class="preprocessor">#include <<a class="code" href="ip_8h.html">inet/ip.h</a>></span>00024 <span class="preprocessor">#include <<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>></span>00025 00026 <span class="comment">/* Network Interface definition. Must be somewhere so why not here? :-)*/</span><a name="l00027"></a><a class="code" href="main__demo_8c.html#a0">00027</a> <span class="keyword">struct </span><a class="code" href="structnetif.html">netif</a> localmachine;00028 00029 <span class="comment">/* main stuff */</span>00030 <span class="keywordtype">void</span> main(<span class="keywordtype">void</span>)00031 {00032 UINT16 len;00033 00034 <span class="comment">/* initialize processor-dependant stuff (I/O ports, timers...).</span>00035 <span class="comment"> * This will normally be some function under the arch/xxxMCU dir. Most</span>00036 <span class="comment"> * important things to do in this function as far as the TCP/IP stack</span>00037 <span class="comment"> * is concerned is to:</span>00038 <span class="comment"> * - initialize some timer so it executes decrement_timers</span>00039 <span class="comment"> * on every 10ms (TODO: Throw out this dependency from several files</span>00040 <span class="comment"> * so that frequency can be adjusted more freely!!!)</span>00041 <span class="comment"> * - not mess too much with ports allocated for Ethernet controller</span>00042 <span class="comment"> */</span>00043 init();00044 00045 <span class="comment">/* Set our network information. This is for static configuration.</span>00046 <span class="comment"> * if using BOOTP or DHCP this will be a bit different.</span>00047 <span class="comment"> */</span>00048 00049 <span class="comment">/* IP address */</span>00050 localmachine.<a class="code" href="structnetif.html#m0">localip</a> = 0xAC1006E9; <span class="comment">/* 172.16.6.233 */</span>00051 <span class="comment">/* Default gateway */</span>00052 localmachine.<a class="code" href="structnetif.html#m2">defgw</a> = 0xAC100101;00053 <span class="comment">/* Subnet mask */</span>00054 localmachine.<a class="code" href="structnetif.html#m3">netmask</a> = 0xFFFF0000;00055 <span class="comment">/* Ethernet (MAC) address */</span>00056 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[5] = 0x00;00057 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[4] = 0x06;00058 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[3] = 0x70;00059 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[2] = 0xBA;00060 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[1] = 0xBE;00061 localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[0] = 0xEE;00062 00063 00064 <span class="comment">/* Init system services */</span> 00065 <a class="code" href="group__core__initializer.html#a3">timer_pool_init</a>();00066 00067 <span class="comment">/*interrupts can be enabled AFTER timer pool has been initialized */</span>00068 00069 <span class="comment">/* Initialize all network layers */</span>00070 <a class="code" href="ethernet_8c.html#a1">NE2000Init</a>(&localmachine.<a class="code" href="structnetif.html#m1">localHW</a>[0]);00071 <a class="code" href="group__core__initializer.html#a0">arp_init</a>();00072 <a class="code" href="group__core__initializer.html#a4">udp_init</a>();00073 <a class="code" href="group__core__initializer.html#a2">tcp_init</a>();00074 00075 <span class="comment">/* Initialize applications */</span>00076 udp_demo_init();00077 tpcc_demo_init();00078 tcps_demo_init();00079 00080 00081 DEBUGOUT(<span class="stringliteral">">>>>>>>>>Entering to MAIN LOOP>>>>>>>>>\n\r"</span>);00082 00083 <span class="comment">/*** MAIN LOOP ***/</span>00084 00085 <span class="keywordflow">while</span>(1) {00086 <span class="comment">/* take care of watchdog stuff */</span>00087 00088 <span class="comment">/* do some stuff here</span>00089 <span class="comment"> * .........</span>00090 <span class="comment"> */</span>00091 00092 00093 <span class="comment">/* Try to receive Ethernet Frame */</span>00094 00095 <span class="keywordflow">if</span>( <a class="code" href="group__periodic__functions.html#a7">NETWORK_CHECK_IF_RECEIVED</a>() == <a class="code" href="system_8h.html#a1">TRUE</a> ) {00096 00097 <span class="keywordflow">switch</span>( received_frame.protocol) {00098 00099 <span class="keywordflow">case</span> <a class="code" href="ethernet_8h.html#a5">PROTOCOL_ARP</a>:00100 <a class="code" href="arp_8c.html#a2">process_arp</a>(&received_frame); 00101 <span class="keywordflow">break</span>;00102 00103 00104 <span class="keywordflow">case</span> <a class="code" href="ethernet_8h.html#a4">PROTOCOL_IP</a>: 00105 len = <a class="code" href="ip_8c.html#a3">process_ip_in</a>(&received_frame);00106 00107 <span class="keywordflow">if</span>(len < 0)00108 <span class="keywordflow">break</span>;00109 00110 <span class="keywordflow">switch</span>(received_ip_packet.protocol){00111 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a1">IP_ICMP</a>:00112 <a class="code" href="icmp_8c.html#a2">process_icmp_in</a> (&received_ip_packet, len); 00113 <span class="keywordflow">break</span>;00114 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a2">IP_UDP</a>:00115 <a class="code" href="udp_8c.html#a8">process_udp_in</a> (&received_ip_packet,len);00116 <span class="keywordflow">break</span>;00117 <span class="keywordflow">case</span> <a class="code" href="ip_8h.html#a3">IP_TCP</a>:00118 <a class="code" href="tcp_8c.html#a14">process_tcp_in</a> (&received_ip_packet, len); 00119 <span class="keywordflow">break</span>;00120 <span class="keywordflow">default</span>:00121 <span class="keywordflow">break</span>;00122 }00123 <span class="keywordflow">break</span>;00124 00125 <span class="keywordflow">default</span>:00126 00127 <span class="keywordflow">break</span>;00128 }00129 00130 <span class="comment">/* discard received frame */</span> 00131 <a class="code" href="group__periodic__functions.html#a8">NETWORK_RECEIVE_END</a>();00132 }00133 00134 <span class="comment">/* Application main loops */</span>00135 <span class="comment">/* Do not forget this!!! These don't get invoked magically :-) */</span>00136 udp_demo_run();00137 tcpc_demo_run();00138 tcps_demo_run();00139 00140 00141 <span class="comment">/* TCP/IP stack Periodic tasks */</span>00142 <span class="comment">/* Check possible overflow in Ethernet controller */</span>00143 <a class="code" href="group__periodic__functions.html#a1">NE2000CheckOverFlow</a>();00144 <span class="comment">/* manage arp cache tables */</span>00145 <a class="code" href="group__periodic__functions.html#a0">arp_manage</a>();00146 <span class="comment">/* manage opened TCP connections (retransmissions, timeouts,...)*/</span>00147 <a class="code" href="group__periodic__functions.html#a4">tcp_poll</a>();00148 }00149 00150 }00151 </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 + -