2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* Standard includes. */
\r
68 /* Scheduler includes. */
\r
69 #include "FreeRTOS.h"
\r
75 #include "net/uip.h"
\r
76 #include "net/uip_arp.h"
\r
77 #include "apps/httpd/httpd.h"
\r
78 #include "sys/timer.h"
\r
79 #include "net/clock-arch.h"
\r
82 /* Demo includes. */
\r
83 #include "ParTest.h"
\r
85 /* The buffer used by the uIP stack to both receive and send. In this case,
\r
86 because the Ethernet driver is implemented to be zero copy - the uip_buf
\r
87 variable is just a pointer to an Ethernet buffer, and not a buffer in its own
\r
89 extern unsigned char *uip_buf;
\r
91 /* The ARP timer and the periodic timer share a callback function, so the
\r
92 respective timer IDs are used to determine which timer actually expired. These
\r
93 constants are assigned to the timer IDs. */
\r
94 #define uipARP_TIMER 0
\r
95 #define uipPERIODIC_TIMER 1
\r
97 /* The length of the queue used to send events from timers or the Ethernet
\r
98 driver to the uIP stack. */
\r
99 #define uipEVENT_QUEUE_LENGTH 10
\r
101 /* A block time of zero simply means "don't block". */
\r
102 #define uipDONT_BLOCK 0UL
\r
104 /* Shortcut to the header within the Rx buffer. */
\r
105 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
107 /*-----------------------------------------------------------*/
\r
110 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
112 static void prvSetMACAddress( void );
\r
115 * Perform any uIP initialisation required to ready the stack for http
\r
118 static void prvInitialise_uIP( void );
\r
121 * The callback function that is assigned to both the periodic timer and the
\r
124 static void prvUIPTimerCallback( xTimerHandle xTimer );
\r
127 * Port functions required by the uIP stack.
\r
129 clock_time_t clock_time( void );
\r
131 /*-----------------------------------------------------------*/
\r
133 /* The queue used to send TCP/IP events to the uIP stack. */
\r
134 xQueueHandle xEMACEventQueue = NULL;
\r
136 /*-----------------------------------------------------------*/
\r
138 clock_time_t clock_time( void )
\r
140 return xTaskGetTickCount();
\r
142 /*-----------------------------------------------------------*/
\r
144 void vuIP_Task( void *pvParameters )
\r
147 unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL;
\r
148 unsigned short usPacketLength;
\r
150 /* Just to prevent compiler warnings about the unused parameter. */
\r
151 ( void ) pvParameters;
\r
153 /* Initialise the uIP stack, configuring for web server usage. */
\r
154 prvInitialise_uIP();
\r
156 /* Initialise the MAC and PHY. */
\r
161 /* Is there received data ready to be processed? */
\r
162 usPacketLength = usEMACRead();
\r
164 /* Statements to be executed if data has been received on the Ethernet. */
\r
165 if( ( usPacketLength > 0U ) && ( uip_buf != NULL ) )
\r
167 uip_len = usPacketLength;
\r
169 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
174 /* If the above function invocation resulted in data that
\r
175 should be sent out on the network, the global variable
\r
176 uip_len is set to a value > 0. */
\r
183 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
187 /* If the above function invocation resulted in data that
\r
188 should be sent out on the network, the global variable
\r
189 uip_len is set to a value > 0. */
\r
198 /* Clear the RX event latched in ulUIP_Events - if one was latched. */
\r
199 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
202 /* Statements to be executed if the TCP/IP period timer has expired. */
\r
203 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
205 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
207 if( uip_buf != NULL )
\r
209 for( i = 0; i < UIP_CONNS; i++ )
\r
213 /* If the above function invocation resulted in data that
\r
214 should be sent out on the network, the global variable
\r
215 uip_len is set to a value > 0. */
\r
225 /* Statements to be executed if the ARP timer has expired. */
\r
226 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
228 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
232 /* If all latched events have been cleared - block until another event
\r
234 if( ulUIP_Events == pdFALSE )
\r
236 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
237 ulUIP_Events |= ulNewEvent;
\r
241 /*-----------------------------------------------------------*/
\r
243 static void prvSetMACAddress( void )
\r
245 struct uip_eth_addr xAddr;
\r
247 /* Configure the MAC address in the uIP stack. */
\r
248 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
249 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
250 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
251 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
252 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
253 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
254 uip_setethaddr( xAddr );
\r
256 /*-----------------------------------------------------------*/
\r
258 static void prvInitialise_uIP( void )
\r
260 uip_ipaddr_t xIPAddr;
\r
261 xTimerHandle xARPTimer, xPeriodicTimer;
\r
264 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
265 uip_sethostaddr( &xIPAddr );
\r
266 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
267 uip_setnetmask( &xIPAddr );
\r
268 prvSetMACAddress();
\r
271 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
272 xEMACEventQueue = xQueueCreate( uipEVENT_QUEUE_LENGTH, sizeof( unsigned long ) );
\r
274 /* Create and start the uIP timers. */
\r
275 xARPTimer = xTimerCreate( ( signed char * ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
276 ( 10000UL / portTICK_RATE_MS ), /* Timer period. */
\r
277 pdTRUE, /* Autor-reload. */
\r
278 ( void * ) uipARP_TIMER,
\r
279 prvUIPTimerCallback
\r
282 xPeriodicTimer = xTimerCreate( ( signed char * ) "PeriodicTimer",
\r
283 ( 500UL / portTICK_RATE_MS ),
\r
284 pdTRUE, /* Autor-reload. */
\r
285 ( void * ) uipPERIODIC_TIMER,
\r
286 prvUIPTimerCallback
\r
289 /* Sanity check that the timers were indeed created. */
\r
290 configASSERT( xARPTimer );
\r
291 configASSERT( xPeriodicTimer );
\r
292 configASSERT( xEMACEventQueue );
\r
294 /* These commands will block indefinitely until they succeed, so there is
\r
295 no point in checking their return values. */
\r
296 xTimerStart( xARPTimer, portMAX_DELAY );
\r
297 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
299 /*-----------------------------------------------------------*/
\r
301 static void prvUIPTimerCallback( xTimerHandle xTimer )
\r
303 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
304 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
306 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
307 block. As this callback is assigned to both the ARP and Periodic timers, the
\r
308 first thing to do is ascertain which timer it was that actually expired. */
\r
309 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
311 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
314 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
317 default : /* Should not get here. */
\r
321 /*-----------------------------------------------------------*/
\r
323 void vApplicationProcessFormInput( char *pcInputString )
\r
326 const unsigned long ulYellowLED = 2UL;
\r
328 /* Only interested in processing form input if this is the IO page. */
\r
329 c = strstr( pcInputString, "io.shtml" );
\r
333 /* Is there a command in the string? */
\r
334 c = strstr( pcInputString, "?" );
\r
337 /* Turn the LEDs on or off in accordance with the check box status. */
\r
338 if( strstr( c, "LED0=1" ) != NULL )
\r
340 /* Turn the LEDs on. */
\r
341 vParTestSetLED( ulYellowLED, pdTRUE );
\r
345 /* Turn the LEDs off. */
\r
346 vParTestSetLED( ulYellowLED, pdFALSE );
\r
351 /* Some browsers will only imply that a check box is off. */
\r
352 vParTestSetLED( ulYellowLED, pdFALSE );
\r
356 /*-----------------------------------------------------------*/
\r