2 FreeRTOS V7.4.1 - 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
75 /* Standard includes. */
\r
78 /* Scheduler includes. */
\r
79 #include "FreeRTOS.h"
\r
85 #include "net/uip.h"
\r
86 #include "net/uip_arp.h"
\r
87 #include "apps/httpd/httpd.h"
\r
88 #include "sys/timer.h"
\r
89 #include "net/clock-arch.h"
\r
92 /* Demo includes. */
\r
93 #include "ParTest.h"
\r
95 /* The buffer used by the uIP stack to both receive and send. In this case,
\r
96 because the Ethernet driver is implemented to be zero copy - the uip_buf
\r
97 variable is just a pointer to an Ethernet buffer, and not a buffer in its own
\r
99 extern unsigned char *uip_buf;
\r
101 /* The ARP timer and the periodic timer share a callback function, so the
\r
102 respective timer IDs are used to determine which timer actually expired. These
\r
103 constants are assigned to the timer IDs. */
\r
104 #define uipARP_TIMER 0
\r
105 #define uipPERIODIC_TIMER 1
\r
107 /* The length of the queue used to send events from timers or the Ethernet
\r
108 driver to the uIP stack. */
\r
109 #define uipEVENT_QUEUE_LENGTH 10
\r
111 /* A block time of zero simply means "don't block". */
\r
112 #define uipDONT_BLOCK 0UL
\r
114 /* Shortcut to the header within the Rx buffer. */
\r
115 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
117 /*-----------------------------------------------------------*/
\r
120 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
122 static void prvSetMACAddress( void );
\r
125 * Perform any uIP initialisation required to ready the stack for http
\r
128 static void prvInitialise_uIP( void );
\r
131 * The callback function that is assigned to both the periodic timer and the
\r
134 static void prvUIPTimerCallback( xTimerHandle xTimer );
\r
137 * Port functions required by the uIP stack.
\r
139 clock_time_t clock_time( void );
\r
141 /*-----------------------------------------------------------*/
\r
143 /* The queue used to send TCP/IP events to the uIP stack. */
\r
144 xQueueHandle xEMACEventQueue = NULL;
\r
146 /*-----------------------------------------------------------*/
\r
148 clock_time_t clock_time( void )
\r
150 return xTaskGetTickCount();
\r
152 /*-----------------------------------------------------------*/
\r
154 void vuIP_Task( void *pvParameters )
\r
157 unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL;
\r
158 unsigned short usPacketLength;
\r
160 /* Just to prevent compiler warnings about the unused parameter. */
\r
161 ( void ) pvParameters;
\r
163 /* Initialise the uIP stack, configuring for web server usage. */
\r
164 prvInitialise_uIP();
\r
166 /* Initialise the MAC and PHY. */
\r
171 /* Is there received data ready to be processed? */
\r
172 usPacketLength = usEMACRead();
\r
174 /* Statements to be executed if data has been received on the Ethernet. */
\r
175 if( ( usPacketLength > 0U ) && ( uip_buf != NULL ) )
\r
177 uip_len = usPacketLength;
\r
179 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
184 /* If the above function invocation resulted in data that
\r
185 should be sent out on the network, the global variable
\r
186 uip_len is set to a value > 0. */
\r
193 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
197 /* If the above function invocation resulted in data that
\r
198 should be sent out on the network, the global variable
\r
199 uip_len is set to a value > 0. */
\r
208 /* Clear the RX event latched in ulUIP_Events - if one was latched. */
\r
209 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
212 /* Statements to be executed if the TCP/IP period timer has expired. */
\r
213 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
215 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
217 if( uip_buf != NULL )
\r
219 for( i = 0; i < UIP_CONNS; i++ )
\r
223 /* If the above function invocation resulted in data that
\r
224 should be sent out on the network, the global variable
\r
225 uip_len is set to a value > 0. */
\r
235 /* Statements to be executed if the ARP timer has expired. */
\r
236 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
238 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
242 /* If all latched events have been cleared - block until another event
\r
244 if( ulUIP_Events == pdFALSE )
\r
246 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
247 ulUIP_Events |= ulNewEvent;
\r
251 /*-----------------------------------------------------------*/
\r
253 static void prvSetMACAddress( void )
\r
255 struct uip_eth_addr xAddr;
\r
257 /* Configure the MAC address in the uIP stack. */
\r
258 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
259 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
260 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
261 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
262 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
263 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
264 uip_setethaddr( xAddr );
\r
266 /*-----------------------------------------------------------*/
\r
268 static void prvInitialise_uIP( void )
\r
270 uip_ipaddr_t xIPAddr;
\r
271 xTimerHandle xARPTimer, xPeriodicTimer;
\r
274 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
275 uip_sethostaddr( &xIPAddr );
\r
276 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
277 uip_setnetmask( &xIPAddr );
\r
278 prvSetMACAddress();
\r
281 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
282 xEMACEventQueue = xQueueCreate( uipEVENT_QUEUE_LENGTH, sizeof( unsigned long ) );
\r
284 /* Create and start the uIP timers. */
\r
285 xARPTimer = xTimerCreate( ( signed char * ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
286 ( 10000UL / portTICK_RATE_MS ), /* Timer period. */
\r
287 pdTRUE, /* Autor-reload. */
\r
288 ( void * ) uipARP_TIMER,
\r
289 prvUIPTimerCallback
\r
292 xPeriodicTimer = xTimerCreate( ( signed char * ) "PeriodicTimer",
\r
293 ( 500UL / portTICK_RATE_MS ),
\r
294 pdTRUE, /* Autor-reload. */
\r
295 ( void * ) uipPERIODIC_TIMER,
\r
296 prvUIPTimerCallback
\r
299 /* Sanity check that the timers were indeed created. */
\r
300 configASSERT( xARPTimer );
\r
301 configASSERT( xPeriodicTimer );
\r
302 configASSERT( xEMACEventQueue );
\r
304 /* These commands will block indefinitely until they succeed, so there is
\r
305 no point in checking their return values. */
\r
306 xTimerStart( xARPTimer, portMAX_DELAY );
\r
307 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
309 /*-----------------------------------------------------------*/
\r
311 static void prvUIPTimerCallback( xTimerHandle xTimer )
\r
313 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
314 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
316 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
317 block. As this callback is assigned to both the ARP and Periodic timers, the
\r
318 first thing to do is ascertain which timer it was that actually expired. */
\r
319 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
321 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
324 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
327 default : /* Should not get here. */
\r
331 /*-----------------------------------------------------------*/
\r
333 void vApplicationProcessFormInput( char *pcInputString )
\r
336 const unsigned long ulYellowLED = 2UL;
\r
338 /* Only interested in processing form input if this is the IO page. */
\r
339 c = strstr( pcInputString, "io.shtml" );
\r
343 /* Is there a command in the string? */
\r
344 c = strstr( pcInputString, "?" );
\r
347 /* Turn the LEDs on or off in accordance with the check box status. */
\r
348 if( strstr( c, "LED0=1" ) != NULL )
\r
350 /* Turn the LEDs on. */
\r
351 vParTestSetLED( ulYellowLED, pdTRUE );
\r
355 /* Turn the LEDs off. */
\r
356 vParTestSetLED( ulYellowLED, pdFALSE );
\r
361 /* Some browsers will only imply that a check box is off. */
\r
362 vParTestSetLED( ulYellowLED, pdFALSE );
\r
366 /*-----------------------------------------------------------*/
\r