2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org 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.org 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.org; 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.org, 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
62 + Changed the page returned by the lwIP WEB server demo to display the
\r
63 task status table rather than the TCP/IP statistics.
\r
67 /* Standard includes. */
\r
71 /* Scheduler includes. */
\r
72 #include "FreeRTOS.h"
\r
76 /* Demo includes. */
\r
77 #include "BasicWEB.h"
\r
78 #include "SAM7_EMAC.h"
\r
80 /* lwIP includes. */
\r
81 #include "lwip/api.h"
\r
82 #include "lwip/tcpip.h"
\r
83 #include "lwip/memp.h"
\r
84 #include "lwip/stats.h"
\r
85 #include "netif/loopif.h"
\r
87 /* The size of the buffer in which the dynamic WEB page is created. */
\r
88 #define webMAX_PAGE_SIZE 2048
\r
90 /* Standard GET response. */
\r
91 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
\r
93 /* The port on which we listen. */
\r
94 #define webHTTP_PORT ( 80 )
\r
96 /* Delay on close error. */
\r
97 #define webSHORT_DELAY ( 10 )
\r
99 /* Format of the dynamic page that is returned on each connection. */
\r
100 #define webHTML_START \
\r
104 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
\r
107 #define webHTML_END \
\r
112 /*------------------------------------------------------------*/
\r
115 * Process an incoming connection on port 80.
\r
117 * This simply checks to see if the incoming data contains a GET request, and
\r
118 * if so sends back a single dynamically created page. The connection is then
\r
119 * closed. A more complete implementation could create a task for each
\r
122 static void vProcessConnection( struct netconn *pxNetCon );
\r
124 /*------------------------------------------------------------*/
\r
126 static void vProcessConnection( struct netconn *pxNetCon )
\r
128 static portCHAR cDynamicPage[ webMAX_PAGE_SIZE ], cPageHits[ 11 ];
\r
129 struct netbuf *pxRxBuffer;
\r
130 portCHAR *pcRxString;
\r
131 unsigned portSHORT usLength;
\r
132 static unsigned portLONG ulPageHits = 0;
\r
134 /* We expect to immediately get data. */
\r
135 pxRxBuffer = netconn_recv( pxNetCon );
\r
137 if( pxRxBuffer != NULL )
\r
139 /* Where is the data? */
\r
140 netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
\r
142 /* Is this a GET? We don't handle anything else. */
\r
143 if( !strncmp( pcRxString, "GET", 3 ) )
\r
145 pcRxString = cDynamicPage;
\r
147 /* Update the hit count. */
\r
149 sprintf( cPageHits, "%lu", ulPageHits );
\r
151 /* Write out the HTTP OK header. */
\r
152 netconn_write(pxNetCon, webHTTP_OK, (u16_t)strlen( webHTTP_OK ), NETCONN_COPY );
\r
154 /* Generate the dynamic page...
\r
156 ... First the page header. */
\r
157 strcpy( cDynamicPage, webHTML_START );
\r
158 /* ... Then the hit count... */
\r
159 strcat( cDynamicPage, cPageHits );
\r
160 strcat( cDynamicPage, "<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
163 /* ... Finally the page footer. */
\r
164 strcat( cDynamicPage, webHTML_END );
\r
166 /* Write out the dynamically generated page. */
\r
167 netconn_write(pxNetCon, cDynamicPage, (u16_t)strlen( cDynamicPage ), NETCONN_COPY );
\r
170 netbuf_delete( pxRxBuffer );
\r
173 netconn_close( pxNetCon );
\r
175 /*------------------------------------------------------------*/
\r
177 void vlwIPInit( void )
\r
179 /* Initialize lwIP and its interface layer. */
\r
186 tcpip_init( NULL, NULL );
\r
188 /*------------------------------------------------------------*/
\r
190 void vBasicWEBServer( void *pvParameters )
\r
192 struct netconn *pxHTTPListener, *pxNewConnection;
\r
193 struct ip_addr xIpAddr, xNetMast, xGateway;
\r
194 extern err_t ethernetif_init( struct netif *netif );
\r
195 static struct netif EMAC_if;
\r
197 /* Parameters are not used - suppress compiler error. */
\r
198 ( void ) pvParameters;
\r
201 /* Create and configure the EMAC interface. */
\r
202 IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
\r
203 IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
\r
204 IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_ADDR3);
\r
205 netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);
\r
207 /* make it the default interface */
\r
208 netif_set_default(&EMAC_if);
\r
211 netif_set_up(&EMAC_if);
\r
213 /* Create a new tcp connection handle */
\r
215 pxHTTPListener = netconn_new( NETCONN_TCP );
\r
216 netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
\r
217 netconn_listen( pxHTTPListener );
\r
222 /* Wait for connection. */
\r
223 pxNewConnection = netconn_accept(pxHTTPListener);
\r
225 if(pxNewConnection != NULL)
\r
227 /* Service connection. */
\r
228 vProcessConnection( pxNewConnection );
\r
229 while( netconn_delete( pxNewConnection ) != ERR_OK )
\r
231 vTaskDelay( webSHORT_DELAY );
\r