2 FreeRTOS V8.0.0:rc1 - 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 distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
65 /* Standard includes. */
\r
68 /* Scheduler includes. */
\r
69 #include "FreeRTOS.h"
\r
75 #include "uip_arp.h"
\r
78 #include "clock-arch.h"
\r
80 /* Demo includes. */
\r
82 #include "partest.h"
\r
84 /*-----------------------------------------------------------*/
\r
86 /* MAC address configuration. */
\r
87 #define uipMAC_ADDR0 0x00
\r
88 #define uipMAC_ADDR1 0x12
\r
89 #define uipMAC_ADDR2 0x13
\r
90 #define uipMAC_ADDR3 0x10
\r
91 #define uipMAC_ADDR4 0x15
\r
92 #define uipMAC_ADDR5 0x11
\r
94 /* IP address configuration. */
\r
95 #define uipIP_ADDR0 172
\r
96 #define uipIP_ADDR1 25
\r
97 #define uipIP_ADDR2 218
\r
98 #define uipIP_ADDR3 16
\r
100 /* How long to wait before attempting to connect the MAC again. */
\r
101 #define uipINIT_WAIT 100
\r
103 /* Shortcut to the header within the Rx buffer. */
\r
104 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
106 /* Standard constant. */
\r
107 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
109 /*-----------------------------------------------------------*/
\r
112 * Send the uIP buffer to the MAC.
\r
114 static void prvENET_Send(void);
\r
117 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
119 static void prvSetMACAddress( void );
\r
122 * Port functions required by the uIP stack.
\r
124 void clock_init( void );
\r
125 clock_time_t clock_time( void );
\r
127 /*-----------------------------------------------------------*/
\r
129 /* The semaphore used by the ISR to wake the uIP task. */
\r
130 extern xSemaphoreHandle xEMACSemaphore;
\r
132 /*-----------------------------------------------------------*/
\r
134 void clock_init(void)
\r
136 /* This is done when the scheduler starts. */
\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 uip_ipaddr_t xIPAddr;
\r
150 struct timer periodic_timer, arp_timer;
\r
151 extern void ( vEMAC_ISR_Wrapper )( void );
\r
153 /* Create the semaphore used by the ISR to wake this task. */
\r
154 vSemaphoreCreateBinary( xEMACSemaphore );
\r
156 /* Initialise the uIP stack. */
\r
157 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
158 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
160 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
161 uip_sethostaddr( xIPAddr );
\r
164 /* Initialise the MAC. */
\r
165 while( Init_EMAC() != pdPASS )
\r
167 vTaskDelay( uipINIT_WAIT );
\r
170 portENTER_CRITICAL();
\r
172 MAC_INTENABLE = INT_RX_DONE;
\r
173 VICIntEnable |= 0x00200000;
\r
174 VICVectAddr21 = ( long ) vEMAC_ISR_Wrapper;
\r
175 prvSetMACAddress();
\r
177 portEXIT_CRITICAL();
\r
182 /* Is there received data ready to be processed? */
\r
183 uip_len = uiGetEMACRxData( uip_buf );
\r
187 /* Standard uIP loop taken from the uIP manual. */
\r
188 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\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
202 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
206 /* If the above function invocation resulted in data that
\r
207 should be sent out on the network, the global variable
\r
208 uip_len is set to a value > 0. */
\r
217 if( timer_expired( &periodic_timer ) )
\r
219 timer_reset( &periodic_timer );
\r
220 for( i = 0; i < UIP_CONNS; i++ )
\r
224 /* If the above function invocation resulted in data that
\r
225 should be sent out on the network, the global variable
\r
226 uip_len is set to a value > 0. */
\r
234 /* Call the ARP timer function every 10 seconds. */
\r
235 if( timer_expired( &arp_timer ) )
\r
237 timer_reset( &arp_timer );
\r
243 /* We did not receive a packet, and there was no periodic
\r
244 processing to perform. Block for a fixed period. If a packet
\r
245 is received during this period we will be woken by the ISR
\r
246 giving us the Semaphore. */
\r
247 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
252 /*-----------------------------------------------------------*/
\r
254 static void prvENET_Send(void)
\r
258 /* Copy the header into the Tx buffer. */
\r
259 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
260 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
262 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
265 DoSend_EMAC( uip_len );
\r
267 /*-----------------------------------------------------------*/
\r
269 static void prvSetMACAddress( void )
\r
271 struct uip_eth_addr xAddr;
\r
273 /* Configure the MAC address in the uIP stack. */
\r
274 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
275 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
276 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
277 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
278 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
279 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
280 uip_setethaddr( xAddr );
\r
282 /*-----------------------------------------------------------*/
\r
284 void vApplicationProcessFormInput( char *pcInputString, portBASE_TYPE xInputLength )
\r
287 static char cMessageForDisplay[ 32 ];
\r
288 extern xQueueHandle xLCDQueue;
\r
289 xLCDMessage xLCDMessage;
\r
291 /* Process the form input sent by the IO page of the served HTML. */
\r
293 c = strstr( pcInputString, "?" );
\r
296 /* Turn LED's on or off in accordance with the check box status. */
\r
297 if( strstr( c, "LED0=1" ) != NULL )
\r
299 vParTestSetLED( 5, 0 );
\r
303 vParTestSetLED( 5, 1 );
\r
306 if( strstr( c, "LED1=1" ) != NULL )
\r
308 vParTestSetLED( 6, 0 );
\r
312 vParTestSetLED( 6, 1 );
\r
315 if( strstr( c, "LED2=1" ) != NULL )
\r
317 vParTestSetLED( 7, 0 );
\r
321 vParTestSetLED( 7, 1 );
\r
324 /* Find the start of the text to be displayed on the LCD. */
\r
325 pcText = strstr( c, "LCD=" );
\r
326 pcText += strlen( "LCD=" );
\r
328 /* Terminate the file name for further processing within uIP. */
\r
331 /* Terminate the LCD string. */
\r
332 c = strstr( pcText, " " );
\r
338 /* Add required spaces. */
\r
339 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
344 /* Write the message to the LCD. */
\r
345 strcpy( cMessageForDisplay, pcText );
\r
346 xLCDMessage.xColumn = 0;
\r
347 xLCDMessage.pcMessage = cMessageForDisplay;
\r
348 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r