/* This function initializes applications */ static void apps_init() { #if LWIP_DNS_APP && LWIP_DNS /* wait until the netif is up (for dhcp, autoip or ppp) */ sys_timeout(5000, dns_dorequest, NULL); #endif /* LWIP_DNS_APP && LWIP_DNS */ #if LWIP_CHARGEN_APP && LWIP_SOCKET chargen_init(); #endif /* LWIP_CHARGEN_APP && LWIP_SOCKET */ #if LWIP_PING_APP && LWIP_RAW && LWIP_ICMP ping_init(); #endif /* LWIP_PING_APP && LWIP_RAW && LWIP_ICMP */ #if LWIP_NETBIOS_APP && LWIP_UDP netbios_init(); #endif /* LWIP_NETBIOS_APP && LWIP_UDP */ #if LWIP_HTTPD_APP && LWIP_TCP #ifdef LWIP_HTTPD_APP_NETCONN http_server_netconn_init(); #else /* LWIP_HTTPD_APP_NETCONN */ httpd_init(); #endif /* LWIP_HTTPD_APP_NETCONN */ #endif /* LWIP_HTTPD_APP && LWIP_TCP */ #if LWIP_NETIO_APP && LWIP_TCP netio_init(); #endif /* LWIP_NETIO_APP && LWIP_TCP */ #if LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP rtp_init(); #endif /* LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP */ #if LWIP_SNTP_APP && LWIP_SOCKET sntp_init(); #endif /* LWIP_SNTP_APP && LWIP_SOCKET */ #if LWIP_SHELL_APP && LWIP_NETCONN shell_init(); #endif /* LWIP_SHELL_APP && LWIP_NETCONN */ #if LWIP_TCPECHO_APP #if LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) tcpecho_init(); #else /* LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) */ echo_init(); #endif #endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */ #if LWIP_UDPECHO_APP && LWIP_NETCONN udpecho_init(); #endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */ #if LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET socket_examples_init(); #endif /* LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET */ #ifdef LWIP_APP_INIT LWIP_APP_INIT(); #endif }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { sys_read_cfg(); if(!syscfg.cfg.b.debug_print_enable) system_set_os_print(0); uart_init(); #if USE_TMP2NET_PORT GPIO0_MUX = 0; #else GPIO0_MUX = VAL_MUX_GPIO0_SDK_DEF; #endif GPIO4_MUX = VAL_MUX_GPIO4_SDK_DEF; GPIO5_MUX = VAL_MUX_GPIO5_SDK_DEF; GPIO12_MUX = VAL_MUX_GPIO12_SDK_DEF; GPIO14_MUX = VAL_MUX_GPIO14_SDK_DEF; system_timer_reinit(); #if DEBUGSOO > 0 os_printf("\nSimple WEB version: " WEB_SVERSION "\nOpenLoaderSDK v1.2\n"); #endif if(syscfg.cfg.b.pin_clear_cfg_enable) test_pin_clr_wifi_config(); set_cpu_clk(); // select cpu frequency 80 or 160 MHz #if DEBUGSOO > 0 if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); #endif #if DEBUGSOO > 0 os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); #endif Setup_WiFi(); #if USE_TMP2NET_PORT tpm2net_init(); #endif #ifdef USE_NETBIOS if(syscfg.cfg.b.netbios_ena) netbios_init(); #endif /* #ifdef USE_SNTP if(syscfg.cfg.b.sntp_ena) sntp_init(); #endif */ #ifdef UDP_TEST_PORT if(syscfg.udp_port) udp_test_port_init(syscfg.udp_port); #endif // инициализация и запуск tcp серверa(ов) #ifdef USE_SRV_WEB_PORT if(syscfg.web_port) webserver_init(syscfg.web_port); #endif /// if(syscfg.tcp2uart_port) tcp2uart_init(syscfg.tcp2uart_port); #ifdef USE_MODBUS mdb_tcp_init(502); #endif #ifdef USE_WDRV init_wdrv(); #endif system_deep_sleep_set_option(0); system_init_done_cb(init_done_cb); }
LW_API VOID API_INetNetBiosInit (VOID) { static BOOL bIsInit = LW_FALSE; void netbios_init(void); if (bIsInit) { return; } else { bIsInit = LW_TRUE; } netbios_init(); #if LW_CFG_SHELL_EN > 0 API_TShellKeywordAdd("nbname", __inetBiosNameSet); API_TShellFormatAdd("nbname", " [local host name]"); API_TShellHelpAdd("nbname", "set local host name(NetBIOS).\n"); #endif }
//***************************************************************************** // //! Initializes the lwIP TCP/IP stack. //! //! \param pucMAC is a pointer to a six byte array containing the MAC //! address to be used for the interface. //! \param ulIPAddr is the IP address to be used (static). //! \param ulNetMask is the network mask to be used (static). //! \param ulGWAddr is the Gateway address to be used (static). //! \param ulIPMode is the IP Address Mode. \b IPADDR_USE_STATIC will force //! static IP addressing to be used, \b IPADDR_USE_DHCP will force DHCP with //! fallback to Link Local (Auto IP), while \b IPADDR_USE_AUTOIP will force //! Link Local only. //! //! This function performs initialization of the lwIP TCP/IP stack for the //! Stellaris Ethernet MAC, including DHCP and/or AutoIP, as configured. //! //! \return None. // //***************************************************************************** void LWIPServiceTaskInit(void *pvParameters) { struct ip_addr *ip_addr; struct ip_addr *net_mask; struct ip_addr *gw_addr; //struct ip_addr ip_addr_local; //struct ip_addr net_mask_local; char IPState = 0; char* configLoad; IP_CONFIG * ipCfg; printf("Initialisiere IP "); ipCfg = pvPortMalloc(sizeof(IP_CONFIG)); configLoad = loadFromConfig(IP_CONFIG_FILE, "USE_DHCP"); #ifdef ENABLE_GRAPHIC vShowBootText("load ipconfig ..."); #endif printf("LWIPSTACK: LOAD CONFIG: (%s)\n", configLoad); if (configLoad == 0) { IPState = IPADDR_USE_AUTOIP; } else if (strcmp(configLoad, "true") == 0) { IPState = IPADDR_USE_DHCP; } else { IPState = IPADDR_USE_STATIC; } vPortFree(configLoad); // Start the TCP/IP thread & init stuff tcpip_init(NULL, NULL); vTaskDelay(100 / portTICK_RATE_MS); // Setup the network address values. if (IPState == IPADDR_USE_STATIC) { ip_addr = getAddresFromConfig("IP_ADDRESS"); net_mask = getAddresFromConfig("IP_SUBNETMASK"); gw_addr = getAddresFromConfig("IP_GATEWAY"); } #if LWIP_DHCP || LWIP_AUTOIP else { ip_addr = pvPortMalloc(sizeof(struct ip_addr)); net_mask = pvPortMalloc(sizeof(struct ip_addr)); gw_addr = pvPortMalloc(sizeof(struct ip_addr)); } #endif // Create, configure and add the Ethernet controller interface with // default settings. // WARNING: This must only be run after the OS has been started. // Typically this is the case, however, if not, you must place this // in a post-OS initialization // @SEE http://lwip.wikia.com/wiki/Initialization_using_tcpip.c printf("Starting NETIF ... \n"); #ifdef ENABLE_GRAPHIC vShowBootText("starting Network ..."); #endif netif_add(&lwip_netif, ip_addr, net_mask, gw_addr, NULL, ethernetif_init, tcpip_input); netif_set_default(&lwip_netif); printf("NETIF UP\n"); // Start DHCP, if enabled. #if LWIP_DHCP if (IPState == IPADDR_USE_DHCP) { #ifdef ENABLE_GRAPHIC vShowBootText("waiting for DHCP ..."); #endif printf("Starte DHCP Client ... "); if (dhcp_start(&lwip_netif) == ERR_OK) { printf("[ok]\n"); } else { printf("[fail]\n"); } } #endif // Start AutoIP, if enabled and DHCP is not. #if LWIP_AUTOIP if (IPState == IPADDR_USE_AUTOIP) { printf ("Setzte Auto IP (NICHT DHCP) ...\n"); autoip_start(&lwip_netif); } #endif if (IPState == IPADDR_USE_STATIC) { // Bring the interface up. netif_set_up(&lwip_netif); } vTaskDelay(1000 / portTICK_RATE_MS); while (0 == netif_is_up(&lwip_netif)) { vTaskDelay(5000 / portTICK_RATE_MS); if (0 == netif_is_up(&lwip_netif)) { dhcp_renew(&lwip_netif); } } printnetif(&lwip_netif); configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_SERVER"); if (strcmp(configLoad, "true") == 0) { /* Initialize HTTP, DNS, SNTP */ printf("HTTPD Starten ...\n"); httpd_init(); } vPortFree(configLoad); #if ENABLE_SNTP printf("SNTP Starten ...\n"); sntp_init(); #endif #if ENABLE_DNS printf("DNS Starten ...\n"); dns_init(); #endif #if ENABLE_NET_BIOS printf("NETBIOS Starten ...\n"); netbios_init(); #endif printf("Dienste gestartet ...\n"); #ifdef ENABLE_GRAPHIC configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT"); if (strcmp(configLoad, "true") == 0) { vShowBootText("loading menu ..."); vLoadMenu(); } else { vShowBootText("ready for requests ..."); } vPortFree(configLoad); #endif // Nothing else to do. No point hanging around. while (1) { vTaskDelay(500 / portTICK_RATE_MS); if (EthernetPHYRead(ETH_BASE, PHY_MR1) & ETH_PHY_LINK_UP) { if (!(netif_is_up(&lwip_netif))) { // set link up flag netif_set_up(&lwip_netif); #ifdef ENABLE_GRAPHIC vShowBootText("activate networkinterface ..."); configLoad = loadFromConfig(IP_CONFIG_FILE, "IS_CLIENT"); if (strcmp(configLoad, "true") == 0) { vShowBootText("loading menu ..."); vLoadMenu(); } else { vShowBootText("ready for requests ..."); } vPortFree(configLoad); #endif if (IPState == IPADDR_USE_DHCP) { printf("DHCP Adresse anfordern ... "); if (dhcp_renew(&lwip_netif) == ERR_OK) { printf("[ok]\n"); printnetif(&lwip_netif); } else { printf("[fail]\n"); } } } } else { if (netif_is_up(&lwip_netif)) { #ifdef ENABLE_GRAPHIC vShowBootText("no networkconnection!!"); #endif printf("Deaktiviere Netzwerkinterface ... "); netif_set_down(&lwip_netif); } } } }
void Network::Spin() { // Basically we can't do anything if we can't interact with LWIP if (!LockLWIP()) { platform->ClassReport(longWait); return; } if (state == NetworkActive) { // See if we can read any packets if (readingData) { readingData = false; do { // read all queued packets from the RX buffer } while (ethernet_read()); ethernet_set_rx_callback(&emac_read_packet); } // See if we can send anything NetworkTransaction *r = writingTransactions; if (r != NULL && r->Send()) { // We're done, free up this transaction ConnectionState *cs = r->cs; NetworkTransaction *rn = r->nextWrite; writingTransactions = r->next; AppendTransaction(&freeTransactions, r); // If there is more data to write on this connection, do it next time if (cs != NULL) { cs->sendingTransaction = rn; } if (rn != NULL) { PrependTransaction(&writingTransactions, rn); } } } else if (state == NetworkInitializing && establish_ethernet_link()) { start_ethernet(platform->IPAddress(), platform->NetMask(), platform->GateWay()); ethernet_set_rx_callback(&emac_read_packet); httpd_init(); ftpd_init(); telnetd_init(); netbios_init(); state = NetworkActive; } UnlockLWIP(); platform->ClassReport(longWait); }
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; }