2 FreeRTOS V7.4.2 - Copyright (C) 2013 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
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not it can be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
76 * Very simple task that responds with a single WEB page to http requests.
\r
78 * The WEB page displays task and system status. A semaphore is used to
\r
79 * wake the task when there is processing to perform as determined by the
\r
80 * interrupts generated by the Ethernet interface.
\r
83 /* Standard includes. */
\r
87 /* Tern includes. */
\r
88 #include "utils\system_common.h"
\r
89 #include "i2chip_hw.h"
\r
92 /* FreeRTOS.org includes. */
\r
93 #include <FreeRTOS.h>
\r
97 /* The standard http port on which we are going to listen. */
\r
100 #define httpTX_WAIT 2
\r
102 /* Network address configuration. */
\r
103 const unsigned char ucMacAddress[] = { 12, 128, 12, 34, 56, 78 };
\r
104 const unsigned char ucGatewayAddress[] = { 192, 168, 2, 1 };
\r
105 const unsigned char ucIPAddress[] = { 172, 25, 218, 210 };
\r
106 const unsigned char ucSubnetMask[] = { 255, 255, 255, 0 };
\r
108 /* The number of sockets this task is going to handle. */
\r
109 #define httpSOCKET_NUM 3
\r
110 unsigned char ucConnection[ httpSOCKET_NUM ];
\r
112 /* The maximum data buffer size we can handle. */
\r
113 #define httpSOCKET_BUFFER_SIZE 2048
\r
115 /* Standard HTTP response. */
\r
116 #define httpOUTPUT_OK "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
\r
118 /* Hard coded HTML components. Other data is generated dynamically. */
\r
119 #define HTML_OUTPUT_BEGIN "\
\r
120 <HTML><head><meta http-equiv=\"Refresh\" content=\"1\;url=index.htm\"></head>\
\r
121 <BODY bgcolor=\"#CCCCFF\"><font face=\"arial\"><H2>FreeRTOS.org<sup>tm</sup> + Tern E-Engine<sup>tm</sup></H2>\
\r
122 <a href=\"http:\/\/www.FreeRTOS.org\">FreeRTOS.org Homepage</a><P>\
\r
123 <HR>Task status table:\r\n\
\r
124 <p><font face=\"courier\"><pre>Task State Priority Stack #<br>\
\r
125 ************************************************<br>"
\r
127 #define HTML_OUTPUT_END "\
\r
128 </font></BODY></HTML>"
\r
130 /*-----------------------------------------------------------*/
\r
133 * Initialise the data structures used to hold the socket status.
\r
135 static void prvHTTPInit( void );
\r
138 * Setup the Ethernet interface with the network addressing information.
\r
140 static void prvNetifInit( void );
\r
143 * Generate the dynamic components of the served WEB page and transmit the
\r
144 * entire page through the socket.
\r
146 static void prvTransmitHTTP( unsigned char socket );
\r
147 /*-----------------------------------------------------------*/
\r
149 /* This variable is simply incremented by the idle task hook so the number of
\r
150 iterations the idle task has performed can be displayed as part of the served
\r
152 unsigned long ulIdleLoops = 0UL;
\r
154 /* Data buffer shared by sockets. */
\r
155 unsigned char ucSocketBuffer[ httpSOCKET_BUFFER_SIZE ];
\r
157 /* The semaphore used by the Ethernet ISR to signal that the task should wake
\r
158 and process whatever caused the interrupt. */
\r
159 xSemaphoreHandle xTCPSemaphore = NULL;
\r
161 /*-----------------------------------------------------------*/
\r
162 void vHTTPTask( void * pvParameters )
\r
165 unsigned char ucState;
\r
167 ( void ) pvParameters;
\r
169 /* Create the semaphore used to communicate between this task and the
\r
171 vSemaphoreCreateBinary( xTCPSemaphore );
\r
173 /* Make sure everything is setup before we start. */
\r
179 /* Wait until the ISR tells us there is something to do. */
\r
180 xSemaphoreTake( xTCPSemaphore, portMAX_DELAY );
\r
182 /* Check each socket. */
\r
183 for( i = 0; i < httpSOCKET_NUM; i++ )
\r
185 ucState = select( i, SEL_CONTROL );
\r
189 case SOCK_ESTABLISHED : /* new connection established. */
\r
191 if( ( sLen = select( i, SEL_RECV ) ) > 0 )
\r
193 if( sLen > httpSOCKET_BUFFER_SIZE )
\r
195 sLen = httpSOCKET_BUFFER_SIZE;
\r
200 sLen = recv( i, ucSocketBuffer, sLen );
\r
202 if( ucConnection[ i ] == 1 )
\r
204 /* This is our first time processing a HTTP
\r
205 request on this connection. */
\r
206 prvTransmitHTTP( i );
\r
207 ucConnection[i] = 0;
\r
213 case SOCK_CLOSE_WAIT :
\r
220 ucConnection[i] = 1;
\r
221 socket( i, SOCK_STREAM, 80, 0x00 );
\r
222 NBlisten( i ); /* reinitialize socket. */
\r
228 /*-----------------------------------------------------------*/
\r
230 static void prvHTTPInit( void )
\r
232 unsigned char ucIndex;
\r
234 /* There are 4 total sockets available; we will claim 3 for HTTP. */
\r
235 for(ucIndex = 0; ucIndex < httpSOCKET_NUM; ucIndex++)
\r
237 socket( ucIndex, SOCK_STREAM, httpPORT, 0x00 );
\r
238 NBlisten( ucIndex );
\r
239 ucConnection[ ucIndex ] = 1;
\r
242 /*-----------------------------------------------------------*/
\r
244 static void prvNetifInit( void )
\r
249 setMACAddr( ( unsigned char * ) ucMacAddress );
\r
250 setgateway( ( unsigned char * ) ucGatewayAddress );
\r
251 setsubmask( ( unsigned char * ) ucSubnetMask );
\r
252 setIP( ( unsigned char * ) ucIPAddress );
\r
254 /* See definition of 'sysinit' in socket.c
\r
255 - 8 KB transmit buffer, and 8 KB receive buffer available. These buffers
\r
256 are shared by all 4 channels.
\r
257 - (0x55, 0x55) configures the send and receive buffers at
\r
258 httpSOCKET_BUFFER_SIZE bytes for each of the 4 channels. */
\r
259 sysinit( 0x55, 0x55 );
\r
261 /*-----------------------------------------------------------*/
\r
263 static void prvTransmitHTTP(unsigned char socket)
\r
265 extern short usCheckStatus;
\r
267 /* Send the http and html headers. */
\r
268 send( socket, ( unsigned char * ) httpOUTPUT_OK, strlen( httpOUTPUT_OK ) );
\r
269 send( socket, ( unsigned char * ) HTML_OUTPUT_BEGIN, strlen( HTML_OUTPUT_BEGIN ) );
\r
271 /* Generate then send the table showing the status of each task. */
\r
272 vTaskList( ucSocketBuffer );
\r
273 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
275 /* Send the number of times the idle task has looped. */
\r
276 sprintf( ucSocketBuffer, "</pre></font><p><br>The idle task has looped 0x%08lx times<br>", ulIdleLoops );
\r
277 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
279 /* Send the tick count. */
\r
280 sprintf( ucSocketBuffer, "The tick count is 0x%08lx<br>", xTaskGetTickCount() );
\r
281 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
283 /* Show a message indicating whether or not the check task has discovered
\r
284 an error in any of the standard demo tasks. */
\r
285 if( usCheckStatus == 0 )
\r
287 sprintf( ucSocketBuffer, "No errors detected." );
\r
288 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
292 sprintf( ucSocketBuffer, "<font color=\"red\">An error has been detected in at least one task %x.</font><p>", usCheckStatus );
\r
293 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
296 /* Finish the page off. */
\r
297 send( socket, (unsigned char*)HTML_OUTPUT_END, strlen(HTML_OUTPUT_END));
\r
299 /* Must make sure the data is gone before closing the socket. */
\r
300 while( !tx_empty( socket ) )
\r
302 vTaskDelay( httpTX_WAIT );
\r
306 /*-----------------------------------------------------------*/
\r
308 void vApplicationIdleHook( void )
\r