📄 webport_8c-source.html
字号:
00302 <span class="comment">/*</span>00303 <span class="comment"> * If the Nut/OS libraries had been compiled and linked with</span>00304 <span class="comment"> * NUTDEBUG defined, we can switch on additional trace output.</span>00305 <span class="comment"> */</span>00306 <span class="preprocessor">#ifdef NUTDEBUG</span>00307 <span class="preprocessor"></span> NutTraceTcp(stdout, 0);00308 NutTraceOs(stdout, 0);00309 NutTraceHeap(stdout, 0);00310 <span class="preprocessor">#endif</span>00311 <span class="preprocessor"></span>00312 <span class="comment">/*</span>00313 <span class="comment"> * During debugging, some delay during startup is quite helpful.</span>00314 <span class="comment"> */</span>00315 NutSleep(2000);00316 <span class="preprocessor">#endif</span>00317 <span class="preprocessor"></span>00318 <span class="comment">/*</span>00319 <span class="comment"> * Register the Ethernet controller. Nut/OS supports different</span>00320 <span class="comment"> * controllers. We use DEV_ETHER here, which should have been </span>00321 <span class="comment"> * defined in one of the include files, which fits our real hardware.</span>00322 <span class="comment"> */</span>00323 <span class="keywordflow">if</span> (NutRegisterDevice(&DEV_ETHER, 0x8300, 5)) {00324 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00325 <span class="preprocessor"></span> puts(<span class="stringliteral">"Registering NIC failed"</span>);00326 <span class="preprocessor">#endif</span>00327 <span class="preprocessor"></span> }00328 00329 <span class="comment">/*</span>00330 <span class="comment"> * LAN configuration using values in non-volatile memory or </span>00331 <span class="comment"> * DHCP/ARP. We are ready to wait upto 15 seconds for a </span>00332 <span class="comment"> * response from the DHCP server. If it fails, use hardcoded </span>00333 <span class="comment"> * values.</span>00334 <span class="comment"> *</span>00335 <span class="comment"> * The whole process is done in three steps.</span>00336 <span class="comment"> *</span>00337 <span class="comment"> * 1. Call NutDhcpIfConfig() without specifying a MAC address</span>00338 <span class="comment"> * will try read all values from non-volatile memory. If</span>00339 <span class="comment"> * there are no values available, it will immediately</span>00340 <span class="comment"> * return an error.</span>00341 <span class="comment"> *</span>00342 <span class="comment"> * 2. If step 1 fails, call NutDhcpIfConfig() with a hard coded </span>00343 <span class="comment"> * MAC address. The routine will use this MAC address to query </span>00344 <span class="comment"> * a DHCP server for its IP configuration. If it succeeds, the </span>00345 <span class="comment"> * MAC address and the values received from DHCP will be </span>00346 <span class="comment"> * stored in non-volatile memory and used in step 1 during the</span>00347 <span class="comment"> * next reboot. Otherwise the call will return an error.</span>00348 <span class="comment"> *</span>00349 <span class="comment"> * 3. If step 2 fails, call NutNetIfConfig() with hard coded</span>00350 <span class="comment"> * MAC address and IP configuration. This fixed values will</span>00351 <span class="comment"> * be stored in non-volatile memory and on the next reboot,</span>00352 <span class="comment"> * these values will be used in step 1.</span>00353 <span class="comment"> *</span>00354 <span class="comment"> * Note, that DHCP is only used, if the network configuration</span>00355 <span class="comment"> * stored in non-volatile memory doesn't contain a fixed IP</span>00356 <span class="comment"> * address. If a fixed value is used once, Nut/OS will store</span>00357 <span class="comment"> * it in non-volatile memory and never use DHCP unless this</span>00358 <span class="comment"> * fixed values are removed from volatile memory again.</span>00359 <span class="comment"> */</span>00360 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00361 <span class="preprocessor"></span> printf(<span class="stringliteral">"\nTry stored configuration..."</span>);00362 <span class="preprocessor">#endif</span>00363 <span class="preprocessor"></span> <span class="keywordflow">if</span> (NutDhcpIfConfig(<span class="stringliteral">"eth0"</span>, 0, 10000)) {00364 u_char mac[] = { <a class="code" href="group__xg_w_p_defs.html#ga0">MYMAC</a> };00365 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00366 <span class="preprocessor"></span> printf(<span class="stringliteral">"failed\nTry DHCP..."</span>);00367 <span class="preprocessor">#endif</span>00368 <span class="preprocessor"></span> <span class="keywordflow">if</span> (NutDhcpIfConfig(<span class="stringliteral">"eth0"</span>, mac, 10000)) {00369 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00370 <span class="preprocessor"></span> printf(<span class="stringliteral">"failed\nUse fixed configuration..."</span>);00371 <span class="preprocessor">#endif</span>00372 <span class="preprocessor"></span> <span class="keywordflow">if</span> (NutNetIfConfig(<span class="stringliteral">"eth0"</span>, mac, inet_addr(<a class="code" href="group__xg_w_p_defs.html#ga1">MYIP</a>), inet_addr(<a class="code" href="group__xg_w_p_defs.html#ga2">MYMASK</a>))) {00373 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00374 <span class="preprocessor"></span> puts(<span class="stringliteral">"failed\nWhere is the NIC?"</span>);00375 <span class="preprocessor">#endif</span>00376 <span class="preprocessor"></span> <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00377 }00378 <span class="comment">/* If not in a local network, we must also call </span>00379 <span class="comment"> NutIpRouteAdd() to configure the routing. */</span>00380 }00381 }00382 <span class="preprocessor">#ifdef WP_STATUSOUT</span>00383 <span class="preprocessor"></span> puts(<span class="stringliteral">"OK"</span>);00384 <span class="keywordflow">if</span> (confnet.cdn_cip_addr)00385 printf(<span class="stringliteral">"IP addr: %s\n"</span>, inet_ntoa(confnet.cdn_cip_addr));00386 <span class="keywordflow">else</span>00387 printf(<span class="stringliteral">"IP addr: %s\n"</span>, inet_ntoa(confnet.cdn_ip_addr));00388 printf(<span class="stringliteral">"IP mask: %s\n"</span>, inet_ntoa(confnet.cdn_ip_mask));00389 printf(<span class="stringliteral">"IP gate: %s\n"</span>, inet_ntoa(confnet.cdn_gateway));00390 <span class="preprocessor">#endif</span>00391 <span class="preprocessor"></span>00392 <span class="comment">/*</span>00393 <span class="comment"> * Register our device for the file system. If we intend to use </span>00394 <span class="comment"> * another file system, we need to register it by calling</span>00395 <span class="comment"> * NutRegisterHttpRoot(). If none is registered, the UROM</span>00396 <span class="comment"> * file system will be used by default.</span>00397 <span class="comment"> */</span>00398 NutRegisterDevice(&devUrom, 0, 0);00399 00400 <span class="comment">/*</span>00401 <span class="comment"> * Register our CGI routines. This is required to inform the</span>00402 <span class="comment"> * HTTP helper routines, which corresponding routine has to</span>00403 <span class="comment"> * be called.</span>00404 <span class="comment"> */</span>00405 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga8">PORT_CONTROL_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga10">CpuPortControl</a>))00406 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00407 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga9">PORT_STATUS_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga11">CpuPortStatus</a>))00408 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00409 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga10">RELAY_CONTROL_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga12">SpiRelayControl</a>))00410 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00411 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga11">OPTO_STATUS_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga13">SpiOptoStatus</a>))00412 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00413 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga12">CHARON_CONTROL_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga14">CharonLedControl</a>))00414 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00415 <span class="keywordflow">if</span> (NutRegisterCgi(<a class="code" href="group__xg_w_p_defs.html#ga13">CHARON_STATUS_CGI</a>, <a class="code" href="group__xg_c_g_i.html#ga15">CharonSwitchStatus</a>))00416 <a class="code" href="group__xg_web_port.html#ga3">JUMP_RESET</a>;00417 00418 <span class="comment">/*</span>00419 <span class="comment"> * Start a defined number of concurrent background threads. The more </span>00420 <span class="comment"> * threads we have running, the more connections we can handle </span>00421 <span class="comment"> * concurrently. However, each thread occupies some additional RAM.</span>00422 <span class="comment"> */</span>00423 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="group__xg_w_p_defs.html#ga6">NUM_HTTP_THREADS</a> - 1; i++) {00424 <span class="comment">/*</span>00425 <span class="comment"> * Not really required here, but we give each thread a unique</span>00426 <span class="comment"> * name.</span>00427 <span class="comment"> */</span>00428 <span class="keywordtype">char</span> *thname = <span class="stringliteral">"httpd0"</span>;00429 thname[5] = <span class="charliteral">'0'</span> + i;00430 NutThreadCreate(thname, <a class="code" href="group__xg_web_port.html#ga1">ServiceThread</a>, 0, <a class="code" href="group__xg_w_p_defs.html#ga7">HTTP_THREAD_STACK</a>);00431 }00432 00433 <span class="comment">/*</span>00434 <span class="comment"> * Finally we use the main thread too for handling HTTP request.</span>00435 <span class="comment"> * There's nothing else we can do.</span>00436 <span class="comment"> */</span>00437 <span class="keywordflow">for</span> (;;) {00438 <a class="code" href="group__xg_web_port.html#ga0">Service</a>();00439 }00440 00441 <span class="comment">/*</span>00442 <span class="comment"> * This point is never reached. Nut/OS applications are started</span>00443 <span class="comment"> * once and continue running forever.</span>00444 <span class="comment"> */</span>00445 }00446 <span class="comment"></span>00447 <span class="comment">/*@}*/</span></pre></div><hr><address> <small> © 2002-2004 by egnite Software GmbH - visit <a href="http://www.ethernut.de/">http://www.ethernut.de/</a> </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -