]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/lwIP/lwIP_Apps/lwIP_Apps.c
Remove unnecessary files from the MicroBlaze http server file system creation directory.
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / lwIP / lwIP_Apps / lwIP_Apps.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /* lwIP core includes */\r
55 #include "lwip/opt.h"\r
56 #include "lwip/sys.h"\r
57 #include "lwip/timers.h"\r
58 #include "lwip/debug.h"\r
59 #include "lwip/stats.h"\r
60 #include "lwip/init.h"\r
61 #include "lwip/tcpip.h"\r
62 #include "lwip/netif.h"\r
63 #include "lwip/tcp.h"\r
64 #include "lwip/udp.h"\r
65 #include "lwip/dns.h"\r
66 #include "lwip/dhcp.h"\r
67 #include "lwip/autoip.h"\r
68 \r
69 /* lwIP netif includes */\r
70 #include "netif/etharp.h"\r
71 \r
72 /* applications includes */\r
73 #include "apps/httpserver_raw/httpd.h"\r
74 #include "apps/httpserver/httpserver-netconn.h"\r
75 #include "apps/netio/netio.h"\r
76 #include "apps/netbios/netbios.h"\r
77 #include "apps/ping/ping.h"\r
78 #include "apps/rtp/rtp.h"\r
79 #include "apps/sntp/sntp.h"\r
80 #include "apps/chargen/chargen.h"\r
81 #include "apps/shell/shell.h"\r
82 #include "apps/tcpecho/tcpecho.h"\r
83 #include "apps/udpecho/udpecho.h"\r
84 #include "apps/tcpecho_raw/echo.h"\r
85 #include "apps/socket_examples/socket_examples.h"\r
86 \r
87 /* include the port-dependent configuration */\r
88 #include "lwipcfg_msvc.h"\r
89 \r
90 static struct netif netif;\r
91 \r
92 static void apps_init( void );\r
93 \r
94 #define ssiTASK_STATS_INDEX                     0\r
95 #define ssiRUN_TIME_STATS_INDEX         1\r
96 \r
97 \r
98 /*\r
99  * The SSI handler callback function passed to lwIP.\r
100  */\r
101 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );\r
102 \r
103 \r
104 /* The SSI strings that are embedded in the served html files. */\r
105 static const char *pccSSITags[] = \r
106 {\r
107         "rtos_stats",\r
108         "run_stats"\r
109 };\r
110 \r
111 \r
112 /* Called from the TCP/IP thread. */\r
113 void lwIPAppsInit( void *pvArgument )\r
114 {\r
115 ip_addr_t ipaddr, netmask, gw;\r
116 extern err_t ethernetif_init( struct netif *netif );\r
117 \r
118         ( void ) pvArgument;\r
119 \r
120         ip_addr_set_zero( &gw );\r
121         ip_addr_set_zero( &ipaddr );\r
122         ip_addr_set_zero( &netmask );\r
123 \r
124         LWIP_PORT_INIT_GW(&gw);\r
125         LWIP_PORT_INIT_IPADDR(&ipaddr);\r
126         LWIP_PORT_INIT_NETMASK(&netmask);\r
127         printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&ipaddr));\r
128 \r
129         netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));\r
130 \r
131         #if LWIP_NETIF_STATUS_CALLBACK\r
132                 netif_set_status_callback(&netif, status_callback);\r
133         #endif /* LWIP_NETIF_STATUS_CALLBACK */\r
134         #if LWIP_NETIF_LINK_CALLBACK\r
135                 netif_set_link_callback(&netif, link_callback);\r
136         #endif /* LWIP_NETIF_LINK_CALLBACK */\r
137 \r
138         netif_set_up( &netif );\r
139         apps_init();\r
140         http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 /* This function initializes applications */\r
145 static void apps_init( void )\r
146 {\r
147         /* Taken from the lwIP example code. */\r
148         \r
149         #if LWIP_DNS_APP && LWIP_DNS\r
150                 /* wait until the netif is up (for dhcp, autoip or ppp) */\r
151                 sys_timeout(5000, dns_dorequest, NULL);\r
152         #endif /* LWIP_DNS_APP && LWIP_DNS */\r
153 \r
154         #if LWIP_CHARGEN_APP && LWIP_SOCKET\r
155                 chargen_init();\r
156         #endif /* LWIP_CHARGEN_APP && LWIP_SOCKET */\r
157 \r
158         #if LWIP_PING_APP && LWIP_RAW && LWIP_ICMP\r
159                 ping_init();\r
160         #endif /* LWIP_PING_APP && LWIP_RAW && LWIP_ICMP */\r
161 \r
162         #if LWIP_NETBIOS_APP && LWIP_UDP\r
163                 netbios_init();\r
164         #endif /* LWIP_NETBIOS_APP && LWIP_UDP */\r
165 \r
166         #if LWIP_HTTPD_APP && LWIP_TCP\r
167         {\r
168                 #ifdef LWIP_HTTPD_APP_NETCONN\r
169                         http_server_netconn_init();\r
170                 #else /* LWIP_HTTPD_APP_NETCONN */\r
171                         httpd_init();\r
172                 #endif /* LWIP_HTTPD_APP_NETCONN */\r
173         }\r
174         #endif /* LWIP_HTTPD_APP && LWIP_TCP */\r
175 \r
176         #if LWIP_NETIO_APP && LWIP_TCP\r
177                 netio_init();\r
178         #endif /* LWIP_NETIO_APP && LWIP_TCP */\r
179 \r
180         #if LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP\r
181                 rtp_init();\r
182         #endif /* LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP */\r
183 \r
184         #if LWIP_SNTP_APP && LWIP_SOCKET\r
185                 sntp_init();\r
186         #endif /* LWIP_SNTP_APP && LWIP_SOCKET */\r
187 \r
188         #if LWIP_SHELL_APP && LWIP_NETCONN\r
189                 shell_init();\r
190         #endif /* LWIP_SHELL_APP && LWIP_NETCONN */\r
191 \r
192         #if LWIP_TCPECHO_APP\r
193                 #if LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN)\r
194                         tcpecho_init();\r
195                 #else /* LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) */\r
196                         echo_init();\r
197                 #endif\r
198         #endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */\r
199 \r
200         #if LWIP_UDPECHO_APP && LWIP_NETCONN\r
201                 udpecho_init();\r
202         #endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */\r
203         \r
204         #if LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET\r
205                 socket_examples_init();\r
206         #endif /* LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET */\r
207 }\r
208 /*-----------------------------------------------------------*/\r
209 \r
210 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )\r
211 {\r
212 static unsigned int uiUpdateCount = 0;\r
213 static char cUpdateString[ 200 ];\r
214 extern char *pcMainGetTaskStatusMessage( void );\r
215 \r
216         ( void ) iBufferLength;\r
217 \r
218         /* The SSI handler function that generates text depending on the index of\r
219         the SSI tag encountered. */\r
220         \r
221         switch( iIndex )\r
222         {\r
223                 case ssiTASK_STATS_INDEX :\r
224                         vTaskList( pcBuffer );\r
225                         break;\r
226 \r
227                 case ssiRUN_TIME_STATS_INDEX :\r
228                         vTaskGetRunTimeStats( pcBuffer );\r
229                         break;\r
230         }\r
231 \r
232         uiUpdateCount++;\r
233         sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );\r
234         strcat( pcBuffer, cUpdateString );\r
235         return strlen( pcBuffer );\r
236 }\r
237 \r