2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* Standard includes. */
\r
73 /* Scheduler includes. */
\r
74 #include "FreeRTOS.h"
\r
80 #include "net/uip.h"
\r
81 #include "net/uip_arp.h"
\r
82 #include "apps/httpd/httpd.h"
\r
83 #include "sys/timer.h"
\r
84 #include "net/clock-arch.h"
\r
85 #include "r_ether.h"
\r
87 /* Demo includes. */
\r
88 #include "ParTest.h"
\r
90 /*-----------------------------------------------------------*/
\r
92 /* How long to wait before attempting to connect the MAC again. */
\r
93 #define uipINIT_WAIT ( 100 / portTICK_PERIOD_MS )
\r
95 /* Shortcut to the header within the Rx buffer. */
\r
96 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
98 /* Standard constant. */
\r
99 #define uipTOTAL_FRAME_HEADER_SIZE 54
\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 /* A block time of zero ticks simply means, "don't block". */
\r
108 #define uipDONT_BLOCK 0UL
\r
110 /*-----------------------------------------------------------*/
\r
113 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
115 static void prvSetMACAddress( void );
\r
118 * Perform any uIP initialisation necessary.
\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( TimerHandle_t 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 QueueHandle_t 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;
\r
150 unsigned long ulUIP_Events = 0UL;
\r
152 ( void ) pvParameters;
\r
154 /* Initialise the uIP stack. */
\r
155 prvInitialise_uIP();
\r
157 /* Initialise the MAC. */
\r
160 while( lEMACWaitForLink() != pdPASS )
\r
162 vTaskDelay( uipINIT_WAIT );
\r
167 if( ( ulUIP_Events & uipETHERNET_RX_EVENT ) != 0UL )
\r
169 /* Is there received data ready to be processed? */
\r
170 uip_len = ( unsigned short ) ulEMACRead();
\r
172 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
174 /* Standard uIP loop taken from the uIP manual. */
\r
175 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
180 /* If the above function invocation resulted in data that
\r
181 should be sent out on the network, the global variable
\r
182 uip_len is set to a value > 0. */
\r
189 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
193 /* If the above function invocation resulted in data that
\r
194 should be sent out on the network, the global variable
\r
195 uip_len is set to a value > 0. */
\r
204 ulUIP_Events &= ~uipETHERNET_RX_EVENT;
\r
208 if( ( ulUIP_Events & uipPERIODIC_TIMER_EVENT ) != 0UL )
\r
210 ulUIP_Events &= ~uipPERIODIC_TIMER_EVENT;
\r
212 for( i = 0; i < UIP_CONNS; i++ )
\r
216 /* If the above function invocation resulted in data that
\r
217 should be sent out on the network, the global variable
\r
218 uip_len is set to a value > 0. */
\r
227 /* Call the ARP timer function every 10 seconds. */
\r
228 if( ( ulUIP_Events & uipARP_TIMER_EVENT ) != 0 )
\r
230 ulUIP_Events &= ~uipARP_TIMER_EVENT;
\r
234 if( ulUIP_Events == pdFALSE )
\r
236 xQueueReceive( xEMACEventQueue, &ulNewEvent, portMAX_DELAY );
\r
237 ulUIP_Events |= ulNewEvent;
\r
241 /*-----------------------------------------------------------*/
\r
243 static void prvInitialise_uIP( void )
\r
245 TimerHandle_t xARPTimer, xPeriodicTimer;
\r
246 uip_ipaddr_t xIPAddr;
\r
247 const unsigned long ul_uIPEventQueueLength = 10UL;
\r
249 /* Initialise the uIP stack. */
\r
251 uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
252 uip_sethostaddr( &xIPAddr );
\r
253 uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
254 uip_setnetmask( &xIPAddr );
\r
255 prvSetMACAddress();
\r
258 /* Create the queue used to sent TCP/IP events to the uIP stack. */
\r
259 xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) );
\r
261 /* Create and start the uIP timers. */
\r
262 xARPTimer = xTimerCreate( "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */
\r
263 ( 10000UL / portTICK_PERIOD_MS ), /* Timer period. */
\r
264 pdTRUE, /* Autor-reload. */
\r
265 ( void * ) uipARP_TIMER,
\r
266 prvUIPTimerCallback
\r
269 xPeriodicTimer = xTimerCreate( "PeriodicTimer",
\r
270 ( 50 / portTICK_PERIOD_MS ),
\r
271 pdTRUE, /* Autor-reload. */
\r
272 ( void * ) uipPERIODIC_TIMER,
\r
273 prvUIPTimerCallback
\r
276 configASSERT( xARPTimer );
\r
277 configASSERT( xPeriodicTimer );
\r
279 xTimerStart( xARPTimer, portMAX_DELAY );
\r
280 xTimerStart( xPeriodicTimer, portMAX_DELAY );
\r
282 /*-----------------------------------------------------------*/
\r
284 static void prvUIPTimerCallback( TimerHandle_t xTimer )
\r
286 static const unsigned long ulARPTimerExpired = uipARP_TIMER_EVENT;
\r
287 static const unsigned long ulPeriodicTimerExpired = uipPERIODIC_TIMER_EVENT;
\r
289 /* This is a time callback, so calls to xQueueSend() must not attempt to
\r
291 switch( ( int ) pvTimerGetTimerID( xTimer ) )
\r
293 case uipARP_TIMER : xQueueSend( xEMACEventQueue, &ulARPTimerExpired, uipDONT_BLOCK );
\r
296 case uipPERIODIC_TIMER : xQueueSend( xEMACEventQueue, &ulPeriodicTimerExpired, uipDONT_BLOCK );
\r
299 default : /* Should not get here. */
\r
303 /*-----------------------------------------------------------*/
\r
305 static void prvSetMACAddress( void )
\r
307 struct uip_eth_addr xAddr;
\r
309 /* Configure the MAC address in the uIP stack. */
\r
310 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
311 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
312 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
313 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
314 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
315 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
316 uip_setethaddr( xAddr );
\r
318 /*-----------------------------------------------------------*/
\r
320 void vApplicationProcessFormInput( char *pcInputString )
\r
324 /* Only interested in processing form input if this is the IO page. */
\r
325 c = strstr( pcInputString, "io.shtml" );
\r
329 /* Is there a command in the string? */
\r
330 c = strstr( pcInputString, "?" );
\r
333 /* Turn the LED's on or off in accordance with the check box status. */
\r
334 if( strstr( c, "LED0=1" ) != NULL )
\r
336 /* Turn the LEDs on. */
\r
337 vParTestSetLED( 7, 1 );
\r
338 vParTestSetLED( 8, 1 );
\r
339 vParTestSetLED( 9, 1 );
\r
340 vParTestSetLED( 10, 1 );
\r
344 /* Turn the LEDs off. */
\r
345 vParTestSetLED( 7, 0 );
\r
346 vParTestSetLED( 8, 0 );
\r
347 vParTestSetLED( 9, 0 );
\r
348 vParTestSetLED( 10, 0 );
\r
353 /* Commands to turn LEDs off are not always explicit. */
\r
354 vParTestSetLED( 7, 0 );
\r
355 vParTestSetLED( 8, 0 );
\r
356 vParTestSetLED( 9, 0 );
\r
357 vParTestSetLED( 10, 0 );
\r