2 FreeRTOS.org V5.0.3 - copyright (C) 2003-2006 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 Implements a simplistic WEB server. Every time a connection is made and
\r
52 data is received a dynamic page that shows the current TCP/IP statistics
\r
53 is generated and returned. The connection is then closed.
\r
55 This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
\r
59 /* ------------------------ System includes ------------------------------- */
\r
62 /* ------------------------ FreeRTOS includes ----------------------------- */
\r
63 #include "FreeRTOS.h"
\r
67 /* ------------------------ lwIP includes --------------------------------- */
\r
68 #include "lwip/api.h"
\r
69 #include "lwip/tcpip.h"
\r
70 #include "lwip/ip.h"
\r
71 #include "lwip/memp.h"
\r
72 #include "lwip/stats.h"
\r
73 #include "netif/loopif.h"
\r
75 /* ------------------------ Project includes ------------------------------ */
\r
78 #include "HTTPDemo.h"
\r
80 /* ------------------------ Defines --------------------------------------- */
\r
81 /* The size of the buffer in which the dynamic WEB page is created. */
\r
82 #define webMAX_PAGE_SIZE ( 1024 ) /*FSL: buffer containing array*/
\r
84 /* Standard GET response. */
\r
85 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
\r
87 /* The port on which we listen. */
\r
88 #define webHTTP_PORT ( 80 )
\r
90 /* Delay on close error. */
\r
91 #define webSHORT_DELAY ( 10 )
\r
93 /* Format of the dynamic page that is returned on each connection. */
\r
94 #define webHTML_START \
\r
98 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
\r
99 \r\n\r\nPage Hits = "
\r
101 #define webHTML_END \
\r
107 #if INCLUDE_uxTaskGetStackHighWaterMark
\r
108 static volatile unsigned portBASE_TYPE uxHighWaterMark_web = 0;
\r
111 /* ------------------------ Prototypes ------------------------------------ */
\r
112 static void vProcessConnection( struct netconn *pxNetCon );
\r
114 /*------------------------------------------------------------*/
\r
117 * Process an incoming connection on port 80.
\r
119 * This simply checks to see if the incoming data contains a GET request, and
\r
120 * if so sends back a single dynamically created page. The connection is then
\r
121 * closed. A more complete implementation could create a task for each
\r
124 static void vProcessConnection( struct netconn *pxNetCon )
\r
126 static portCHAR cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
\r
127 struct netbuf *pxRxBuffer;
\r
128 portCHAR *pcRxString;
\r
129 unsigned portSHORT usLength;
\r
130 static unsigned portLONG ulPageHits = 0;
\r
132 /* We expect to immediately get data. */
\r
133 pxRxBuffer = netconn_recv( pxNetCon );
\r
135 if( pxRxBuffer != NULL )
\r
137 /* Where is the data? */
\r
138 netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
\r
140 /* Is this a GET? We don't handle anything else. */
\r
141 if( !strncmp( pcRxString, "GET", 3 ) )
\r
143 pcRxString = cDynamicPage;
\r
145 /* Update the hit count. */
\r
147 sprintf( cPageHits, "%d", (int)ulPageHits );
\r
149 /* Write out the HTTP OK header. */
\r
150 netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
\r
152 /* Generate the dynamic page...
\r
154 ... First the page header. */
\r
155 strcpy( cDynamicPage, webHTML_START );
\r
156 /* ... Then the hit count... */
\r
157 strcat( cDynamicPage, cPageHits );
\r
159 strcat( cDynamicPage,
\r
160 "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
\r
161 /* ... Then the list of tasks and their status... */
\r
162 vTaskList( ( signed portCHAR * )cDynamicPage + strlen( cDynamicPage ) );
\r
164 /* ... Finally the page footer. */
\r
165 strcat( cDynamicPage, webHTML_END );
\r
167 /* Write out the dynamically generated page. */
\r
168 netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
\r
170 netbuf_delete( pxRxBuffer );
\r
172 netconn_close( pxNetCon );
\r
175 /*------------------------------------------------------------*/
\r
177 void vlwIPInit( void )
\r
179 /* Initialize lwIP and its interface layer. */
\r
180 tcpip_init( NULL, NULL );
\r
183 /*------------------------------------------------------------*/
\r
185 void vBasicWEBServer( void *pvParameters )
\r
187 struct netconn *pxHTTPListener, *pxNewConnection;
\r
188 struct ip_addr xIpAddr, xNetMast, xGateway;
\r
189 static struct netif fec523x_if;
\r
190 extern err_t ethernetif_init(struct netif *netif);
\r
192 /* Parameters are not used - suppress compiler error. */
\r
193 ( void )pvParameters;
\r
197 /* Create and configure the FEC interface. */
\r
198 IP4_ADDR( &xIpAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
199 IP4_ADDR( &xNetMast, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
200 IP4_ADDR( &xGateway, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3 );
\r
201 netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input );
\r
203 /* make it the default interface */
\r
204 netif_set_default( &fec523x_if );
\r
207 netif_set_up( &fec523x_if );
\r
209 /* Create a new tcp connection handle */
\r
210 pxHTTPListener = netconn_new( NETCONN_TCP );
\r
211 netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
\r
212 netconn_listen( pxHTTPListener );
\r
217 /* Wait for connection. */
\r
218 pxNewConnection = netconn_accept( pxHTTPListener );
\r
220 if( pxNewConnection != NULL )
\r
222 /* Service connection. */
\r
223 vProcessConnection( pxNewConnection );
\r
224 while( netconn_delete( pxNewConnection ) != ERR_OK )
\r
226 vTaskDelay( webSHORT_DELAY );
\r