/************************************************************************* * * * host.c Functions used to set up the lwIP interface * * tcp_timeout() TCP timeout * * tcpip_init_done() Signals lwIP init completion semaphore * * main_thread() System-dependant initialization function * * HostUp() Top-level function for lwIP initialization * * * * Modified by Nancy Minderman October 25, 2004 * * Changes--Updated code to work with LWIP 0.7.2 * * * *************************************************************************/ #include "lwip/debug.h" #include "lwip/opt.h" #include "lwip/mem.h" #include "lwip/memp.h" #include "lwip/sys.h" #include "lwip/stats.h" #include "lwip/tcpip.h" #include "lwip/loopif.h" #include "lwip/slipif.h" #include "lwip/netif.h" #include "lwip/ip_addr.h" #include "lwip/perf.h" #include "io/io.h" #include "net_apps/httpd.h" #include "net_apps/tcpecho.h" #include "net_apps/statserv.h" #define htons(x) (x) #define ntohs(x) (x) #define htonl(x) (x) #define ntohl(x) (x) /*-----------------------------------------------------------------------*/ void init_client(void); static void client_thread(void *arg); static void tcp_timeout(void *data) { #if TCP_DEBUG tcp_debug_print_pcbs(); #endif /* TCP_DEBUG */ sys_timeout(5000, tcp_timeout, NULL); } /*-----------------------------------------------------------------------*/ static void tcpip_init_done(void *arg) { sys_sem_t *sem; sem = arg; sys_sem_signal(*sem); } /*-----------------------------------------------------------------------*/ static void main_thread(void *arg) { struct ip_addr ipaddr, netmask, gw; sys_sem_t sem; struct netif * loop_netif; struct netif * loop_ret_netif ; struct netif * slip_netif; struct netif * slip_ret_netif ; /* Initialize the network interface driver */ netif_init(); /* Initialize the lwIP stack */ sem = sys_sem_new(0); /* create temporary semaphore */ tcpip_init(tcpip_init_done, &sem); /* start initializing lwIP */ sys_sem_wait(sem); /* wait for completion */ sys_sem_free(sem); /* recycle semaphore */ outstr("LWIP 0.7.2 Loaded\n\r"); /* allocate loopback netif structure */ loop_netif = mem_malloc(sizeof(struct netif)); if (loop_netif == NULL) { outstr("host.c main_thread out of memory for netif loopback\n"); } /* Install loopback interface */ IP4_ADDR(&gw, 127,0,0,1); /* define gateway (Linux PC) */ IP4_ADDR(&ipaddr, 127,0,0,1); /* define local IP address */ IP4_ADDR(&netmask, 255,0,0,0); /* set IP mask */ loop_ret_netif = netif_add(loop_netif, &ipaddr, &netmask, &gw, NULL, loopif_init, tcpip_input); outstr("Loopback Interface Up 127.0.0.1\n\r"); /* allocate slip netif structure */ slip_netif = mem_malloc(sizeof(struct netif)); if (slip_netif == NULL) { outstr("host.c main_thread out of memory for netif slip\n"); } /* Install SLIP interface */ IP4_ADDR(&gw, 10,0,0,1); /* define gateway (Linux PC) */ IP4_ADDR(&ipaddr, 10,0,0,2); /* define local IP address */ IP4_ADDR(&netmask, 255,255,255,0); /* set IP mask */ netif_set_default(slip_ret_netif = netif_add(slip_netif, &ipaddr, &netmask, &gw, NULL, slipif_init, tcpip_input)); outstr("SLIP Interface Up 10.0.0.2\n\r"); /* Create all server threads/tasks */ tcpecho_init(); //statserv_init(); //httpd_init(); outstr("Network Initialized\n\r"); /* confirm successful initialization */ /* terminate this thread/task */ OSTaskDel(OS_PRIO_SELF); outstr("ERROR - main TCP/IP thread returned!\n\r"); } /*-------------------------------------------------------------------------*/ void HostUp(void) { sys_init(); mem_init(); memp_init(); pbuf_init(); sys_thread_new((void *)(main_thread), NULL, 0); } /*-------------------------------------------------------------------------*/