2 FreeRTOS V4.1.0 - copyright (C) 2003-2006 Richard Barry.
4 This file is part of the FreeRTOS distribution.
6 FreeRTOS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 FreeRTOS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with FreeRTOS; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 A special exception to the GPL can be applied should you wish to distribute
21 a combined work that includes FreeRTOS, without being obliged to provide
22 the source code for any proprietary components. See the licensing section
23 of http://www.FreeRTOS.org for full details of how and when the exception
26 ***************************************************************************
27 See http://www.FreeRTOS.org for documentation, latest information, license
28 and contact details. Please ensure to read the configuration and relevant
29 port sections of the online documentation.
30 ***************************************************************************
34 Implements a simplistic WEB server. Every time a connection is made and
35 data is received a dynamic page that shows the current TCP/IP statistics
36 is generated and returned. The connection is then closed.
38 This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
42 /* ------------------------ System includes ------------------------------- */
46 /* ------------------------ FreeRTOS includes ----------------------------- */
51 /* ------------------------ lwIP includes --------------------------------- */
53 #include "lwip/tcpip.h"
54 #include "lwip/memp.h"
55 #include "lwip/stats.h"
56 #include "netif/loopif.h"
58 /* ------------------------ Project includes ------------------------------ */
61 #include "netif/fec.h"
65 /* ------------------------ Defines --------------------------------------- */
66 /* The size of the buffer in which the dynamic WEB page is created. */
67 #define webMAX_PAGE_SIZE ( 2048 )
69 /* Standard GET response. */
70 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
72 /* The port on which we listen. */
73 #define webHTTP_PORT ( 80 )
75 /* Delay on close error. */
76 #define webSHORT_DELAY ( 10 )
78 /* Format of the dynamic page that is returned on each connection. */
79 #define webHTML_START \
83 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
88 "FreeRTOS MCF5235 port (c) 2006 by Christian Walter <wolti@sil.at>\r\n" \
93 /* ------------------------ Prototypes ------------------------------------ */
94 static void vProcessConnection( struct netconn *pxNetCon );
96 /*------------------------------------------------------------*/
99 * Process an incoming connection on port 80.
101 * This simply checks to see if the incoming data contains a GET request, and
102 * if so sends back a single dynamically created page. The connection is then
103 * closed. A more complete implementation could create a task for each
107 vProcessConnection( struct netconn *pxNetCon )
109 static portCHAR cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
110 struct netbuf *pxRxBuffer;
111 portCHAR *pcRxString;
112 unsigned portSHORT usLength;
113 static unsigned portLONG ulPageHits = 0;
115 /* We expect to immediately get data. */
116 pxRxBuffer = netconn_recv( pxNetCon );
118 if( pxRxBuffer != NULL )
120 /* Where is the data? */
121 netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
123 /* Is this a GET? We don't handle anything else. */
124 if( !strncmp( pcRxString, "GET", 3 ) )
126 pcRxString = cDynamicPage;
128 /* Update the hit count. */
130 sprintf( cPageHits, "%lu", ulPageHits );
132 /* Write out the HTTP OK header. */
133 netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
135 /* Generate the dynamic page...
137 ... First the page header. */
138 strcpy( cDynamicPage, webHTML_START );
139 /* ... Then the hit count... */
140 strcat( cDynamicPage, cPageHits );
141 strcat( cDynamicPage,
142 "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
143 /* ... Then the list of tasks and their status... */
144 vTaskList( ( signed portCHAR * )cDynamicPage + strlen( cDynamicPage ) );
145 /* ... Finally the page footer. */
146 strcat( cDynamicPage, webHTML_END );
148 /* Write out the dynamically generated page. */
149 netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
152 netbuf_delete( pxRxBuffer );
155 netconn_close( pxNetCon );
158 /*------------------------------------------------------------*/
163 /* Initialize lwIP and its interface layer. */
170 tcpip_init( NULL, NULL );
173 /*------------------------------------------------------------*/
176 vBasicWEBServer( void *pvParameters )
178 struct netconn *pxHTTPListener, *pxNewConnection;
179 struct ip_addr xIpAddr, xNetMast, xGateway;
180 static struct netif fec523x_if;
182 /* Parameters are not used - suppress compiler error. */
183 ( void )pvParameters;
185 /* Create and configure the EMAC interface. */
186 IP4_ADDR( &xIpAddr, 10, 0, 10, 2 );
187 IP4_ADDR( &xNetMast, 255, 255, 255, 0 );
188 IP4_ADDR( &xGateway, 10, 0, 10, 1 );
189 netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, mcf523xfec_init, tcpip_input );
191 /* make it the default interface */
192 netif_set_default( &fec523x_if );
195 netif_set_up( &fec523x_if );
197 /* Create a new tcp connection handle */
198 pxHTTPListener = netconn_new( NETCONN_TCP );
199 netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
200 netconn_listen( pxHTTPListener );
205 /* Wait for connection. */
206 pxNewConnection = netconn_accept( pxHTTPListener );
208 if( pxNewConnection != NULL )
210 /* Service connection. */
211 vProcessConnection( pxNewConnection );
212 while( netconn_delete( pxNewConnection ) != ERR_OK )
214 vTaskDelay( webSHORT_DELAY );