2 FreeRTOS V7.3.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
70 * Very simple task that responds with a single WEB page to http requests.
\r
72 * The WEB page displays task and system status. A semaphore is used to
\r
73 * wake the task when there is processing to perform as determined by the
\r
74 * interrupts generated by the Ethernet interface.
\r
77 /* Standard includes. */
\r
81 /* Tern includes. */
\r
82 #include "utils\system_common.h"
\r
83 #include "i2chip_hw.h"
\r
86 /* FreeRTOS.org includes. */
\r
87 #include <FreeRTOS.h>
\r
91 /* The standard http port on which we are going to listen. */
\r
94 #define httpTX_WAIT 2
\r
96 /* Network address configuration. */
\r
97 const unsigned char ucMacAddress[] = { 12, 128, 12, 34, 56, 78 };
\r
98 const unsigned char ucGatewayAddress[] = { 192, 168, 2, 1 };
\r
99 const unsigned char ucIPAddress[] = { 172, 25, 218, 210 };
\r
100 const unsigned char ucSubnetMask[] = { 255, 255, 255, 0 };
\r
102 /* The number of sockets this task is going to handle. */
\r
103 #define httpSOCKET_NUM 3
\r
104 unsigned char ucConnection[ httpSOCKET_NUM ];
\r
106 /* The maximum data buffer size we can handle. */
\r
107 #define httpSOCKET_BUFFER_SIZE 2048
\r
109 /* Standard HTTP response. */
\r
110 #define httpOUTPUT_OK "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
\r
112 /* Hard coded HTML components. Other data is generated dynamically. */
\r
113 #define HTML_OUTPUT_BEGIN "\
\r
114 <HTML><head><meta http-equiv=\"Refresh\" content=\"1\;url=index.htm\"></head>\
\r
115 <BODY bgcolor=\"#CCCCFF\"><font face=\"arial\"><H2>FreeRTOS.org<sup>tm</sup> + Tern E-Engine<sup>tm</sup></H2>\
\r
116 <a href=\"http:\/\/www.FreeRTOS.org\">FreeRTOS.org Homepage</a><P>\
\r
117 <HR>Task status table:\r\n\
\r
118 <p><font face=\"courier\"><pre>Task State Priority Stack #<br>\
\r
119 ************************************************<br>"
\r
121 #define HTML_OUTPUT_END "\
\r
122 </font></BODY></HTML>"
\r
124 /*-----------------------------------------------------------*/
\r
127 * Initialise the data structures used to hold the socket status.
\r
129 static void prvHTTPInit( void );
\r
132 * Setup the Ethernet interface with the network addressing information.
\r
134 static void prvNetifInit( void );
\r
137 * Generate the dynamic components of the served WEB page and transmit the
\r
138 * entire page through the socket.
\r
140 static void prvTransmitHTTP( unsigned char socket );
\r
141 /*-----------------------------------------------------------*/
\r
143 /* This variable is simply incremented by the idle task hook so the number of
\r
144 iterations the idle task has performed can be displayed as part of the served
\r
146 unsigned long ulIdleLoops = 0UL;
\r
148 /* Data buffer shared by sockets. */
\r
149 unsigned char ucSocketBuffer[ httpSOCKET_BUFFER_SIZE ];
\r
151 /* The semaphore used by the Ethernet ISR to signal that the task should wake
\r
152 and process whatever caused the interrupt. */
\r
153 xSemaphoreHandle xTCPSemaphore = NULL;
\r
155 /*-----------------------------------------------------------*/
\r
156 void vHTTPTask( void * pvParameters )
\r
159 unsigned char ucState;
\r
161 ( void ) pvParameters;
\r
163 /* Create the semaphore used to communicate between this task and the
\r
165 vSemaphoreCreateBinary( xTCPSemaphore );
\r
167 /* Make sure everything is setup before we start. */
\r
173 /* Wait until the ISR tells us there is something to do. */
\r
174 xSemaphoreTake( xTCPSemaphore, portMAX_DELAY );
\r
176 /* Check each socket. */
\r
177 for( i = 0; i < httpSOCKET_NUM; i++ )
\r
179 ucState = select( i, SEL_CONTROL );
\r
183 case SOCK_ESTABLISHED : /* new connection established. */
\r
185 if( ( sLen = select( i, SEL_RECV ) ) > 0 )
\r
187 if( sLen > httpSOCKET_BUFFER_SIZE )
\r
189 sLen = httpSOCKET_BUFFER_SIZE;
\r
194 sLen = recv( i, ucSocketBuffer, sLen );
\r
196 if( ucConnection[ i ] == 1 )
\r
198 /* This is our first time processing a HTTP
\r
199 request on this connection. */
\r
200 prvTransmitHTTP( i );
\r
201 ucConnection[i] = 0;
\r
207 case SOCK_CLOSE_WAIT :
\r
214 ucConnection[i] = 1;
\r
215 socket( i, SOCK_STREAM, 80, 0x00 );
\r
216 NBlisten( i ); /* reinitialize socket. */
\r
222 /*-----------------------------------------------------------*/
\r
224 static void prvHTTPInit( void )
\r
226 unsigned char ucIndex;
\r
228 /* There are 4 total sockets available; we will claim 3 for HTTP. */
\r
229 for(ucIndex = 0; ucIndex < httpSOCKET_NUM; ucIndex++)
\r
231 socket( ucIndex, SOCK_STREAM, httpPORT, 0x00 );
\r
232 NBlisten( ucIndex );
\r
233 ucConnection[ ucIndex ] = 1;
\r
236 /*-----------------------------------------------------------*/
\r
238 static void prvNetifInit( void )
\r
243 setMACAddr( ( unsigned char * ) ucMacAddress );
\r
244 setgateway( ( unsigned char * ) ucGatewayAddress );
\r
245 setsubmask( ( unsigned char * ) ucSubnetMask );
\r
246 setIP( ( unsigned char * ) ucIPAddress );
\r
248 /* See definition of 'sysinit' in socket.c
\r
249 - 8 KB transmit buffer, and 8 KB receive buffer available. These buffers
\r
250 are shared by all 4 channels.
\r
251 - (0x55, 0x55) configures the send and receive buffers at
\r
252 httpSOCKET_BUFFER_SIZE bytes for each of the 4 channels. */
\r
253 sysinit( 0x55, 0x55 );
\r
255 /*-----------------------------------------------------------*/
\r
257 static void prvTransmitHTTP(unsigned char socket)
\r
259 extern short usCheckStatus;
\r
261 /* Send the http and html headers. */
\r
262 send( socket, ( unsigned char * ) httpOUTPUT_OK, strlen( httpOUTPUT_OK ) );
\r
263 send( socket, ( unsigned char * ) HTML_OUTPUT_BEGIN, strlen( HTML_OUTPUT_BEGIN ) );
\r
265 /* Generate then send the table showing the status of each task. */
\r
266 vTaskList( ucSocketBuffer );
\r
267 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
269 /* Send the number of times the idle task has looped. */
\r
270 sprintf( ucSocketBuffer, "</pre></font><p><br>The idle task has looped 0x%08lx times<br>", ulIdleLoops );
\r
271 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
273 /* Send the tick count. */
\r
274 sprintf( ucSocketBuffer, "The tick count is 0x%08lx<br>", xTaskGetTickCount() );
\r
275 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
277 /* Show a message indicating whether or not the check task has discovered
\r
278 an error in any of the standard demo tasks. */
\r
279 if( usCheckStatus == 0 )
\r
281 sprintf( ucSocketBuffer, "No errors detected." );
\r
282 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
286 sprintf( ucSocketBuffer, "<font color=\"red\">An error has been detected in at least one task %x.</font><p>", usCheckStatus );
\r
287 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
290 /* Finish the page off. */
\r
291 send( socket, (unsigned char*)HTML_OUTPUT_END, strlen(HTML_OUTPUT_END));
\r
293 /* Must make sure the data is gone before closing the socket. */
\r
294 while( !tx_empty( socket ) )
\r
296 vTaskDelay( httpTX_WAIT );
\r
300 /*-----------------------------------------------------------*/
\r
302 void vApplicationIdleHook( void )
\r