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

📄 lwip_init.c

📁 lan911的vhdl源代码
💻 C
字号:
/******************************************************************************* Copyright ? 2004 Altera Corporation, San Jose, California, USA.             ** All rights reserved. All use of this software and documentation is          ** subject to the License Agreement located at the end of this file below.     ********************************************************************************                                                                             ** Author - S. O'Reilly                                                        ** Date - July 4, 2004                                                         ** Module - lwip_init.c                                                        **                                                                             *                                                                             ** Based on Telnet example by JRK and lwIP & HTTP server ports by PRR          *******************************************************************************//****************************************************************************** * lwIP TCP/IP stack initialization and Operating System Start in main() * for Simple Socket Server (SSS) example.  *  * This example demonstrates the use of MicroC/OS-II running on NIOS II.        * In addition it is to serve as a good starting point for designs using        * MicroC/OS-II and lightweight IP with NIOS II.                                                                                            *       * Please refer to the Using Lightweight IP with the Nios II Processor Tutorial  * documentation for details on this  * software example, as well as details on how to configure the lwIP TCP/IP  * networking stack and MicroC/OS-II Real-Time Operating System.  This * Tutorial, along with the rest of the Nios II documentation is published  * on the Altera web-site.  See:  * Start Menu -> Programs -> Nios II Development Kit -> Nios II Documentation. */ /* * Include files: *  *      <stdio.h>: Standard IO *   lwip/netif.h: lwIP stack network interface structs. * lwip/sockets.h: Sockets API. *     includes.h: This is the default MicroC/OS-II include file. *      Simple_Socket_Server.h: Our Simple Socket Server declarations. * alt_lwip_dev.h: Defines lwIP stack initialization calls. *     lwip/sys.h: Defines lwIP stack system calls (e.g. sys_thead_new()). * alt_error_handler.h: Altera Error Handler suite of development error  * handling functions. */ #include <stdio.h>#include "includes.h"#include "simple_socket_server.h"                                                                    #include "alt_error_handler.h"#include "alt_lwip_dev.h"#include "lwip/sys.h"#include "lwip/netif.h"#include "lwip/sockets.h"/* * init_done_func() *  * This function is called once the lwIP stack is alive, as specified in our * lwip_stack_init() call in main(), below. * * We tell it about each of our network devices and start the application &  * timer threads as appropriate. */ static void init_done_func(void *arg){  /*    * At this point lwIP has been initialized, but the Ethernet interface has   * not; the lwip_devices_init() call does so, adding in MicroC-OS/II   * threads for low-level Ethernet MAC interface and TCP protocol timer.   */   if (!lwip_devices_init(LWIP_RX_ETHER_TASK_PRIORITY))   {      alt_lwIPErrorHandler(EXPANDED_DIAGNOSIS_CODE,"[init_done_func] Fatal: lwip_devices_init failed, perhaps ethernet interface.");   } #if LWIP_DHCP == 1  /*    * If DHCP is enabled, activate a thread for the 120-second long time period   * that will set a static IP address if acquisistion via DHCP times out.    */   if (!sys_thread_new(NETUTILSDHCPTimeoutTask, NULL,                        NETUTILS_DHCP_TIMEOUT_TASK_PRIORITY))   {      alt_lwIPErrorHandler(EXPANDED_DIAGNOSIS_CODE,                 "[init_done_func] Fatal: Can't add NETUTILSDHCPTimeoutTask!");   }#endif /* LWIP_DHCP */    /*    * Add any application task(s) that rely on lwIP:   *     * 1. SSSSimpleSocketServerTask() - Creates listening sockets, manages    *          incoming connection requests, and handles all simple socket    *          server communication.   */   if(!sys_thread_new(SSSSimpleSocketServerTask, NULL,                       SSS_SIMPLE_SOCKET_SERVER_TASK_PRIORITY))   {      alt_lwIPErrorHandler(EXPANDED_DIAGNOSIS_CODE,              "[init_done_func] Fatal: Can't add SSSSimpleSocketServerTask!");     }}/* Main initializes lwIP, creates a single task and starts task scheduler. */ int main (int argc, char* argv[], char* envp[]){    INT8U error_code;    /*    * Our very first call in an lwIP example design is to start up lwIP TCP/IP   * stack. We specify a MicroC/OS-II thread priority for the tcp_ip thread,   * as well as a call-back routine, init_done_func(), which is called once   * the stack is alive and well.   */  lwip_stack_init(LWIP_TCPIP_TASK_PRIORITY, init_done_func, 0);    error_code = OSTaskCreateExt(SSSInitialTask,                             NULL,                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],                             SSS_INITIAL_TASK_PRIORITY,                             SSS_INITIAL_TASK_PRIORITY,                             SSSInitialTaskStk,                             TASK_STACKSIZE,                             NULL,                             0);  alt_uCOSIIErrorHandler(error_code, 0);  printf("\nSimple Socket Server starting up\n");      /*   * As with all MicroC/OS-II designs, once the initial thread(s) and    * associated RTOS resources are declared, we start the RTOS. That's it!   */  OSStart();    while(1); /* Correct Program Flow never gets here. */  return -1;}

⌨️ 快捷键说明

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