/** * @brief Strart thread * @param argument not used * @retval None */ static void StartThread(void const * argument) { /* Initialize LCD and LEDs */ BSP_Config(); /* Create tcp_ip stack thread */ tcpip_init( NULL, NULL ); /* Initilaize the LwIP stack */ Netif_Config(); /* Initialize webserver demo */ http_server_netconn_init(); /* Notify user about the netwoek interface config */ User_notification(&gnetif); #ifdef USE_DHCP /* Start DHCPClient */ osThreadDef(DHCP, DHCP_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE * 2); osThreadCreate (osThread(DHCP), &gnetif); #endif /* Start toogleLed4 task : Toggle LED4 every 250ms */ osThreadDef(LED4, ToggleLed4, osPriorityLow, 0, configMINIMAL_STACK_SIZE); osThreadCreate (osThread(LED4), NULL); for( ;; ) { /* Delete the Init Thread */ osThreadTerminate(NULL); } }
/* 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 }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured to 120 MHz, this is done through SystemInit() function which is called from startup file (startup_stm32f2xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f2xx.c file */ //add a long delay wait for DP83848 finish reset unsigned int i,j; for(i=0;i<36;i++) { for(j=0;j < 65500;j++); } #ifdef SERIAL_DEBUG DebugComPort_Init(); #endif /*Initialize LCD and Leds */ LCD_LED_Init(); /* configure ethernet (GPIOs, clocks, MAC, DMA) */ ETH_BSP_Config(); /* Initilaize the LwIP stack */ LwIP_Init(); /* Initialize webserver demo */ http_server_netconn_init(); #ifdef USE_DHCP /* Start DHCPClient */ xTaskCreate(LwIP_DHCP_task, "DHCPClient", configMINIMAL_STACK_SIZE * 2, NULL,DHCP_TASK_PRIO, NULL); #endif /* Start toogleLed4 task : Toggle LED4 every 250ms */ xTaskCreate(ToggleLed4, "LED4", configMINIMAL_STACK_SIZE, NULL, LED_TASK_PRIO, NULL); /* Start scheduler */ vTaskStartScheduler(); /* We should never get here as control is now taken by the scheduler */ for( ;; ); }
int main(int argc,char *argv[]) { struct tapif tapif[NETIF_MAX]; struct netif netif[NETIF_MAX]; int ch; int n = 0; memset(tapif,0,sizeof(tapif)); memset(netif,0,sizeof(netif)); tcpip_init(NULL,NULL); #ifdef LWIP_DEBUG while ((ch = getopt(argc,argv,"CEHdhi:")) != -1) { #else while ((ch = getopt(argc,argv,"CEHhi:")) != -1) { #endif switch (ch) { case 'C': chargen_init(); break; case 'E': udpecho_init(); tcpecho_init(); break; case 'H': http_server_netconn_init(); break; #ifdef LWIP_DEBUG case 'd': debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE| LWIP_DBG_FRESH|LWIP_DBG_HALT); break; #endif case 'i': if (n >= NETIF_MAX) break; if (parse_interface(&tapif[n],optarg) != 0) help(); netif_add(&netif[n], IP4_OR_NULL(tapif[n].ip_addr), IP4_OR_NULL(tapif[n].netmask), IP4_OR_NULL(tapif[n].gw), &tapif[n], tapif_init, tcpip_input); if (n == 0) netif_set_default(&netif[n]); netif_set_up(&netif[n]); if (IP4_OR_NULL(tapif[n].ip_addr) == 0 && IP4_OR_NULL(tapif[n].netmask) == 0 && IP4_OR_NULL(tapif[n].gw) == 0) dhcp_start(&netif[n]); n++; break; case 'h': default: help(); } } argc -= optind; argv += optind; if (n <= 0) help(); pause(); return -1; }
/* LWIP kickoff and PHY link monitor thread */ static void vSetupIFTask(void *pvParameters) { ip_addr_t ipaddr, netmask, gw; volatile s32_t tcpipdone = 0; uint32_t physts; static int prt_ip = 0; DEBUGSTR("LWIP HTTP Web Server FreeRTOS Demo...\r\n"); /* Wait until the TCP/IP thread is finished before continuing or wierd things may happen */ DEBUGSTR("Waiting for TCPIP thread to initialize...\r\n"); tcpip_init(tcpip_init_done_signal, (void *) &tcpipdone); while (!tcpipdone) { msDelay(1); } DEBUGSTR("Starting LWIP HTTP server...\r\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); #endif /* Add netif interface for lpc17xx_8x */ memset(&lpc_netif, 0, sizeof(lpc_netif)); if (!netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init, tcpip_input)) { DEBUGSTR("Net interface failed to initialize\r\n"); while(1); } netif_set_default(&lpc_netif); netif_set_up(&lpc_netif); /* Enable MAC interrupts only after LWIP is ready */ NVIC_SetPriority(ETHERNET_IRQn, config_ETHERNET_INTERRUPT_PRIORITY); NVIC_EnableIRQ(ETHERNET_IRQn); #if LWIP_DHCP dhcp_start(&lpc_netif); #endif /* Initialize and start application */ http_server_netconn_init(); /* This loop monitors the PHY link and will handle cable events via the PHY driver. */ while (1) { /* 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); prt_ip = 0; /* Set interface speed and duplex */ if (physts & PHY_LINK_SPEED100) { Chip_ENET_Set100Mbps(LPC_ETHERNET); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 100000000); } else { Chip_ENET_Set10Mbps(LPC_ETHERNET); NETIF_INIT_SNMP(&lpc_netif, snmp_ifType_ethernet_csmacd, 10000000); } if (physts & PHY_LINK_FULLDUPLX) { Chip_ENET_SetFullDuplex(LPC_ETHERNET); } else { Chip_ENET_SetHalfDuplex(LPC_ETHERNET); } tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up, (void *) &lpc_netif, 1); } else { Board_LED_Set(0, false); tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down, (void *) &lpc_netif, 1); } /* Delay for link detection (250mS) */ vTaskDelay(configTICK_RATE_HZ / 4); } /* Print IP address info */ if (!prt_ip) { if (lpc_netif.ip_addr.addr) { static char tmp_buff[16]; DEBUGOUT("IP_ADDR : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.ip_addr, tmp_buff, 16)); DEBUGOUT("NET_MASK : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.netmask, tmp_buff, 16)); DEBUGOUT("GATEWAY_IP : %s\r\n", ipaddr_ntoa_r((const ip_addr_t *) &lpc_netif.gw, tmp_buff, 16)); prt_ip = 1; } } } }
/** \brief LWIP kickoff and PHY link monitor thread \param[in] pvParameters Not used \return Does not return */ static portTASK_FUNCTION( vSetupIFTask, pvParameters ) { ip_addr_t ipaddr, netmask, gw; volatile s32_t tcpipdone = 0; /* Wait until the TCP/IP thread is finished before continuing or wierd things may happen */ LWIP_DEBUGF(LWIP_DBG_ON, ("Waiting for TCPIP thread to initialize...\n")); tcpip_init(tcpip_init_done_signal, &tcpipdone); while (!tcpipdone); LWIP_DEBUGF(LWIP_DBG_ON, ("Starting LWIP HTTP 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 */ memset(lpc_netif, 0, sizeof(lpc_netif)); if (!netif_add(&lpc_netif, &ipaddr, &netmask, &gw, NULL, lpc_enetif_init, ethernet_input)) LWIP_ASSERT("Net interface failed to initialize\r\n", 0); netif_set_default(&lpc_netif); netif_set_up(&lpc_netif); /* Enable MAC interrupts */ NVIC_SetPriority(ENET_IRQn, ((0x01 << 3) | 0x01)); NVIC_EnableIRQ(ENET_IRQn); #if LWIP_DHCP dhcp_start(&lpc_netif); #endif /* Initialize and start application */ http_server_netconn_init(); /* This loop monitors the PHY link and will handle cable events via the PHY driver. */ while (1) { /* Call the PHY status update state machine once in a while to keep the link status up-to-date */ if (lpc_phy_sts_sm(&lpc_netif) != 0) { /* Set the state of the LED to on if the ethernet link is active or off is disconnected. */ if (lpc_netif.flags & NETIF_FLAG_LINK_UP) led_set(1); else led_set(0); } /* Non-blocking delay for link detection */ msDelay(250); } }
int main(void) { printf("Calling httpserver\n"); http_server_netconn_init(); printf("Called httpserver\n"); return 0; }
/* This function initializes applications */ static void apps_init(void) { #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 netbiosns_init(); #ifndef NETBIOS_LWIP_NAME #if LWIP_NETIF_HOSTNAME netbiosns_set_name(netif_default->hostname); #else netbiosns_set_name("NETBIOSLWIPDEV"); #endif #endif #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_MDNS_RESPONDER mdns_resp_init(); #if LWIP_NETIF_HOSTNAME mdns_resp_add_netif(netif_default, netif_default->hostname, 3600); #else mdns_resp_add_netif(netif_default, "lwip", 3600); #endif mdns_resp_add_service(netif_default, "lwipweb", "_http", DNSSD_PROTO_TCP, HTTPD_SERVER_PORT, 3600, srv_txt, NULL); #endif #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) */ tcpecho_raw_init(); #endif #endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */ #if LWIP_UDPECHO_APP && LWIP_NETCONN udpecho_init(); #endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */ #if LWIP_LWIPERF_APP lwiperf_start_tcp_server_default(lwiperf_report, NULL); #endif #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 }