Beispiel #1
0
/**
 * Initialize this module:
 * - initialize all sub modules
 * - start the tcpip_thread
 *
 * @param initfunc a function to call when tcpip_thread is running and finished initializing
 * @param arg argument to pass to initfunc
 */
void
tcpip_init(void (* initfunc)(void *), void *arg)
{
  lwip_init();

  tcpip_init_done = initfunc;
  tcpip_init_done_arg = arg;
  mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
#if LWIP_TCPIP_CORE_LOCKING
  lock_tcpip_core = sys_sem_new(1);
#endif /* LWIP_TCPIP_CORE_LOCKING */

  sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
}
Beispiel #2
0
int main_thread()
{
#if LWIP_DHCP==1
	int mscnt = 0;
#endif
	/* initialize lwIP before calling sys_thread_new */
    lwip_init();

    /* any thread using lwIP should be created using sys_thread_new */
    sys_thread_new("NW_THRD", network_thread, NULL,
            THREAD_STACKSIZE,
            DEFAULT_THREAD_PRIO);
#if LWIP_DHCP==1
    while (1) {
#ifdef OS_IS_FREERTOS
    	vTaskDelay(DHCP_FINE_TIMER_MSECS / portTICK_RATE_MS);
#else
    	sleep(DHCP_FINE_TIMER_MSECS);
#endif
		if (server_netif.ip_addr.addr) {
			xil_printf("DHCP request success\r\n");
			print_ip_settings(&(server_netif.ip_addr), &(server_netif.netmask), &(server_netif.gw));
			/* print all application headers */
			print_headers();
			/* now we can start application threads */
			launch_app_threads();
			break;
		}
		mscnt += DHCP_FINE_TIMER_MSECS;
		if (mscnt >= 10000) {
			xil_printf("ERROR: DHCP request timed out\r\n");
			xil_printf("Configuring default IP of 192.168.1.10\r\n");
			IP4_ADDR(&(server_netif.ip_addr),  192, 168,   1, 10);
			IP4_ADDR(&(server_netif.netmask), 255, 255, 255,  0);
			IP4_ADDR(&(server_netif.gw),      192, 168,   1,  1);
			print_ip_settings(&(server_netif.ip_addr), &(server_netif.netmask), &(server_netif.gw));
			/* print all application headers */
			print_headers();
			launch_app_threads();
			break;
		}

	}
#ifdef OS_IS_FREERTOS
	vTaskDelete(NULL);
#endif
#endif

    return 0;
}
Beispiel #3
0
/* win32_init() performs win32 socket initialization to properly setup the
   stack to allow networking */
static CURLcode win32_init(void)
{
#ifdef USE_WINSOCK
  WORD wVersionRequested;
  WSADATA wsaData;
  int res;

#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
  Error IPV6_requires_winsock2
#endif

  wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);

  res = WSAStartup(wVersionRequested, &wsaData);

  if(res != 0)
    /* Tell the user that we couldn't find a useable */
    /* winsock.dll.     */
    return CURLE_FAILED_INIT;

  /* Confirm that the Windows Sockets DLL supports what we need.*/
  /* Note that if the DLL supports versions greater */
  /* than wVersionRequested, it will still return */
  /* wVersionRequested in wVersion. wHighVersion contains the */
  /* highest supported version. */

  if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
     HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
    /* Tell the user that we couldn't find a useable */

    /* winsock.dll. */
    WSACleanup();
    return CURLE_FAILED_INIT;
  }
  /* The Windows Sockets DLL is acceptable. Proceed. */
#elif defined(USE_LWIPSOCK)
  lwip_init();
#endif

#ifdef USE_WINDOWS_SSPI
  {
    CURLcode result = Curl_sspi_global_init();
    if(result)
      return result;
  }
#endif

  return CURLE_OK;
}
Beispiel #4
0
/**@brief Function for initializing IP stack.
 *
 * @details Initialize the IP Stack and its driver.
 */
static void ip_stack_init(void)
{
    uint32_t err_code;

    //Initialize memory manager.
    err_code = nrf51_sdk_mem_init();
    APP_ERROR_CHECK(err_code);

    //Initialize lwip stack driver.
    err_code = nrf51_driver_init();
    APP_ERROR_CHECK(err_code);

    //Initialize lwip stack.
    lwip_init();
}
/** \brief Initialize the Ethernet subsystem.
 *
 */
void init_ethernet(const u8_t macAddress[], const char *hostname)
{
	lwip_init();
	ethernet_hardware_init();

	ethernetif_set_mac_address(macAddress);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Waddress"
	/* netif_set_hostname() macro uses an always true conditional
	 * for encapsulation.  That, generates a compiler warning which
	 * is why that particular trick isn't always apt.
	 */
	netif_set_hostname(&gs_net_if, hostname);
#pragma GCC diagnostic pop
}
Beispiel #6
0
int
main_thread()
{
	//xil_printf("Before lwip_init\r\n");
    /* initialize lwIP before calling sys_thread_new */
    lwip_init();

    //xil_printf("After lwip_init\r\n");
    //xil_printf("Before NW_THREAD creation\r\n");
    /* any thread using lwIP should be created using sys_thread_new */
    sys_thread_new("NW_THREAD", network_thread, NULL,
            THREAD_STACKSIZE,
            DEFAULT_THREAD_PRIO);

    return 0;
}
/**
 * Initialize this module:
 * - initialize all sub modules
 * - start the tcpip_thread
 *
 * @param initfunc a function to call when tcpip_thread is running and finished initializing
 * @param arg argument to pass to initfunc
 */
void
tcpip_init(void (* initfunc)(void *), void *arg)
{
#if 0 /* refer lwip_sock_init() called in lwip_init() for details on why this is commented out */
  lwip_init();
#endif

  tcpip_init_done = initfunc;
  tcpip_init_done_arg = arg;
  mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
#if LWIP_TCPIP_CORE_LOCKING
  lock_tcpip_core = sys_sem_new(1);
#endif /* LWIP_TCPIP_CORE_LOCKING */

  sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
}
Beispiel #8
0
static void init_lwip(void)
{
	lwip_init();
	tcp_mem_free(lwip_free_payload);

	/* setting the IP address */
	IP4_ADDR(&ip, 10,0,2,8);
	IP4_ADDR(&gw, 10,0,1,1);
	/* IP4_ADDR(&ip, 192,168,1,128); */
	/* IP4_ADDR(&gw, 192,168,1,1); */
	IP4_ADDR(&mask, 255,255,255,0);
	
	netif_add(&cos_if, &ip, &mask, &gw, NULL, cos_if_init, ip_input);
	netif_set_default(&cos_if);
	netif_set_up(&cos_if);
}
/** \brief Create ethernet task, for ethernet management.
 *
 */
void init_ethernet(const unsigned char ipAddress[], const unsigned char netMask[], const unsigned char gateWay[])
{
	/* Initialize lwIP */
	lwip_init();

	/* Set hw and IP parameters, initialize MAC too */
	ethernet_configure_interface(ipAddress, netMask, gateWay);

	/* Init timer service */
	sys_init_timing();

#if defined(HTTP_RAW_USED)
	/* Bring up the web server */
	httpd_init();
#endif
}
Beispiel #10
0
/**
 * \brief Create ethernet task, for ethernet management.
 */
void init_ethernet(void)
{
	/** Initialize lwIP */
	lwip_init();

	/** Init timer service */
	sys_init_timing();

	/** Set hw and IP parameters, initialize MAC too */
	ethernet_configure_interface();

#if defined(HTTP_RAW_USED)
	/** Bring up the web server */
	http_init();
#endif
}
Beispiel #11
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
    /* Enable the CPU Cache */
    CPU_CACHE_Enable();

    /* STM32F7xx HAL library initialization:
         - Configure the Flash ART accelerator on ITCM interface
         - Configure the Systick to generate an interrupt each 1 msec
         - Set NVIC Group Priority to 4
         - Global MSP (MCU Support Package) initialization
       */
    HAL_Init();

    /* Configure the system clock to 200 MHz */
    SystemClock_Config();

    /* Configure the BSP */
    BSP_Config();

    /* Initialize the LwIP stack */
    lwip_init();

    /* Configure the Network interface */
    Netif_Config();

    /* Http webserver Init */
    httpd_init();

    /* Notify user about the network interface config */
    User_notification(&gnetif);

    /* Infinite loop */
    while (1)
    {
        /* Read a received packet from the Ethernet buffers and send it
           to the lwIP for handling */
        ethernetif_input(&gnetif);

        /* Handle timeouts */
        sys_check_timeouts();

#ifdef USE_DHCP
        /* handle periodic timers for DHCP */
        DHCP_Periodic_Handle(&gnetif);
#endif
    }
}
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  /* Configure the BSP */
  BSP_Config();

  /* Initialize the LwIP stack */
  lwip_init();

  /* Configure the Network interface */
  Netif_Config();

  /* Initialize the TFTP server */
  tftpd_init();

  /* Notify user about the network interface config */
  User_notification(&gnetif);

  /* Link the SD Card disk I/O driver */
  FATFS_LinkDriver(&SD_Driver, SD_Path);

  /* Infinite loop */
  while (1)
  {
    /* Read a received packet from the Ethernet buffers and send it
    to the lwIP for handling */
    ethernetif_input(&gnetif);

    /* Handle timeouts */
    sys_check_timeouts();

#ifdef USE_DHCP
    /* handle periodic timers for LwIP */
    DHCP_Periodic_Handle(&gnetif);
#endif
  }
}
Beispiel #13
0
/**
 * Initialize this module:
 * - initialize all sub modules
 * - start the tcpip_thread
 *
 * @param initfunc a function to call when tcpip_thread is running and finished initializing
 * @param arg argument to pass to initfunc
 */
void
tcpip_init(tcpip_init_done_fn initfunc, void *arg)
{
  lwip_init();

  tcpip_init_done = initfunc;
  tcpip_init_done_arg = arg;
  if(sys_mbox_new(&mbox, TCPIP_MBOX_SIZE) != ERR_OK) {
    LWIP_ASSERT("failed to create tcpip_thread mbox", 0);
  }
#if LWIP_TCPIP_CORE_LOCKING
  if(sys_mutex_new(&lock_tcpip_core) != ERR_OK) {
    LWIP_ASSERT("failed to create lock_tcpip_core", 0);
  }
#endif /* LWIP_TCPIP_CORE_LOCKING */
  sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
}
Beispiel #14
0
/**@brief Function for initializing IP stack.
 *
 * @details Initialize the IP Stack and its driver.
 */
static void ip_stack_init(void)
{
    uint32_t err_code;
    err_code = ipv6_medium_eui64_get(m_ipv6_medium.ipv6_medium_instance_id, \
                                     &eui64_local_iid);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_mem_init();
    APP_ERROR_CHECK(err_code);

    //Initialize LwIP stack.
    lwip_init();

    //Initialize LwIP stack driver.
    err_code = nrf_driver_init();
    APP_ERROR_CHECK(err_code);
}
Beispiel #15
0
static void network_init(void)
{
    struct ip4_addr local_ip;
    struct ip4_addr netmask;
    struct ip4_addr gateway_ip;

    init_macadr();
    fsip_or_default(&local_ip, "ip", 192, 168, 0, 42);
    fsip_or_default(&netmask, "netmask", 255, 255, 255, 0);
    fsip_or_default(&gateway_ip, "gateway", 192, 168, 0, 1);

    lwip_init();

    netif_add(&netif, &local_ip, &netmask, &gateway_ip, 0, liteeth_init, ethernet_input);
    netif_set_default(&netif);
    netif_set_up(&netif);
    netif_set_link_up(&netif);
}
Beispiel #16
0
/**
 * Initialize this module:
 * - initialize all sub modules
 * - start the tcpip_thread
 *
 * @param initfunc a function to call when tcpip_thread is running and finished initializing
 * @param arg argument to pass to initfunc
 */
void
tcpip_init(void (* initfunc)(void *), void *arg)
{
  static unsigned char lwipinitflag = 0;
  if(lwipinitflag == 0)
  {
    lwip_init();
    tcpip_init_done = initfunc;
    tcpip_init_done_arg = arg;
    mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
#if LWIP_TCPIP_CORE_LOCKING
    lock_tcpip_core = sys_sem_new(1);
#endif /* LWIP_TCPIP_CORE_LOCKING */
    /*----*/
    TCPIP_Task_Handle = sys_thread_new(TCPIP_THREAD_NAME, tcpip_thread, NULL, TCPIP_THREAD_STACKSIZE, TCPIP_THREAD_PRIO);
    lwipinitflag = 1;
  }
}
Beispiel #17
0
/*!
 * @brief main function
 */
int main(void)
{
  ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

  app_low_level_init();
  OSA_Init();
  lwip_init();

  IP4_ADDR(&fsl_netif0_ipaddr, 192,168,2,102);
  IP4_ADDR(&fsl_netif0_netmask, 255,255,255,0);
  IP4_ADDR(&fsl_netif0_gw, 192,168,2,100);
  netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, ethernet_input);
  netif_set_default(&fsl_netif0);
  netif_set_up(&fsl_netif0);

  ping_init();

  return 0;
}
Beispiel #18
0
/* Init lwIP TCP/IP stack */
void init_lwip_stack (unsigned int IPaddress, unsigned int NETmask, unsigned int GATEaddress, unsigned char EnDHCP, unsigned char EnAutoIP)
{
	struct ip_addr ip_addr, net_mask, gate_addr;

	/* Initialize all lwIP modules */
	lwip_init ();

	/* Setup static IP values */
	ip_addr.addr	= htonl(IPaddress);
	net_mask.addr	= htonl(NETmask);
	gate_addr.addr	= htonl(GATEaddress);

#if (LWIP_AUTOIP || LWIP_DHCP)
	/* If DHCP or AutoIP is enabled clear IP values */
	if (EnDHCP || EnAutoIP) {
		ip_addr.addr	= 0;
		net_mask.addr	= 0;
		gate_addr.addr	= 0;
	}
#endif

	/* Add a network interface to the list of lwIP netifs */
 	/* use ethernet_input() insted of tcpip_input() */
	netif_add(&enc28j60_netif, &ip_addr, &net_mask, &gate_addr, NULL, ethernetif_init, ip_input);

	/* Set a 'enc28j60_netif' interface as the default network interface */
	netif_set_default(&enc28j60_netif);

#if LWIP_DHCP
	/* Start DHCP if it enabled */
	if (EnDHCP)
		dhcp_start (&enc28j60_netif);
#endif

#if LWIP_AUTOIP
	/* Start AutoIP if it enabled */
	if (EnAutoIP)
		autoip_start (&enc28j60_netif);
#endif

	/* Bring an interface up, available for processing traffic */
	netif_set_up (&enc28j60_netif);
}
Beispiel #19
0
int
main(int argc, char **argv)
{
        struct netif netif;

        /* startup defaults (may be overridden by one or more opts). this is
         * hard-coded v4 even in presence of v6, which does auto-discovery and
         * should thus wind up with an address of fe80::12:34ff:fe56:78ab%tap0
         * */
        IP4_ADDR(&gw, 192,168,113,1);
        IP4_ADDR(&ipaddr, 192,168,113,2);
        IP4_ADDR(&netmask, 255,255,255,0);

        lwip_init();

        printf("TCP/IP initialized.\n");

        netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input);
        netif.flags |= NETIF_FLAG_ETHARP;
        netif_set_default(&netif);
        netif_set_up(&netif);
#if LWIP_IPV6
        netif_create_ip6_linklocal_address(&netif, 1);
#endif

        /* start applications here */

        server_coap_init();

        printf("Applications started.\n");


        while (1) {
                /* poll netif, pass packet to lwIP */
                tapif_select(&netif);

                sys_check_timeouts();

                server_coap_poll();
        }

        return 0;
}
void init_udp() {
	err_t err;
	struct ip_addr ipSend;

	lwip_init();
	pUdpConnection = udp_new();
	IP4_ADDR(&ipSend, 255, 255, 255, 255);

	pUdpConnection->multicast_ip = ipSend;
	pUdpConnection->remote_ip = ipSend;
	pUdpConnection->remote_port = port;

	if(pUdpConnection == NULL) {
		os_printf("\nCould not create new udp socket... \n");
	}
	err = udp_bind(pUdpConnection, IP_ADDR_ANY, port);
	udp_recv(pUdpConnection, handle_udp_recv, pUdpConnection);
	os_timer_disarm(&waitTimer);
}
Beispiel #21
0
void net_init(void) {
	memset(&ipaddr, 0, sizeof(ipaddr));
	memset(&netmask, 0, sizeof(ipaddr));
	memset(&gw, 0, sizeof(ipaddr));

	printf("Initializing network...\n");
	lwip_init();
	printf("lwIP Initialized\n");
	netif_add(&eth, &ipaddr, &netmask, &gw, NULL, gelicif_init, ethernet_input);
	netif_set_default(&eth);
	netif_set_up(&eth);
	printf("Ethernet interface initialized\n");
	printf("Starting DHCP\n");
	dhcp_start(&eth);

	u64 now = gettb();
#if LWIP_TCP
	last_tcp_time = now;
#endif
	last_arp_time = last_dhcp_coarse_time = last_dhcp_fine_time = now;
}
/*
 * 函数名:LWIP_Init
 * 描述  :初始化LWIP协议栈,主要是把enc28j60与LWIP连接起来。
 			包括IP、MAC地址,接口函数
 * 输入  :无
 * 输出  : 无
 * 调用  :外部调用
 */
void LwIP_Init( void )
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;

   /*调用LWIP初始化函数,
   初始化网络接口结构体链表、内存池、pbuf结构体*/
   lwip_init();	
	  
#if LWIP_DHCP			   					//若使用DHCP协议
  ipaddr.addr = 0;
  netmask.addr = 0;
  gw.addr = 0; 
#else										//
  IP4_ADDR(&ipaddr, 192, 168, 1, 18);  		//设置网络接口的ip地址
  IP4_ADDR(&netmask, 255, 255, 255, 0);		//子网掩码
  IP4_ADDR(&gw, 192, 168, 1, 1);			    //网关

#endif
   
  /*初始化enc28j60与LWIP的接口,参数为网络接口结构体、ip地址、
  子网掩码、网关、网卡信息指针、初始化函数、输入函数*/
  netif_add(&enc28j60, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
 
  /*把enc28j60设置为默认网卡 .*/
  netif_set_default(&enc28j60);


#if LWIP_DHCP	   			//若使用了DHCP
  /*  Creates a new DHCP client for this interface on the first call.
  Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
  the predefined regular intervals after starting the client.
  You can peek in the netif->dhcp struct for the actual DHCP status.*/
  dhcp_start(&enc28j60);   	//启动DHCP
#endif

  /*  When the netif is fully configured this function must be called.*/
  netif_set_up(&enc28j60); //使能enc28j60接口
}
Beispiel #23
0
/** \brief LWIP initialization function
 *
 * The followings are executed: */
void Ifx_Lwip_init(const Ifx_Lwip_Config *config)
{
    Ifx_Lwip *lwip = &Ifx_g_Lwip;

    LWIP_DEBUGF(IFX_LWIP_DEBUG, ("Ifx_Lwip_init start!\n"));

    /** - initialise LWIP (lwip_init()) */
    lwip_init();

    /** - initialise and add a \ref netif */
    lwip->eth_addr = config->ethAddr;
    netif_add(&lwip->netif, &config->ipAddr, &config->netMask, &config->gateway,
        (void *)0, ethernetif_tc2x_init, ethernet_input);
    netif_set_default(&lwip->netif);
    netif_set_up(&lwip->netif);

#if 0
    /** - assign \ref dhcp to \ref netif */
    dhcp_set_struct(&lwip->netif, &lwip->dhcp);
    dhcp_start(&lwip->netif);

    LWIP_DEBUGF(IFX_LWIP_DEBUG, ("Ifx_Lwip_init end!\n"));

    {   /** - initialise some network applications (ping, echo, httpd) */
        void ping_init(void);
        void echo_init(void);
        void httpd_init(void);

        //ping_init();
        //echo_init();
        httpd_init();
    }
#endif

    if (sizeof(ip_addr_t) != 4)
    {
        __debug();
    }
}
Beispiel #24
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Configure the BSP */
  BSP_Config();
    
  /* Initilaize the LwIP stack */
  lwip_init();
  
  /* Configure the Network interface */
  Netif_Config();
  
  /* tcp echo server Init */
  udp_echoserver_init();
  
  /* Notify user about the netwoek interface config */
  User_notification(&gnetif);
  
  /* Infinite loop */
  while (1)
  {  
    /* Read a received packet from the Ethernet buffers and send it 
       to the lwIP for handling */
    ethernetif_input(&gnetif);

    /* Handle timeouts */
    sys_check_timeouts();
  }
}
Beispiel #25
0
/* init function */
void MX_LWIP_Init(void)
{  /* Initilialize the LwIP stack */
  lwip_init();
 
 
  ipaddr.addr = 0;
  netmask.addr = 0;
  gw.addr = 0;
  

  /* add the network interface */
#if LWIP_ARP
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
 
 
  /*  Registers the default network interface */
  netif_set_default(&gnetif);

  if (netif_is_link_up(&gnetif))
  {
    /* When the netif is fully configured this function must be called */
    netif_set_up(&gnetif);
  }
  else
  {
    /* When the netif link is down this function must be called */
       netif_set_down(&gnetif);
  }  
  

#endif  /* LWIP_ARP || LWIP_ETHERNET */

dhcp_start(&gnetif);
  

/* USER CODE BEGIN 3 */

/* USER CODE END 3 */
}
Beispiel #26
0
void LwIP_Config (void) 
{
    struct ip_addr ipaddr;
    struct ip_addr netmask;
    struct ip_addr gw;
    
    // 调用LWIP初始化函数
    lwip_init();    
    
    IP4_ADDR(&ipaddr, 192, 168, 1, 16);             // 设置网络接口的ip地址
    IP4_ADDR(&netmask, 255, 255, 255, 0);           // 子网掩码
    IP4_ADDR(&gw, 192, 168, 1, 1);                  // 网关
    
    // 初始化enc28j60与LWIP的接口,参数为网络接口结构体、ip地址、
    // 子网掩码、网关、网卡信息指针、初始化函数、输入函数
    netif_add(&enc28j60, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);
    
    // 把enc28j60设置为默认网卡
    netif_set_default(&enc28j60);
    
    netif_set_up(&enc28j60);
}
Beispiel #27
0
err_t iperf_server_init(void)
{
    int i;
    err_t ret = ERR_OK;
    sys_init();
    lwip_init();
    ticks_sec = rte_get_timer_hz();
    ///////////////////////////////////////////
    ip_addr_t ipaddr, netmask, gateway;

    dpdkif_get_if_params(&ipaddr, &netmask, &gateway, netif.hwaddr);

    netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, dpdkif_init, ethernet_input));

    netif_set_up(&netif);

    rte_eal_remote_launch (dpdkif_rx_thread_func, NULL,1);
   ////////////////////////////////////////////

    for (i = 0; i < sizeof(send_data) / sizeof(*send_data); i++)
        send_data[i] = i;

    struct tcp_pcb *pcb;
    pcb = tcp_new();

    if (pcb == NULL)
        return ERR_MEM;

    if ((ret = tcp_bind(pcb, IP_ADDR_ANY, IPERF_SERVER_PORT)) != ERR_OK) {
        tcp_close(pcb);
        return ret;
    }

    pcb = tcp_listen(pcb);
    tcp_accept(pcb, accept);

    return ret;
}
Beispiel #28
0
void mch_net_init(void)
{
    // Initialize LWIP
    lwip_init();

    mchdrv_netif.hwaddr_len = 6;
    /* demo mac address */
    mchdrv_netif.hwaddr[0] = 0;
    mchdrv_netif.hwaddr[1] = 1;
    mchdrv_netif.hwaddr[2] = 2;
    mchdrv_netif.hwaddr[3] = 3;
    mchdrv_netif.hwaddr[4] = 4;
    mchdrv_netif.hwaddr[5] = 5;

    // Add our netif to LWIP (netif_add calls our driver initialization function)
    if (netif_add(&mchdrv_netif, &mch_myip_addr, &netmask, &gw_addr, &mchdrv_hw,
                mchdrv_init, ethernet_input) == NULL) {
        LWIP_ASSERT("mch_net_init: netif_add (mchdrv_init) failed\n", 0);
    }

    netif_set_default(&mchdrv_netif);
    netif_set_up(&mchdrv_netif);
}
Beispiel #29
0
/**
 * @brief	main routine for example_lwip_tcpecho_sa_18xx43xx
 * @return	Function should not exit.
 */
int main(void)
{
	uint32_t physts;
	ip_addr_t ipaddr, netmask, gw;

	prvSetupHardware();

	/* Initialize LWIP */
	lwip_init();

	LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP TCP echo server...\n"));

	/* Static IP assignment */
#if LWIP_DHCP
	IP4_ADDR(&gw, 0, 0, 0, 0);
	IP4_ADDR(&ipaddr, 0, 0, 0, 0);
	IP4_ADDR(&netmask, 0, 0, 0, 0);
#else
	IP4_ADDR(&gw, 10, 1, 10, 1);
	IP4_ADDR(&ipaddr, 10, 1, 10, 234);
	IP4_ADDR(&netmask, 255, 255, 255, 0);
	APP_PRINT_IP(&ipaddr);
#endif

	/* Add netif interface for lpc17xx_8x */
	netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init,
			  ethernet_input);
	netif_set_default(&lpc_netif);
	netif_set_up(&lpc_netif);

#if LWIP_DHCP
	dhcp_start(&lpc_netif);
#endif

	/* Initialize and start application */
	echo_init();

	/* This could be done in the sysTick ISR, but may stay in IRQ context
	   too long, so do this stuff with a background loop. */
	while (1) {
		/* Handle packets as part of this loop, not in the IRQ handler */
		lpc_enetif_input(&lpc_netif);

		/* lpc_rx_queue will re-qeueu receive buffers. This normally occurs
		   automatically, but in systems were memory is constrained, pbufs
		   may not always be able to get allocated, so this function can be
		   optionally enabled to re-queue receive buffers. */
#if 0
		while (lpc_rx_queue(&lpc_netif)) {}
#endif

		/* Free TX buffers that are done sending */
		lpc_tx_reclaim(&lpc_netif);

		/* LWIP timers - ARP, DHCP, TCP, etc. */
		sys_check_timeouts();

		/* Call the PHY status update state machine once in a while
		   to keep the link status up-to-date */
		physts = lpcPHYStsPoll();

		/* Only check for connection state when the PHY status has changed */
		if (physts & PHY_LINK_CHANGED) {
			if (physts & PHY_LINK_CONNECTED) {
				Board_LED_Set(0, true);

				/* Set interface speed and duplex */
				if (physts & PHY_LINK_SPEED100) {
					Chip_ENET_SetSpeed(LPC_ETHERNET, 1);
					NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000);
				}
				else {
					Chip_ENET_SetSpeed(LPC_ETHERNET, 0);
					NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000);
				}
				if (physts & PHY_LINK_FULLDUPLX) {
					Chip_ENET_SetDuplex(LPC_ETHERNET, true);
				}
				else {
					Chip_ENET_SetDuplex(LPC_ETHERNET, false);
				}

				netif_set_link_up(&lpc_netif);
			}
			else {
				Board_LED_Set(0, false);
				netif_set_link_down(&lpc_netif);
			}

			DEBUGOUT("Link connect status: %d\r\n", ((physts & PHY_LINK_CONNECTED) != 0));
		}
	}

	/* Never returns, for warning only */
	return 0;
}
Beispiel #30
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Configure Key Button */      
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);  
  
  /* Test if Key push-button is not pressed */
  if (BSP_PB_GetState(BUTTON_KEY) != 0x00)
  { /* Key push-button not pressed: jump to user application */
    
    /* Check if valid stack address (RAM address) then jump to user application */
    if (((*(__IO uint32_t*)USER_FLASH_FIRST_PAGE_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
    {
      /* Jump to user application */
      JumpAddress = *(__IO uint32_t*) (USER_FLASH_FIRST_PAGE_ADDRESS + 4);
      Jump_To_Application = (pFunction) JumpAddress;
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) USER_FLASH_FIRST_PAGE_ADDRESS);
      Jump_To_Application();
      /* do nothing */
      while(1);
    }
    else
    {/* Otherwise, do nothing */
      /* LED3 (RED) ON to indicate bad software (when not valid stack address) */
      BSP_LED_Init(LED3);
      BSP_LED_On(LED3);
      /* do nothing */
      while(1);
    }
  }
  /* Enter in IAP mode */
  else
  {
    /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
    HAL_Init();  
    
    /* Configure the system clock to 168 MHz */
    SystemClock_Config();
    
    /* Configure the BSP */
    BSP_Config();
    
    /* Initialize the LwIP stack */
    lwip_init();
    
    /* Configure the Network interface */
    Netif_Config();
    
#ifdef USE_IAP_HTTP
    /* Initialize the webserver module */
    IAP_httpd_init();
#endif
    
#ifdef USE_IAP_TFTP    
    /* Initialize the TFTP server */
    IAP_tftpd_init();
#endif  
    
    /* Notify user about the network interface config */
    User_notification(&gnetif);
    
    /* Infinite loop */
    while (1)
    {
    /* Read a received packet from the Ethernet buffers and send it 
       to the lwIP for handling */
    ethernetif_input(&gnetif);

    /* Handle timeouts */
    sys_check_timeouts();

#ifdef USE_DHCP
    /* handle periodic timers for LwIP */
    DHCP_Periodic_Handle(&gnetif);
#endif 
    }
  }
}