2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 /* Standard includes. */
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
77 #include "net/uip.h"
\r
78 #include "net/uip_arp.h"
\r
79 #include "apps/httpd/httpd.h"
\r
80 #include "sys/timer.h"
\r
81 #include "net/clock-arch.h"
\r
84 /* Demo includes. */
\r
85 #include "ParTest.h"
\r
87 /* The buffer used by the uIP stack to both receive and send. In this case,
\r
88 because the Ethernet driver is implemented to be zero copy - the uip_buf
\r
89 variable is just a pointer to an Ethernet buffer, and not a buffer in its own
\r
91 extern unsigned char *uip_buf;
\r
93 /* The ARP timer and the periodic timer share a callback function, so the
\r
94 respective timer IDs are used to determine which timer actually expired. These
\r
95 constants are assigned to the timer IDs. */
\r
96 #define uipARP_TIMER 0
\r
97 #define uipPERIODIC_TIMER 1
\r
99 /* The length of the queue used to send events from timers or the Ethernet
\r
100 driver to the uIP stack. */
\r
101 #define uipEVENT_QUEUE_LENGTH 10
\r
103 /* A block time of zero simply means "don't block". */
\r
104 #define uipDONT_BLOCK 0UL
\r
106 /* Shortcut to the header within the Rx buffer. */
\r
107 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
109 /*-----------------------------------------------------------*/
\r
112 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
114 static void prvSetMACAddress( void );
\r
117 * Perform any uIP initialisation required to ready the stack for http
\r
120 static void prvInitialise_uIP( void );
\r
123 * The callback function that is assigned to both the periodic timer and the
\r
126 static void prvUIPTimerCallback( xTimerHandle xTimer );
\r
129 * Port functions required by the uIP stack.
\r
131 clock_time_t clock_time( void );
\r
133 /*-----------------------------------------------------------*/
\r
135 /* The queue used to send TCP/IP events to the uIP stack. */
\r
136 xQueueHandle xEMACEventQueue = NULL;
\r
138 /*-----------------------------------------------------------*/
\r
140 clock_time_t clock_time( void )
\r
142 return xTaskGetTickCount();
\r
144 /*-----------------------------------------------------------*/
\r
146 void vuIP_Task( void *pvParameters )
\r
149 unsigned long ulNewEvent = 0UL, ulUIP_Events = 0UL;
\r
150 unsigned short usPacketLength;
\r
152 /* Just to prevent compiler warnings about the unused parameter. */
\r
153 ( void ) pvParameters;
\r
155 /* Initialise the uIP stack, configuring for web server usage. */
\r
156 prvInitialise_uIP();
\r
158 /* Initialise the MAC and PHY. */
\r
163 /* Is there received data ready to be processed? */
\r
164 usPacketLength = usEMACRead();
\r
166 /* Statements to be executed if data has been received on the Ethernet. */
\r
167 if( ( usPacketLength > 0U ) && ( uip_buf != NULL ) )
\r
169 uip_len = usPacketLength;
\r
171 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
176 /* If the above function invocation resulted in data that
\r
177 should be sent out on the network, the global variable
\r
178 uip_len is set to a value > 0. */
\r
185 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
189 /* If the above function invocation resulted in data that
\r
190 should be sent out on the network, the global variable
\r
191 uip_len is set to a value > 0. */
\r
200 /* Clear the RX event latched in ulUIP_Events - if one was latched. */
\r
201 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
204 /* Statements to be executed if the TCP/IP period timer has expired. */
\r
205 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
207 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
209 if( uip_buf != NULL )
\r
211 for( i = 0; i < UIP_CONNS; i++ )
\r
215 /* If the above function invocation resulted in data that
\r
216 should be sent out on the network, the global variable
\r
217 uip_len is set to a value > 0. */
\r
227 /* Statements to be executed if the ARP timer has expired. */
\r
228 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
230 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
234 /* If all latched events have been cleared - block until another event
\r
236 if( ulUIP_Events == pdFALSE )
\r
238 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
239 ulUIP_Events |= ulNewEvent;
\r
243 /*-----------------------------------------------------------*/
\r
245 static void prvSetMACAddress( void )
\r
247 struct uip_eth_addr xAddr;
\r
249 /* Configure the MAC address in the uIP stack. */
\r
250 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
251 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
252 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
253 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
254 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
255 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
256 uip_setethaddr( xAddr );
\r
258 /*-----------------------------------------------------------*/
\r
260 static void prvInitialise_uIP( void )
\r
262 uip_ipaddr_t xIPAddr;
\r
263 xTimerHandle xARPTimer, xPeriodicTimer;
\r
266 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
267 uip_sethostaddr( &xIPAddr );
\r
268 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
269 uip_setnetmask( &xIPAddr );
\r
270 prvSetMACAddress();
\r
273 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
274 xEMACEventQueue = xQueueCreate( uipEVENT_QUEUE_LENGTH, sizeof( unsigned long ) );
\r
276 /* Create and start the uIP timers. */
\r
277 xARPTimer = xTimerCreate( ( signed char * ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
278 ( 10000UL / portTICK_RATE_MS ), /* Timer period. */
\r
279 pdTRUE, /* Autor-reload. */
\r
280 ( void * ) uipARP_TIMER,
\r
281 prvUIPTimerCallback
\r
284 xPeriodicTimer = xTimerCreate( ( signed char * ) "PeriodicTimer",
\r
285 ( 500UL / portTICK_RATE_MS ),
\r
286 pdTRUE, /* Autor-reload. */
\r
287 ( void * ) uipPERIODIC_TIMER,
\r
288 prvUIPTimerCallback
\r
291 /* Sanity check that the timers were indeed created. */
\r
292 configASSERT( xARPTimer );
\r
293 configASSERT( xPeriodicTimer );
\r
294 configASSERT( xEMACEventQueue );
\r
296 /* These commands will block indefinitely until they succeed, so there is
\r
297 no point in checking their return values. */
\r
298 xTimerStart( xARPTimer, portMAX_DELAY );
\r
299 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
301 /*-----------------------------------------------------------*/
\r
303 static void prvUIPTimerCallback( xTimerHandle xTimer )
\r
305 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
306 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
308 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
309 block. As this callback is assigned to both the ARP and Periodic timers, the
\r
310 first thing to do is ascertain which timer it was that actually expired. */
\r
311 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
313 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
316 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
319 default : /* Should not get here. */
\r
323 /*-----------------------------------------------------------*/
\r
325 void vApplicationProcessFormInput( char *pcInputString )
\r
328 const unsigned long ulYellowLED = 2UL;
\r
330 /* Only interested in processing form input if this is the IO page. */
\r
331 c = strstr( pcInputString, "io.shtml" );
\r
335 /* Is there a command in the string? */
\r
336 c = strstr( pcInputString, "?" );
\r
339 /* Turn the LEDs on or off in accordance with the check box status. */
\r
340 if( strstr( c, "LED0=1" ) != NULL )
\r
342 /* Turn the LEDs on. */
\r
343 vParTestSetLED( ulYellowLED, pdTRUE );
\r
347 /* Turn the LEDs off. */
\r
348 vParTestSetLED( ulYellowLED, pdFALSE );
\r
353 /* Some browsers will only imply that a check box is off. */
\r
354 vParTestSetLED( ulYellowLED, pdFALSE );
\r
358 /*-----------------------------------------------------------*/
\r