2 FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Standard includes. */
\r
69 /* Scheduler includes. */
\r
70 #include "FreeRTOS.h"
\r
76 #include "net/uip.h"
\r
77 #include "net/uip_arp.h"
\r
78 #include "apps/httpd/httpd.h"
\r
79 #include "sys/timer.h"
\r
80 #include "net/clock-arch.h"
\r
81 #include "r_ether.h"
\r
83 /* Demo includes. */
\r
84 #include "ParTest.h"
\r
86 /*-----------------------------------------------------------*/
\r
88 /* How long to wait before attempting to connect the MAC again. */
\r
89 #define uipINIT_WAIT ( 100 / portTICK_PERIOD_MS )
\r
91 /* Shortcut to the header within the Rx buffer. */
\r
92 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
94 /* Standard constant. */
\r
95 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
97 /* The ARP timer and the periodic timer share a callback function, so the
\r
98 respective timer IDs are used to determine which timer actually expired. These
\r
99 constants are assigned to the timer IDs. */
\r
100 #define uipARP_TIMER 0
\r
101 #define uipPERIODIC_TIMER 1
\r
103 /* A block time of zero ticks simply means, "don't block". */
\r
104 #define uipDONT_BLOCK 0UL
\r
106 /*-----------------------------------------------------------*/
\r
109 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
111 static void prvSetMACAddress( void );
\r
114 * Perform any uIP initialisation necessary.
\r
116 static void prvInitialise_uIP( void );
\r
119 * The callback function that is assigned to both the periodic timer and the
\r
122 static void prvUIPTimerCallback( TimerHandle_t xTimer );
\r
125 * Port functions required by the uIP stack.
\r
127 clock_time_t clock_time( void );
\r
129 /*-----------------------------------------------------------*/
\r
131 /* The queue used to send TCP/IP events to the uIP stack. */
\r
132 QueueHandle_t xEMACEventQueue = NULL;
\r
134 /*-----------------------------------------------------------*/
\r
136 clock_time_t clock_time( void )
\r
138 return xTaskGetTickCount();
\r
140 /*-----------------------------------------------------------*/
\r
142 void vuIP_Task( void *pvParameters )
\r
145 unsigned long ulNewEvent = 0UL;
\r
146 unsigned long ulUIP_Events = 0UL;
\r
148 ( void ) pvParameters;
\r
150 /* Initialise the uIP stack. */
\r
151 prvInitialise_uIP();
\r
153 /* Initialise the MAC. */
\r
156 while( lEMACWaitForLink() != pdPASS )
\r
158 vTaskDelay( uipINIT_WAIT );
\r
163 if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
\r
165 /* Is there received data ready to be processed? */
\r
166 uip_len = ( unsigned short ) ulEMACRead();
\r
168 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
170 /* Standard uIP loop taken from the uIP manual. */
\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 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
204 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
206 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
208 for( i = 0; i < UIP_CONNS; i++ )
\r
212 /* If the above function invocation resulted in data that
\r
213 should be sent out on the network, the global variable
\r
214 uip_len is set to a value > 0. */
\r
223 /* Call the ARP timer function every 10 seconds. */
\r
224 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
226 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
230 if( ulUIP_Events == pdFALSE )
\r
232 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
233 ulUIP_Events |= ulNewEvent;
\r
237 /*-----------------------------------------------------------*/
\r
239 static void prvInitialise_uIP( void )
\r
241 TimerHandle_t xARPTimer, xPeriodicTimer;
\r
242 uip_ipaddr_t xIPAddr;
\r
243 const unsigned long ul_uIPEventQueueLength = 10UL;
\r
245 /* Initialise the uIP stack. */
\r
247 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
248 uip_sethostaddr( &xIPAddr );
\r
249 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
250 uip_setnetmask( &xIPAddr );
\r
251 prvSetMACAddress();
\r
254 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
255 xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );
\r
257 /* Create and start the uIP timers. */
\r
258 xARPTimer = xTimerCreate( "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
259 ( 10000UL / portTICK_PERIOD_MS ), /* Timer period. */
\r
260 pdTRUE, /* Autor-reload. */
\r
261 ( void * ) uipARP_TIMER,
\r
262 prvUIPTimerCallback
\r
265 xPeriodicTimer = xTimerCreate( "PeriodicTimer",
\r
266 ( 50 / portTICK_PERIOD_MS ),
\r
267 pdTRUE, /* Autor-reload. */
\r
268 ( void * ) uipPERIODIC_TIMER,
\r
269 prvUIPTimerCallback
\r
272 configASSERT( xARPTimer );
\r
273 configASSERT( xPeriodicTimer );
\r
275 xTimerStart( xARPTimer, portMAX_DELAY );
\r
276 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
278 /*-----------------------------------------------------------*/
\r
280 static void prvUIPTimerCallback( TimerHandle_t xTimer )
\r
282 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
283 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
285 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
287 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
289 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
292 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
295 default : /* Should not get here. */
\r
299 /*-----------------------------------------------------------*/
\r
301 static void prvSetMACAddress( void )
\r
303 struct uip_eth_addr xAddr;
\r
305 /* Configure the MAC address in the uIP stack. */
\r
306 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
307 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
308 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
309 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
310 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
311 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
312 uip_setethaddr( xAddr );
\r
314 /*-----------------------------------------------------------*/
\r
316 void vApplicationProcessFormInput( char *pcInputString )
\r
320 /* Only interested in processing form input if this is the IO page. */
\r
321 c = strstr( pcInputString, "io.shtml" );
\r
325 /* Is there a command in the string? */
\r
326 c = strstr( pcInputString, "?" );
\r
329 /* Turn the LED's on or off in accordance with the check box status. */
\r
330 if( strstr( c, "LED0=1" ) != NULL )
\r
332 /* Turn the LEDs on. */
\r
333 vParTestSetLED( 7, 1 );
\r
334 vParTestSetLED( 8, 1 );
\r
335 vParTestSetLED( 9, 1 );
\r
336 vParTestSetLED( 10, 1 );
\r
340 /* Turn the LEDs off. */
\r
341 vParTestSetLED( 7, 0 );
\r
342 vParTestSetLED( 8, 0 );
\r
343 vParTestSetLED( 9, 0 );
\r
344 vParTestSetLED( 10, 0 );
\r
349 /* Commands to turn LEDs off are not always explicit. */
\r
350 vParTestSetLED( 7, 0 );
\r
351 vParTestSetLED( 8, 0 );
\r
352 vParTestSetLED( 9, 0 );
\r
353 vParTestSetLED( 10, 0 );
\r