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
80 #include "r_ether.h"
\r
82 /* Demo includes. */
\r
83 #include "ParTest.h"
\r
85 /*-----------------------------------------------------------*/
\r
87 /* How long to wait before attempting to connect the MAC again. */
\r
88 #define uipINIT_WAIT ( 100 / portTICK_RATE_MS )
\r
90 /* Shortcut to the header within the Rx buffer. */
\r
91 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
93 /* Standard constant. */
\r
94 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
96 /* The ARP timer and the periodic timer share a callback function, so the
\r
97 respective timer IDs are used to determine which timer actually expired. These
\r
98 constants are assigned to the timer IDs. */
\r
99 #define uipARP_TIMER 0
\r
100 #define uipPERIODIC_TIMER 1
\r
102 /* A block time of zero ticks simply means, "don't block". */
\r
103 #define uipDONT_BLOCK 0UL
\r
105 /*-----------------------------------------------------------*/
\r
108 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
110 static void prvSetMACAddress( void );
\r
113 * Perform any uIP initialisation necessary.
\r
115 static void prvInitialise_uIP( void );
\r
118 * The callback function that is assigned to both the periodic timer and the
\r
121 static void prvUIPTimerCallback( xTimerHandle xTimer );
\r
124 * Port functions required by the uIP stack.
\r
126 clock_time_t clock_time( void );
\r
128 /*-----------------------------------------------------------*/
\r
130 /* The queue used to send TCP/IP events to the uIP stack. */
\r
131 xQueueHandle xEMACEventQueue = NULL;
\r
133 /*-----------------------------------------------------------*/
\r
135 clock_time_t clock_time( void )
\r
137 return xTaskGetTickCount();
\r
139 /*-----------------------------------------------------------*/
\r
141 void vuIP_Task( void *pvParameters )
\r
144 unsigned long ulNewEvent = 0UL;
\r
145 unsigned long ulUIP_Events = 0UL;
\r
147 ( void ) pvParameters;
\r
149 /* Initialise the uIP stack. */
\r
150 prvInitialise_uIP();
\r
152 /* Initialise the MAC. */
\r
155 while( lEMACWaitForLink() != pdPASS )
\r
157 vTaskDelay( uipINIT_WAIT );
\r
162 if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
\r
164 /* Is there received data ready to be processed? */
\r
165 uip_len = ( unsigned short ) ulEMACRead();
\r
167 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
169 /* Standard uIP loop taken from the uIP manual. */
\r
170 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
175 /* If the above function invocation resulted in data that
\r
176 should be sent out on the network, the global variable
\r
177 uip_len is set to a value > 0. */
\r
184 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
188 /* If the above function invocation resulted in data that
\r
189 should be sent out on the network, the global variable
\r
190 uip_len is set to a value > 0. */
\r
199 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
203 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
205 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
207 for( i = 0; i < UIP_CONNS; i++ )
\r
211 /* If the above function invocation resulted in data that
\r
212 should be sent out on the network, the global variable
\r
213 uip_len is set to a value > 0. */
\r
222 /* Call the ARP timer function every 10 seconds. */
\r
223 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
225 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
229 if( ulUIP_Events == pdFALSE )
\r
231 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
232 ulUIP_Events |= ulNewEvent;
\r
236 /*-----------------------------------------------------------*/
\r
238 static void prvInitialise_uIP( void )
\r
240 xTimerHandle xARPTimer, xPeriodicTimer;
\r
241 uip_ipaddr_t xIPAddr;
\r
242 const unsigned long ul_uIPEventQueueLength = 10UL;
\r
244 /* Initialise the uIP stack. */
\r
246 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
247 uip_sethostaddr( &xIPAddr );
\r
248 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
249 uip_setnetmask( &xIPAddr );
\r
250 prvSetMACAddress();
\r
253 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
254 xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );
\r
256 /* Create and start the uIP timers. */
\r
257 xARPTimer = xTimerCreate( ( const signed char * const ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
258 ( 10000UL / portTICK_RATE_MS ), /* Timer period. */
\r
259 pdTRUE, /* Autor-reload. */
\r
260 ( void * ) uipARP_TIMER,
\r
261 prvUIPTimerCallback
\r
264 xPeriodicTimer = xTimerCreate( ( const signed char * const ) "PeriodicTimer",
\r
265 ( 50 / portTICK_RATE_MS ),
\r
266 pdTRUE, /* Autor-reload. */
\r
267 ( void * ) uipPERIODIC_TIMER,
\r
268 prvUIPTimerCallback
\r
271 configASSERT( xARPTimer );
\r
272 configASSERT( xPeriodicTimer );
\r
274 xTimerStart( xARPTimer, portMAX_DELAY );
\r
275 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
277 /*-----------------------------------------------------------*/
\r
279 static void prvUIPTimerCallback( xTimerHandle xTimer )
\r
281 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
282 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
284 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
286 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
288 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
291 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
294 default : /* Should not get here. */
\r
298 /*-----------------------------------------------------------*/
\r
300 static void prvSetMACAddress( void )
\r
302 struct uip_eth_addr xAddr;
\r
304 /* Configure the MAC address in the uIP stack. */
\r
305 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
306 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
307 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
308 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
309 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
310 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
311 uip_setethaddr( xAddr );
\r
313 /*-----------------------------------------------------------*/
\r
315 void vApplicationProcessFormInput( char *pcInputString )
\r
319 /* Only interested in processing form input if this is the IO page. */
\r
320 c = strstr( pcInputString, "io.shtml" );
\r
324 /* Is there a command in the string? */
\r
325 c = strstr( pcInputString, "?" );
\r
328 /* Turn the LED's on or off in accordance with the check box status. */
\r
329 if( strstr( c, "LED0=1" ) != NULL )
\r
331 /* Turn the LEDs on. */
\r
332 vParTestSetLED( 7, 1 );
\r
333 vParTestSetLED( 8, 1 );
\r
334 vParTestSetLED( 9, 1 );
\r
335 vParTestSetLED( 10, 1 );
\r
339 /* Turn the LEDs off. */
\r
340 vParTestSetLED( 7, 0 );
\r
341 vParTestSetLED( 8, 0 );
\r
342 vParTestSetLED( 9, 0 );
\r
343 vParTestSetLED( 10, 0 );
\r
348 /* Commands to turn LEDs off are not always explicit. */
\r
349 vParTestSetLED( 7, 0 );
\r
350 vParTestSetLED( 8, 0 );
\r
351 vParTestSetLED( 9, 0 );
\r
352 vParTestSetLED( 10, 0 );
\r