2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\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
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\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
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\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
69 /* lwIP netif includes */
\r
70 #include "netif/etharp.h"
\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
87 /* include the port-dependent configuration */
\r
88 #include "lwipcfg_msvc.h"
\r
90 static struct netif netif;
\r
92 static void apps_init( void );
\r
94 #define ssiTASK_STATS_INDEX 0
\r
95 #define ssiRUN_TIME_STATS_INDEX 1
\r
99 * The SSI handler callback function passed to lwIP.
\r
101 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );
\r
104 /* The SSI strings that are embedded in the served html files. */
\r
105 static const char *pccSSITags[] =
\r
112 /* Called from the TCP/IP thread. */
\r
113 void lwIPAppsInit( void *pvArgument )
\r
115 ip_addr_t ipaddr, netmask, gw;
\r
116 extern err_t ethernetif_init( struct netif *netif );
\r
118 ( void ) pvArgument;
\r
120 ip_addr_set_zero( &gw );
\r
121 ip_addr_set_zero( &ipaddr );
\r
122 ip_addr_set_zero( &netmask );
\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
129 netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
\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
138 netif_set_up( &netif );
\r
140 http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );
\r
142 /*-----------------------------------------------------------*/
\r
144 /* This function initializes applications */
\r
145 static void apps_init( void )
\r
147 /* Taken from the lwIP example code. */
\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
154 #if LWIP_CHARGEN_APP && LWIP_SOCKET
\r
156 #endif /* LWIP_CHARGEN_APP && LWIP_SOCKET */
\r
158 #if LWIP_PING_APP && LWIP_RAW && LWIP_ICMP
\r
160 #endif /* LWIP_PING_APP && LWIP_RAW && LWIP_ICMP */
\r
162 #if LWIP_NETBIOS_APP && LWIP_UDP
\r
164 #endif /* LWIP_NETBIOS_APP && LWIP_UDP */
\r
166 #if LWIP_HTTPD_APP && LWIP_TCP
\r
168 #ifdef LWIP_HTTPD_APP_NETCONN
\r
169 http_server_netconn_init();
\r
170 #else /* LWIP_HTTPD_APP_NETCONN */
\r
172 #endif /* LWIP_HTTPD_APP_NETCONN */
\r
174 #endif /* LWIP_HTTPD_APP && LWIP_TCP */
\r
176 #if LWIP_NETIO_APP && LWIP_TCP
\r
178 #endif /* LWIP_NETIO_APP && LWIP_TCP */
\r
180 #if LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP
\r
182 #endif /* LWIP_RTP_APP && LWIP_SOCKET && LWIP_IGMP */
\r
184 #if LWIP_SNTP_APP && LWIP_SOCKET
\r
186 #endif /* LWIP_SNTP_APP && LWIP_SOCKET */
\r
188 #if LWIP_SHELL_APP && LWIP_NETCONN
\r
190 #endif /* LWIP_SHELL_APP && LWIP_NETCONN */
\r
192 #if LWIP_TCPECHO_APP
\r
193 #if LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN)
\r
195 #else /* LWIP_NETCONN && defined(LWIP_TCPECHO_APP_NETCONN) */
\r
198 #endif /* LWIP_TCPECHO_APP && LWIP_NETCONN */
\r
200 #if LWIP_UDPECHO_APP && LWIP_NETCONN
\r
202 #endif /* LWIP_UDPECHO_APP && LWIP_NETCONN */
\r
204 #if LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET
\r
205 socket_examples_init();
\r
206 #endif /* LWIP_SOCKET_EXAMPLES_APP && LWIP_SOCKET */
\r
208 /*-----------------------------------------------------------*/
\r
210 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )
\r
212 static unsigned int uiUpdateCount = 0;
\r
213 static char cUpdateString[ 200 ];
\r
214 extern char *pcMainGetTaskStatusMessage( void );
\r
216 ( void ) iBufferLength;
\r
218 /* The SSI handler function that generates text depending on the index of
\r
219 the SSI tag encountered. */
\r
223 case ssiTASK_STATS_INDEX :
\r
224 vTaskList( pcBuffer );
\r
227 case ssiRUN_TIME_STATS_INDEX :
\r
228 vTaskGetRunTimeStats( pcBuffer );
\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