2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
71 Implements a simplistic WEB server. Every time a connection is made and
72 data is received a dynamic page that shows the current TCP/IP statistics
73 is generated and returned. The connection is then closed.
75 This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
79 /* ------------------------ System includes ------------------------------- */
82 /* ------------------------ FreeRTOS includes ----------------------------- */
87 /* ------------------------ lwIP includes --------------------------------- */
89 #include "lwip/tcpip.h"
91 #include "lwip/memp.h"
92 #include "lwip/stats.h"
93 #include "netif/loopif.h"
95 /* ------------------------ Project includes ------------------------------ */
100 /* ------------------------ Defines --------------------------------------- */
101 /* The size of the buffer in which the dynamic WEB page is created. */
102 #define webMAX_PAGE_SIZE ( 1024 ) /*FSL: buffer containing array*/
104 /* Standard GET response. */
105 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
107 /* The port on which we listen. */
108 #define webHTTP_PORT ( 80 )
110 /* Delay on close error. */
111 #define webSHORT_DELAY ( 10 )
113 /* Format of the dynamic page that is returned on each connection. */
114 #define webHTML_START \
118 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
119 \r\n\r\nPage Hits = "
121 #define webHTML_END \
127 #if INCLUDE_uxTaskGetStackHighWaterMark
128 static volatile unsigned portBASE_TYPE uxHighWaterMark_web = 0;
131 /* ------------------------ Prototypes ------------------------------------ */
132 static void vProcessConnection( struct netconn *pxNetCon );
134 /*------------------------------------------------------------*/
137 * Process an incoming connection on port 80.
139 * This simply checks to see if the incoming data contains a GET request, and
140 * if so sends back a single dynamically created page. The connection is then
141 * closed. A more complete implementation could create a task for each
144 static void vProcessConnection( struct netconn *pxNetCon )
146 static char cDynamicPage[webMAX_PAGE_SIZE], cPageHits[11];
147 struct netbuf *pxRxBuffer;
149 unsigned short usLength;
150 static unsigned long ulPageHits = 0;
152 /* We expect to immediately get data. */
153 pxRxBuffer = netconn_recv( pxNetCon );
155 if( pxRxBuffer != NULL )
157 /* Where is the data? */
158 netbuf_data( pxRxBuffer, ( void * )&pcRxString, &usLength );
160 /* Is this a GET? We don't handle anything else. */
161 if( !strncmp( pcRxString, "GET", 3 ) )
163 pcRxString = cDynamicPage;
165 /* Update the hit count. */
167 sprintf( cPageHits, "%d", (int)ulPageHits );
169 /* Write out the HTTP OK header. */
170 netconn_write( pxNetCon, webHTTP_OK, ( u16_t ) strlen( webHTTP_OK ), NETCONN_COPY );
172 /* Generate the dynamic page...
174 ... First the page header. */
175 strcpy( cDynamicPage, webHTML_START );
176 /* ... Then the hit count... */
177 strcat( cDynamicPage, cPageHits );
179 strcat( cDynamicPage,
180 "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
181 /* ... Then the list of tasks and their status... */
182 vTaskList( cDynamicPage + strlen( cDynamicPage ) );
184 /* ... Finally the page footer. */
185 strcat( cDynamicPage, webHTML_END );
187 /* Write out the dynamically generated page. */
188 netconn_write( pxNetCon, cDynamicPage, ( u16_t ) strlen( cDynamicPage ), NETCONN_COPY );
190 netbuf_delete( pxRxBuffer );
192 netconn_close( pxNetCon );
195 /*------------------------------------------------------------*/
197 void vlwIPInit( void )
199 /* Initialize lwIP and its interface layer. */
200 tcpip_init( NULL, NULL );
203 /*------------------------------------------------------------*/
205 void vBasicWEBServer( void *pvParameters )
207 struct netconn *pxHTTPListener, *pxNewConnection;
208 struct ip_addr xIpAddr, xNetMast, xGateway;
209 static struct netif fec523x_if;
210 extern err_t ethernetif_init(struct netif *netif);
212 /* Parameters are not used - suppress compiler error. */
213 ( void )pvParameters;
217 /* Create and configure the FEC interface. */
218 IP4_ADDR( &xIpAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
219 IP4_ADDR( &xNetMast, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
220 IP4_ADDR( &xGateway, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3 );
221 netif_add( &fec523x_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input );
223 /* make it the default interface */
224 netif_set_default( &fec523x_if );
227 netif_set_up( &fec523x_if );
229 /* Create a new tcp connection handle */
230 pxHTTPListener = netconn_new( NETCONN_TCP );
231 netconn_bind( pxHTTPListener, NULL, webHTTP_PORT );
232 netconn_listen( pxHTTPListener );
237 /* Wait for connection. */
238 pxNewConnection = netconn_accept( pxHTTPListener );
240 if( pxNewConnection != NULL )
242 /* Service connection. */
243 vProcessConnection( pxNewConnection );
244 while( netconn_delete( pxNewConnection ) != ERR_OK )
246 vTaskDelay( webSHORT_DELAY );