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
106 Changes from V3.2.2
\r
108 + Changed the page returned by the lwIP WEB server demo to display the
\r
109 task status table rather than the TCP/IP statistics.
\r
113 /* Standard includes. */
\r
115 #include <string.h>
\r
117 /* Scheduler includes. */
\r
118 #include "FreeRTOS.h"
\r
120 #include "semphr.h"
\r
122 /* Demo includes. */
\r
123 #include "BasicWEB.h"
\r
124 #include "SAM7_EMAC.h"
\r
126 /* lwIP includes. */
\r
127 #include "lwip/api.h"
\r
128 #include "lwip/tcpip.h"
\r
129 #include "lwip/memp.h"
\r
130 #include "lwip/stats.h"
\r
131 #include "netif/loopif.h"
\r
133 /* The size of the buffer in which the dynamic WEB page is created. */
\r
134 #define webMAX_PAGE_SIZE 2048
\r
136 /* Standard GET response. */
\r
137 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
\r
139 /* The port on which we listen. */
\r
140 #define webHTTP_PORT ( 80 )
\r
142 /* Delay on close error. */
\r
143 #define webSHORT_DELAY ( 10 )
\r
145 /* Format of the dynamic page that is returned on each connection. */
\r
146 #define webHTML_START \
\r
150 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\"bgcolor=\"#CCCCff\">\
\r
153 #define webHTML_END \
\r
158 /*------------------------------------------------------------*/
\r
161 * Process an incoming connection on port 80.
\r
163 * This simply checks to see if the incoming data contains a GET request, and
\r
164 * if so sends back a single dynamically created page. The connection is then
\r
165 * closed. A more complete implementation could create a task for each
\r
168 static void vProcessConnection( struct netconn *pxNetCon );
\r
170 /*------------------------------------------------------------*/
\r
172 static void vProcessConnection( struct netconn *pxNetCon )
\r
174 static char cDynamicPage[ webMAX_PAGE_SIZE ], cPageHits[ 11 ];
\r
175 struct netbuf *pxRxBuffer;
\r
177 unsigned short usLength;
\r
178 static unsigned long ulPageHits = 0;
\r
180 /* We expect to immediately get data. */
\r
181 pxRxBuffer = netconn_recv( pxNetCon );
\r
183 if( pxRxBuffer != NULL )
\r
185 /* Where is the data? */
\r
186 netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
\r
188 /* Is this a GET? We don't handle anything else. */
\r
189 if( !strncmp( pcRxString, "GET", 3 ) )
\r
191 pcRxString = cDynamicPage;
\r
193 /* Update the hit count. */
\r
195 sprintf( cPageHits, "%lu", ulPageHits );
\r
197 /* Write out the HTTP OK header. */
\r
198 netconn_write(pxNetCon, webHTTP_OK, (u16_t)strlen( webHTTP_OK ), NETCONN_COPY );
\r
200 /* Generate the dynamic page...
\r
202 ... First the page header. */
\r
203 strcpy( cDynamicPage, webHTML_START );
\r
204 /* ... Then the hit count... */
\r
205 strcat( cDynamicPage, cPageHits );
\r
206 strcat( cDynamicPage, "<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
209 /* ... Finally the page footer. */
\r
210 strcat( cDynamicPage, webHTML_END );
\r
212 /* Write out the dynamically generated page. */
\r
213 netconn_write(pxNetCon, cDynamicPage, (u16_t)strlen( cDynamicPage ), NETCONN_COPY );
\r
216 netbuf_delete( pxRxBuffer );
\r
219 netconn_close( pxNetCon );
\r
221 /*------------------------------------------------------------*/
\r
223 void vlwIPInit( void )
\r
225 /* Initialize lwIP and its interface layer. */
\r
232 tcpip_init( NULL, NULL );
\r
234 /*------------------------------------------------------------*/
\r
236 void vBasicWEBServer( void *pvParameters )
\r
238 struct netconn *pxHTTPListener, *pxNewConnection;
\r
239 struct ip_addr xIpAddr, xNetMast, xGateway;
\r
240 extern err_t ethernetif_init( struct netif *netif );
\r
241 static struct netif EMAC_if;
\r
243 /* Parameters are not used - suppress compiler error. */
\r
244 ( void ) pvParameters;
\r
247 /* Create and configure the EMAC interface. */
\r
248 IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
\r
249 IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
\r
250 IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_ADDR3);
\r
251 netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);
\r
253 /* make it the default interface */
\r
254 netif_set_default(&EMAC_if);
\r
257 netif_set_up(&EMAC_if);
\r
259 /* Create a new tcp connection handle */
\r
261 pxHTTPListener = netconn_new( NETCONN_TCP );
\r
262 netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
\r
263 netconn_listen( pxHTTPListener );
\r
268 /* Wait for connection. */
\r
269 pxNewConnection = netconn_accept(pxHTTPListener);
\r
271 if(pxNewConnection != NULL)
\r
273 /* Service connection. */
\r
274 vProcessConnection( pxNewConnection );
\r
275 while( netconn_delete( pxNewConnection ) != ERR_OK )
\r
277 vTaskDelay( webSHORT_DELAY );
\r