2 FreeRTOS V7.3.0 - Copyright (C) 2012 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
32 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
33 distribute a combined work that includes FreeRTOS without being obliged to
\r
34 provide the source code for proprietary components outside of the FreeRTOS
\r
35 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
36 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
37 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
38 more details. You should have received a copy of the GNU General Public
\r
39 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
40 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
41 by writing to Richard Barry, contact details for whom are available on the
\r
46 ***************************************************************************
\r
48 * Having a problem? Start by reading the FAQ "My application does *
\r
49 * not run, what could be wrong?" *
\r
51 * http://www.FreeRTOS.org/FAQHelp.html *
\r
53 ***************************************************************************
\r
56 http://www.FreeRTOS.org - Documentation, training, latest versions, license
\r
57 and contact details.
\r
59 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
60 including FreeRTOS+Trace - an indispensable productivity tool.
\r
62 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
63 the code with commercial support, indemnification, and middleware, under
\r
64 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
65 provide a safety engineered and independently SIL3 certified version under
\r
66 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
69 /* Standard includes. */
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
79 #include "net/uip.h"
\r
80 #include "net/uip_arp.h"
\r
81 #include "apps/httpd/httpd.h"
\r
82 #include "sys/timer.h"
\r
83 #include "net/clock-arch.h"
\r
84 #include "r_ether.h"
\r
86 /* Demo includes. */
\r
87 #include "ParTest.h"
\r
89 /*-----------------------------------------------------------*/
\r
91 /* How long to wait before attempting to connect the MAC again. */
\r
92 #define uipINIT_WAIT ( 100 / portTICK_RATE_MS )
\r
94 /* Shortcut to the header within the Rx buffer. */
\r
95 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
97 /* Standard constant. */
\r
98 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
100 /* The ARP timer and the periodic timer share a callback function, so the
\r
101 respective timer IDs are used to determine which timer actually expired. These
\r
102 constants are assigned to the timer IDs. */
\r
103 #define uipARP_TIMER 0
\r
104 #define uipPERIODIC_TIMER 1
\r
106 /* A block time of zero ticks simply means, "don't block". */
\r
107 #define uipDONT_BLOCK 0UL
\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 necessary.
\r
119 static void prvInitialise_uIP( void );
\r
122 * The callback function that is assigned to both the periodic timer and the
\r
125 static void prvUIPTimerCallback( xTimerHandle xTimer );
\r
128 * Port functions required by the uIP stack.
\r
130 clock_time_t clock_time( void );
\r
132 /*-----------------------------------------------------------*/
\r
134 /* The queue used to send TCP/IP events to the uIP stack. */
\r
135 xQueueHandle xEMACEventQueue = NULL;
\r
137 /*-----------------------------------------------------------*/
\r
139 clock_time_t clock_time( void )
\r
141 return xTaskGetTickCount();
\r
143 /*-----------------------------------------------------------*/
\r
145 void vuIP_Task( void *pvParameters )
\r
148 unsigned long ulNewEvent = 0UL;
\r
149 unsigned long ulUIP_Events = 0UL;
\r
151 ( void ) pvParameters;
\r
153 /* Initialise the uIP stack. */
\r
154 prvInitialise_uIP();
\r
156 /* Initialise the MAC. */
\r
159 while( lEMACWaitForLink() != pdPASS )
\r
161 vTaskDelay( uipINIT_WAIT );
\r
166 if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
\r
168 /* Is there received data ready to be processed? */
\r
169 uip_len = ( unsigned short ) ulEMACRead();
\r
171 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
173 /* Standard uIP loop taken from the uIP manual. */
\r
174 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
179 /* If the above function invocation resulted in data that
\r
180 should be sent out on the network, the global variable
\r
181 uip_len is set to a value > 0. */
\r
188 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
192 /* If the above function invocation resulted in data that
\r
193 should be sent out on the network, the global variable
\r
194 uip_len is set to a value > 0. */
\r
203 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
207 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
209 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\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
226 /* Call the ARP timer function every 10 seconds. */
\r
227 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
229 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
233 if( ulUIP_Events == pdFALSE )
\r
235 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
236 ulUIP_Events |= ulNewEvent;
\r
240 /*-----------------------------------------------------------*/
\r
242 static void prvInitialise_uIP( void )
\r
244 xTimerHandle xARPTimer, xPeriodicTimer;
\r
245 uip_ipaddr_t xIPAddr;
\r
246 const unsigned long ul_uIPEventQueueLength = 10UL;
\r
248 /* Initialise the uIP stack. */
\r
250 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
251 uip_sethostaddr( &xIPAddr );
\r
252 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
253 uip_setnetmask( &xIPAddr );
\r
254 prvSetMACAddress();
\r
257 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
258 xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );
\r
260 /* Create and start the uIP timers. */
\r
261 xARPTimer = xTimerCreate( ( const signed char * const ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
262 ( 10000UL / portTICK_RATE_MS ), /* Timer period. */
\r
263 pdTRUE, /* Autor-reload. */
\r
264 ( void * ) uipARP_TIMER,
\r
265 prvUIPTimerCallback
\r
268 xPeriodicTimer = xTimerCreate( ( const signed char * const ) "PeriodicTimer",
\r
269 ( 50 / portTICK_RATE_MS ),
\r
270 pdTRUE, /* Autor-reload. */
\r
271 ( void * ) uipPERIODIC_TIMER,
\r
272 prvUIPTimerCallback
\r
275 configASSERT( xARPTimer );
\r
276 configASSERT( xPeriodicTimer );
\r
278 xTimerStart( xARPTimer, portMAX_DELAY );
\r
279 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
281 /*-----------------------------------------------------------*/
\r
283 static void prvUIPTimerCallback( xTimerHandle xTimer )
\r
285 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
286 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
288 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
290 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
292 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
295 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
298 default : /* Should not get here. */
\r
302 /*-----------------------------------------------------------*/
\r
304 static void prvSetMACAddress( void )
\r
306 struct uip_eth_addr xAddr;
\r
308 /* Configure the MAC address in the uIP stack. */
\r
309 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
310 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
311 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
312 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
313 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
314 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
315 uip_setethaddr( xAddr );
\r
317 /*-----------------------------------------------------------*/
\r
319 void vApplicationProcessFormInput( char *pcInputString )
\r
323 /* Only interested in processing form input if this is the IO page. */
\r
324 c = strstr( pcInputString, "io.shtml" );
\r
328 /* Is there a command in the string? */
\r
329 c = strstr( pcInputString, "?" );
\r
332 /* Turn the LED's on or off in accordance with the check box status. */
\r
333 if( strstr( c, "LED0=1" ) != NULL )
\r
335 /* Turn the LEDs on. */
\r
336 vParTestSetLED( 7, 1 );
\r
337 vParTestSetLED( 8, 1 );
\r
338 vParTestSetLED( 9, 1 );
\r
339 vParTestSetLED( 10, 1 );
\r
343 /* Turn the LEDs off. */
\r
344 vParTestSetLED( 7, 0 );
\r
345 vParTestSetLED( 8, 0 );
\r
346 vParTestSetLED( 9, 0 );
\r
347 vParTestSetLED( 10, 0 );
\r
352 /* Commands to turn LEDs off are not always explicit. */
\r
353 vParTestSetLED( 7, 0 );
\r
354 vParTestSetLED( 8, 0 );
\r
355 vParTestSetLED( 9, 0 );
\r
356 vParTestSetLED( 10, 0 );
\r