2 FreeRTOS V8.2.2 - Copyright (C) 2015 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 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Very simple task that responds with a single WEB page to http requests.
\r
73 * The WEB page displays task and system status. A semaphore is used to
\r
74 * wake the task when there is processing to perform as determined by the
\r
75 * interrupts generated by the Ethernet interface.
\r
78 /* Standard includes. */
\r
82 /* Tern includes. */
\r
83 #include "utils\system_common.h"
\r
84 #include "i2chip_hw.h"
\r
87 /* FreeRTOS.org includes. */
\r
88 #include <FreeRTOS.h>
\r
92 /* The standard http port on which we are going to listen. */
\r
95 #define httpTX_WAIT 2
\r
97 /* Network address configuration. */
\r
98 const unsigned char ucMacAddress[] = { 12, 128, 12, 34, 56, 78 };
\r
99 const unsigned char ucGatewayAddress[] = { 192, 168, 2, 1 };
\r
100 const unsigned char ucIPAddress[] = { 172, 25, 218, 210 };
\r
101 const unsigned char ucSubnetMask[] = { 255, 255, 255, 0 };
\r
103 /* The number of sockets this task is going to handle. */
\r
104 #define httpSOCKET_NUM 3
\r
105 unsigned char ucConnection[ httpSOCKET_NUM ];
\r
107 /* The maximum data buffer size we can handle. */
\r
108 #define httpSOCKET_BUFFER_SIZE 2048
\r
110 /* Standard HTTP response. */
\r
111 #define httpOUTPUT_OK "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"
\r
113 /* Hard coded HTML components. Other data is generated dynamically. */
\r
114 #define HTML_OUTPUT_BEGIN "\
\r
115 <HTML><head><meta http-equiv=\"Refresh\" content=\"1\;url=index.htm\"></head>\
\r
116 <BODY bgcolor=\"#CCCCFF\"><font face=\"arial\"><H2>FreeRTOS.org<sup>tm</sup> + Tern E-Engine<sup>tm</sup></H2>\
\r
117 <a href=\"http:\/\/www.FreeRTOS.org\">FreeRTOS.org Homepage</a><P>\
\r
118 <HR>Task status table:\r\n\
\r
119 <p><font face=\"courier\"><pre>Task State Priority Stack #<br>\
\r
120 ************************************************<br>"
\r
122 #define HTML_OUTPUT_END "\
\r
123 </font></BODY></HTML>"
\r
125 /*-----------------------------------------------------------*/
\r
128 * Initialise the data structures used to hold the socket status.
\r
130 static void prvHTTPInit( void );
\r
133 * Setup the Ethernet interface with the network addressing information.
\r
135 static void prvNetifInit( void );
\r
138 * Generate the dynamic components of the served WEB page and transmit the
\r
139 * entire page through the socket.
\r
141 static void prvTransmitHTTP( unsigned char socket );
\r
142 /*-----------------------------------------------------------*/
\r
144 /* This variable is simply incremented by the idle task hook so the number of
\r
145 iterations the idle task has performed can be displayed as part of the served
\r
147 unsigned long ulIdleLoops = 0UL;
\r
149 /* Data buffer shared by sockets. */
\r
150 unsigned char ucSocketBuffer[ httpSOCKET_BUFFER_SIZE ];
\r
152 /* The semaphore used by the Ethernet ISR to signal that the task should wake
\r
153 and process whatever caused the interrupt. */
\r
154 SemaphoreHandle_t xTCPSemaphore = NULL;
\r
156 /*-----------------------------------------------------------*/
\r
157 void vHTTPTask( void * pvParameters )
\r
160 unsigned char ucState;
\r
162 ( void ) pvParameters;
\r
164 /* Create the semaphore used to communicate between this task and the
\r
166 vSemaphoreCreateBinary( xTCPSemaphore );
\r
168 /* Make sure everything is setup before we start. */
\r
174 /* Wait until the ISR tells us there is something to do. */
\r
175 xSemaphoreTake( xTCPSemaphore, portMAX_DELAY );
\r
177 /* Check each socket. */
\r
178 for( i = 0; i < httpSOCKET_NUM; i++ )
\r
180 ucState = select( i, SEL_CONTROL );
\r
184 case SOCK_ESTABLISHED : /* new connection established. */
\r
186 if( ( sLen = select( i, SEL_RECV ) ) > 0 )
\r
188 if( sLen > httpSOCKET_BUFFER_SIZE )
\r
190 sLen = httpSOCKET_BUFFER_SIZE;
\r
195 sLen = recv( i, ucSocketBuffer, sLen );
\r
197 if( ucConnection[ i ] == 1 )
\r
199 /* This is our first time processing a HTTP
\r
200 request on this connection. */
\r
201 prvTransmitHTTP( i );
\r
202 ucConnection[i] = 0;
\r
208 case SOCK_CLOSE_WAIT :
\r
215 ucConnection[i] = 1;
\r
216 socket( i, SOCK_STREAM, 80, 0x00 );
\r
217 NBlisten( i ); /* reinitialize socket. */
\r
223 /*-----------------------------------------------------------*/
\r
225 static void prvHTTPInit( void )
\r
227 unsigned char ucIndex;
\r
229 /* There are 4 total sockets available; we will claim 3 for HTTP. */
\r
230 for(ucIndex = 0; ucIndex < httpSOCKET_NUM; ucIndex++)
\r
232 socket( ucIndex, SOCK_STREAM, httpPORT, 0x00 );
\r
233 NBlisten( ucIndex );
\r
234 ucConnection[ ucIndex ] = 1;
\r
237 /*-----------------------------------------------------------*/
\r
239 static void prvNetifInit( void )
\r
244 setMACAddr( ( unsigned char * ) ucMacAddress );
\r
245 setgateway( ( unsigned char * ) ucGatewayAddress );
\r
246 setsubmask( ( unsigned char * ) ucSubnetMask );
\r
247 setIP( ( unsigned char * ) ucIPAddress );
\r
249 /* See definition of 'sysinit' in socket.c
\r
250 - 8 KB transmit buffer, and 8 KB receive buffer available. These buffers
\r
251 are shared by all 4 channels.
\r
252 - (0x55, 0x55) configures the send and receive buffers at
\r
253 httpSOCKET_BUFFER_SIZE bytes for each of the 4 channels. */
\r
254 sysinit( 0x55, 0x55 );
\r
256 /*-----------------------------------------------------------*/
\r
258 static void prvTransmitHTTP(unsigned char socket)
\r
260 extern short usCheckStatus;
\r
262 /* Send the http and html headers. */
\r
263 send( socket, ( unsigned char * ) httpOUTPUT_OK, strlen( httpOUTPUT_OK ) );
\r
264 send( socket, ( unsigned char * ) HTML_OUTPUT_BEGIN, strlen( HTML_OUTPUT_BEGIN ) );
\r
266 /* Generate then send the table showing the status of each task. */
\r
267 vTaskList( ( char * ) ucSocketBuffer );
\r
268 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
270 /* Send the number of times the idle task has looped. */
\r
271 sprintf( ucSocketBuffer, "</pre></font><p><br>The idle task has looped 0x%08lx times<br>", ulIdleLoops );
\r
272 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
274 /* Send the tick count. */
\r
275 sprintf( ucSocketBuffer, "The tick count is 0x%08lx<br>", xTaskGetTickCount() );
\r
276 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
278 /* Show a message indicating whether or not the check task has discovered
\r
279 an error in any of the standard demo tasks. */
\r
280 if( usCheckStatus == 0 )
\r
282 sprintf( ucSocketBuffer, "No errors detected." );
\r
283 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
287 sprintf( ucSocketBuffer, "<font color=\"red\">An error has been detected in at least one task %x.</font><p>", usCheckStatus );
\r
288 send( socket, ( unsigned char * ) ucSocketBuffer, strlen( ucSocketBuffer ) );
\r
291 /* Finish the page off. */
\r
292 send( socket, (unsigned char*)HTML_OUTPUT_END, strlen(HTML_OUTPUT_END));
\r
294 /* Must make sure the data is gone before closing the socket. */
\r
295 while( !tx_empty( socket ) )
\r
297 vTaskDelay( httpTX_WAIT );
\r
301 /*-----------------------------------------------------------*/
\r
303 void vApplicationIdleHook( void )
\r