1 /*This file has been prepared for Doxygen automatic documentation generation.*/
\r
2 /*! \file *********************************************************************
\r
4 * \brief Basic WEB Server for AVR32 UC3.
\r
6 * - Compiler: GNU GCC for AVR32
\r
7 * - Supported devices: All AVR32 devices can be used.
\r
10 * \author Atmel Corporation: http://www.atmel.com \n
\r
11 * Support and FAQ: http://support.atmel.no/
\r
13 *****************************************************************************/
\r
15 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
\r
17 * Redistribution and use in source and binary forms, with or without
\r
18 * modification, are permitted provided that the following conditions are met:
\r
20 * 1. Redistributions of source code must retain the above copyright notice,
\r
21 * this list of conditions and the following disclaimer.
\r
23 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
24 * this list of conditions and the following disclaimer in the documentation
\r
25 * and/or other materials provided with the distribution.
\r
27 * 3. The name of ATMEL may not be used to endorse or promote products derived
\r
28 * from this software without specific prior written permission.
\r
30 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
\r
31 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
32 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
\r
33 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
\r
34 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
35 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
36 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
37 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
44 Implements a simplistic WEB server. Every time a connection is made and
\r
45 data is received a dynamic page that shows the current FreeRTOS.org kernel
\r
46 statistics is generated and returned. The connection is then closed.
\r
48 This file was adapted from a FreeRTOS lwIP slip demo supplied by a third
\r
52 #if (HTTP_USED == 1)
\r
55 /* Standard includes. */
\r
59 #include "conf_eth.h"
\r
61 /* Scheduler includes. */
\r
62 #include "FreeRTOS.h"
\r
65 #include "partest.h"
\r
68 /* Demo includes. */
\r
69 /* Demo app includes. */
\r
70 #include "portmacro.h"
\r
72 /* lwIP includes. */
\r
73 #include "lwip/api.h"
\r
74 #include "lwip/tcpip.h"
\r
75 #include "lwip/memp.h"
\r
76 #include "lwip/stats.h"
\r
77 #include "netif/loopif.h"
\r
79 /* ethernet includes */
\r
80 #include "ethernet.h"
\r
82 /*! The size of the buffer in which the dynamic WEB page is created. */
\r
83 #define webMAX_PAGE_SIZE 512
\r
85 /*! Standard GET response. */
\r
86 #define webHTTP_OK "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n"
\r
88 /*! The port on which we listen. */
\r
89 #define webHTTP_PORT ( 80 )
\r
91 /*! Delay on close error. */
\r
92 #define webSHORT_DELAY ( 10 )
\r
94 /*! Format of the dynamic page that is returned on each connection. */
\r
95 #define webHTML_START \
\r
99 <BODY onLoad=\"window.setTimeout("location.href='index.html'",1000)\" bgcolor=\"#FFFFFF\" text=\"#2477E6\">\
\r
102 #define webHTML_END \
\r
104 \r\n</font></BODY>\
\r
107 portCHAR cDynamicPage[ webMAX_PAGE_SIZE ];
\r
108 portCHAR cPageHits[ 11 ];
\r
111 /*! Function to process the current connection */
\r
112 static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon );
\r
115 /*! \brief WEB server main task
\r
116 * check for incoming connection and process it
\r
118 * \param pvParameters Input. Not Used.
\r
121 portTASK_FUNCTION( vBasicWEBServer, pvParameters )
\r
123 struct netconn *pxHTTPListener, *pxNewConnection;
\r
125 /* Create a new tcp connection handle */
\r
126 pxHTTPListener = netconn_new( NETCONN_TCP );
\r
127 netconn_bind(pxHTTPListener, NULL, webHTTP_PORT );
\r
128 netconn_listen( pxHTTPListener );
\r
133 /* Wait for a first connection. */
\r
134 pxNewConnection = netconn_accept(pxHTTPListener);
\r
135 vParTestSetLED(webCONN_LED, pdTRUE);
\r
137 if(pxNewConnection != NULL)
\r
139 prvweb_ParseHTMLRequest(pxNewConnection);
\r
140 }/* end if new connection */
\r
142 vParTestSetLED(webCONN_LED, pdFALSE);
\r
144 } /* end infinite loop */
\r
148 /*! \brief parse the incoming request
\r
149 * parse the HTML request and send file
\r
151 * \param pxNetCon Input. The netconn to use to send and receive data.
\r
154 static void prvweb_ParseHTMLRequest( struct netconn *pxNetCon )
\r
156 struct netbuf *pxRxBuffer;
\r
157 portCHAR *pcRxString;
\r
158 unsigned portSHORT usLength;
\r
159 static unsigned portLONG ulPageHits = 0;
\r
161 /* We expect to immediately get data. */
\r
162 pxRxBuffer = netconn_recv( pxNetCon );
\r
164 if( pxRxBuffer != NULL )
\r
166 /* Where is the data? */
\r
167 netbuf_data( pxRxBuffer, ( void * ) &pcRxString, &usLength );
\r
169 /* Is this a GET? We don't handle anything else. */
\r
170 if( !strncmp( pcRxString, "GET", 3 ) )
\r
172 pcRxString = cDynamicPage;
\r
174 /* Update the hit count. */
\r
176 sprintf( cPageHits, "%d", (int)ulPageHits );
\r
178 /* Write out the HTTP OK header. */
\r
179 netconn_write( pxNetCon, webHTTP_OK, (u16_t) strlen( webHTTP_OK ), NETCONN_COPY );
\r
181 /* Generate the dynamic page... First the page header. */
\r
182 strcpy( cDynamicPage, webHTML_START );
\r
184 /* ... Then the hit count... */
\r
185 strcat( cDynamicPage, cPageHits );
\r
186 strcat( cDynamicPage, "<p><pre>Task State Priority Stack #<br>************************************************<br>" );
\r
188 /* ... Then the list of tasks and their status... */
\r
189 vTaskList( ( signed portCHAR * ) cDynamicPage + strlen( cDynamicPage ) );
\r
191 /* ... Finally the page footer. */
\r
192 strcat( cDynamicPage, webHTML_END );
\r
194 /* Write out the dynamically generated page. */
\r
195 netconn_write( pxNetCon, cDynamicPage, (u16_t) strlen( cDynamicPage ), NETCONN_COPY );
\r
197 netbuf_delete( pxRxBuffer );
\r
200 netconn_close( pxNetCon );
\r
201 netconn_delete( pxNetCon );
\r