2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
97 Implements a simplistic WEB server. Every time a connection is made and
\r
98 data is received a dynamic page that shows the current TCP/IP statistics
\r
99 is generated and returned. The connection is then closed.
\r
101 This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
\r
105 /* ------------------------ System includes ------------------------------- */
\r
108 /* ------------------------ FreeRTOS includes ----------------------------- */
\r
109 #include "FreeRTOS.h"
\r
111 #include "semphr.h"
\r
113 /* ------------------------ lwIP includes --------------------------------- */
\r
114 #include "lwip/api.h"
\r
115 #include "lwip/tcpip.h"
\r
116 #include "lwip/ip.h"
\r
117 #include "lwip/memp.h"
\r
118 #include "lwip/stats.h"
\r
119 #include "netif/loopif.h"
\r
121 /* ------------------------ Project includes ------------------------------ */
\r
122 #include "common.h"
\r
124 #include "HTTPDemo.h"
\r
126 /* ------------------------ Defines --------------------------------------- */
\r
127 /* The size of the buffer in which the dynamic WEB page is created. */
\r
128 #define webMAX_PAGE_SIZE ( 1024 ) /*FSL: buffer containing array*/
\r
130 /* Standard GET response. */
\r
131 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
\r
133 /* The port on which we listen. */
\r
134 #define webHTTP_PORT ( 80 )
\r
136 /* Delay on close error. */
\r
137 #define webSHORT_DELAY ( 10 )
\r
139 /* Format of the dynamic page that is returned on each connection. */
\r
140 #define webHTML_START \
\r
144 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
\r
145 \r\n\r\nPage Hits = "
\r
147 #define webHTML_END \
\r
153 #if INCLUDE_uxTaskGetStackHighWaterMark
\r
154 static volatile unsigned portBASE_TYPE uxHighWaterMark_web = 0;
\r
157 /* ------------------------ Prototypes ------------------------------------ */
\r
158 static void vProcessConnection( struct netconn *pxNetCon );
\r
160 /*------------------------------------------------------------*/
\r
163 * Process an incoming connection on port 80.
\r
165 * This simply checks to see if the incoming data contains a GET request, and
\r
166 * if so sends back a single dynamically created page. The connection is then
\r
167 * closed. A more complete implementation could create a task for each
\r
170 static void vProcessConnection( struct netconn *pxNetCon )
\r
172 static char cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
\r
173 struct netbuf *pxRxBuffer;
\r
175 unsigned short usLength;
\r
176 static unsigned long ulPageHits = 0;
\r
178 /* We expect to immediately get data. */
\r
179 pxRxBuffer = netconn_recv( pxNetCon );
\r
181 if( pxRxBuffer != NULL )
\r
183 /* Where is the data? */
\r
184 netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
\r
186 /* Is this a GET? We don't handle anything else. */
\r
187 if( !strncmp( pcRxString, "GET", 3 ) )
\r
189 pcRxString = cDynamicPage;
\r
191 /* Update the hit count. */
\r
193 sprintf( cPageHits, "%d", (int)ulPageHits );
\r
195 /* Write out the HTTP OK header. */
\r
196 netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
\r
198 /* Generate the dynamic page...
\r
200 ... First the page header. */
\r
201 strcpy( cDynamicPage, webHTML_START );
\r
202 /* ... Then the hit count... */
\r
203 strcat( cDynamicPage, cPageHits );
\r
205 strcat( cDynamicPage,
\r
206 "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
\r
207 /* ... Then the list of tasks and their status... */
\r
208 vTaskList( cDynamicPage + strlen( cDynamicPage ) );
\r
210 /* ... Finally the page footer. */
\r
211 strcat( cDynamicPage, webHTML_END );
\r
213 /* Write out the dynamically generated page. */
\r
214 netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
\r
216 netbuf_delete( pxRxBuffer );
\r
218 netconn_close( pxNetCon );
\r
221 /*------------------------------------------------------------*/
\r
223 void vlwIPInit( void )
\r
225 /* Initialize lwIP and its interface layer. */
\r
226 tcpip_init( NULL, NULL );
\r
229 /*------------------------------------------------------------*/
\r
231 void vBasicWEBServer( void *pvParameters )
\r
233 struct netconn *pxHTTPListener, *pxNewConnection;
\r
234 struct ip_addr xIpAddr, xNetMast, xGateway;
\r
235 static struct netif fec523x_if;
\r
236 extern err_t ethernetif_init(struct netif *netif);
\r
238 /* Parameters are not used - suppress compiler error. */
\r
239 ( void )pvParameters;
\r
243 /* Create and configure the FEC interface. */
\r
244 IP4_ADDR( &xIpAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
245 IP4_ADDR( &xNetMast, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
246 IP4_ADDR( &xGateway, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3 );
\r
247 netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input );
\r
249 /* make it the default interface */
\r
250 netif_set_default( &fec523x_if );
\r
253 netif_set_up( &fec523x_if );
\r
255 /* Create a new tcp connection handle */
\r
256 pxHTTPListener = netconn_new( NETCONN_TCP );
\r
257 netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
\r
258 netconn_listen( pxHTTPListener );
\r
263 /* Wait for connection. */
\r
264 pxNewConnection = netconn_accept( pxHTTPListener );
\r
266 if( pxNewConnection != NULL )
\r
268 /* Service connection. */
\r
269 vProcessConnection( pxNewConnection );
\r
270 while( netconn_delete( pxNewConnection ) != ERR_OK )
\r
272 vTaskDelay( webSHORT_DELAY );
\r