struct netif * LwIP_Init() { uint8_t macaddress[6] = ETH_MAC_ADDR; struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; /* Create isr for ethernet interrupt */ TaskType tid; tid = Os_Arc_CreateIsr(Eth_Isr,3/*prio*/,"Eth"); \ Irq_AttachIsr2(tid,NULL,ETH_IRQn); \ /* Configure ethernet */ Ethernet_Configuration(); #if NO_SYS #if (MEM_LIBC_MALLOC==0) mem_init(); #endif #if (MEMP_MEM_MALLOC==0) memp_init(); #endif #else pre_sys_init(); tcpip_init(tcpip_init_done, NULL); uint32 lockcnt = 0; while(tcpip_initialized == FALSE){ lockcnt++; SLEEP(0); }; #endif #if LWIP_DHCP ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; #else GET_BOOT_IPADDR; GET_BOOT_NETMASK; GET_BOOT_GW; #endif Set_MAC_Address(macaddress); /* Add network interface to the netif_list */ netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, &tcpip_input); /* Registers the default network interface.*/ netif_set_default(&netif); #if LWIP_DHCP /* start dhcp search */ dhcp_start(&netif); #else netif_set_addr(&netif, &ipaddr , &netmask, &gw); #endif /* netif is configured */ netif_set_up(&netif); EnableEthDMAIrq(); netbios_init(); return &netif; }
/** * @brief Initializes the lwIP stack * @param None * @retval None */ void LwIP_Init(void) { struct ip_addr ipaddr; //struct ip_addr netmask; //struct ip_addr gw; uint8_t macaddress[6]={0,0,0,0,0,1}; /* Initializes the dynamic memory heap defined by MEM_SIZE.*/ mem_init(); /* Initializes the memory pools defined by MEMP_NUM_x.*/ memp_init(); #if LWIP_DHCP ip_ipaddr.addr = 0; ip_netmask.addr = 0; ip_gw.addr = 0; /* Configure the board opeartin mode: Client/Server */ #else //IP4_ADDR(&ipaddr, 200,200,2,95); // 10.1.1.8 // 200,200,2, 95 // //IP4_ADDR(&netmask, 255, 255, 255, 0); //IP4_ADDR(&gw, 10, 1, 1, 1); //10, 1,1, 1 #endif Set_MAC_Address(macaddress); /* - netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif)) Adds your network interface to the netif_list. Allocate a struct netif and pass a pointer to this structure as the first argument. Give pointers to cleared ip_addr structures when using DHCP, or fill them with sane numbers otherwise. The state pointer may be NULL. The init function pointer must point to a initialization function for your ethernet netif interface. The following code illustrates it's use.*/ netif_add(&netif, &ip_ipaddr, &ip_netmask, &ip_gw, NULL, ðernetif_init, ðernet_input); /* Registers the default network interface.*/ netif_set_default(&netif); #if LWIP_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(&netif); #endif /* When the netif is fully configured this function must be called.*/ netif_set_up(&netif); }
/** * @brief Initializes the lwIP stack * @param None * @retval None */ void LwIP_Init(void) { struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; uint8_t macaddress[6]={0,0,0,0,0,1}; /* Initializes the dynamic memory heap defined by MEM_SIZE.*/ mem_init(); /* Initializes the memory pools defined by MEMP_NUM_x.*/ memp_init(); #if LWIP_DHCP ipaddr.addr = 0; netmask.addr = 0; gw.addr = 0; /* Configure the board opeartin mode: Client/Server */ LCD_DisplayStringLine(Line5, " Keep Key button "); LCD_DisplayStringLine(Line6, "pressed to activate "); LCD_DisplayStringLine(Line7, " the server "); Delay(KEY_DELAY); if(!STM_EVAL_PBGetState(Button_KEY)) { Server = SELECTED; LCD_DisplayStringLine(Line5, " "); LCD_DisplayStringLine(Line6, " Server selected "); LCD_DisplayStringLine(Line7, " "); Delay(LCD_DELAY); } else { macaddress[5]=CLIENTMAC6; Server = NOT_SELECTED; LCD_DisplayStringLine(Line5, " "); LCD_DisplayStringLine(Line6, " Client selected "); LCD_DisplayStringLine(Line7, " "); Delay(LCD_DELAY); } #else IP4_ADDR(&ipaddr, 192, 168, 0, 8); IP4_ADDR(&netmask, 255, 255, 255, 0); IP4_ADDR(&gw, 192, 168, 0, 1); #endif Set_MAC_Address(macaddress); /* - netif_add(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw, void *state, err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif)) Adds your network interface to the netif_list. Allocate a struct netif and pass a pointer to this structure as the first argument. Give pointers to cleared ip_addr structures when using DHCP, or fill them with sane numbers otherwise. The state pointer may be NULL. The init function pointer must point to a initialization function for your ethernet netif interface. The following code illustrates it's use.*/ netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ðernetif_init, ðernet_input); /* Registers the default network interface.*/ netif_set_default(&netif); #if LWIP_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(&netif); #endif /* When the netif is fully configured this function must be called.*/ netif_set_up(&netif); }