2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
53 /* Standard includes. */
\r
56 /* Scheduler includes. */
\r
57 #include "FreeRTOS.h"
\r
63 #include "uip_arp.h"
\r
66 #include "clock-arch.h"
\r
68 /* Demo includes. */
\r
70 #include "partest.h"
\r
72 /*-----------------------------------------------------------*/
\r
74 /* MAC address configuration. */
\r
75 #define uipMAC_ADDR0 0x00
\r
76 #define uipMAC_ADDR1 0x12
\r
77 #define uipMAC_ADDR2 0x13
\r
78 #define uipMAC_ADDR3 0x10
\r
79 #define uipMAC_ADDR4 0x15
\r
80 #define uipMAC_ADDR5 0x11
\r
82 /* IP address configuration. */
\r
83 #define uipIP_ADDR0 192
\r
84 #define uipIP_ADDR1 168
\r
85 #define uipIP_ADDR2 0
\r
86 #define uipIP_ADDR3 200
\r
88 /* How long to wait before attempting to connect the MAC again. */
\r
89 #define uipINIT_WAIT 200
\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 /*-----------------------------------------------------------*/
\r
100 * Send the uIP buffer to the MAC.
\r
102 static void prvENET_Send(void);
\r
105 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
107 static void prvSetMACAddress( void );
\r
110 * Port functions required by the uIP stack.
\r
112 void clock_init( void );
\r
113 clock_time_t clock_time( void );
\r
115 /*-----------------------------------------------------------*/
\r
117 /* The semaphore used by the ISR to wake the uIP task. */
\r
118 extern xSemaphoreHandle xEMACSemaphore;
\r
120 /*-----------------------------------------------------------*/
\r
122 void clock_init(void)
\r
124 /* This is done when the scheduler starts. */
\r
126 /*-----------------------------------------------------------*/
\r
128 clock_time_t clock_time( void )
\r
130 return xTaskGetTickCount();
\r
132 /*-----------------------------------------------------------*/
\r
134 void vuIP_Task( void *pvParameters )
\r
137 uip_ipaddr_t xIPAddr;
\r
138 struct timer periodic_timer, arp_timer;
\r
139 extern void ( vEMAC_ISR_Wrapper )( void );
\r
141 /* Create the semaphore used by the ISR to wake this task. */
\r
142 vSemaphoreCreateBinary( xEMACSemaphore );
\r
144 /* Initialise the uIP stack. */
\r
145 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
146 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
148 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
149 uip_sethostaddr( xIPAddr );
\r
152 /* Initialise the MAC. */
\r
153 while( Init_EMAC() != pdPASS )
\r
155 vTaskDelay( uipINIT_WAIT );
\r
158 portENTER_CRITICAL();
\r
160 IntEnable = INT_RX_DONE;
\r
161 VICIntEnable |= 0x00200000;
\r
162 VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
\r
163 prvSetMACAddress();
\r
165 portEXIT_CRITICAL();
\r
170 /* Is there received data ready to be processed? */
\r
171 uip_len = uiGetEMACRxData( uip_buf );
\r
175 /* Standard uIP loop taken from the uIP manual. */
\r
176 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
181 /* If the above function invocation resulted in data that
\r
182 should be sent out on the network, the global variable
\r
183 uip_len is set to a value > 0. */
\r
190 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
194 /* If the above function invocation resulted in data that
\r
195 should be sent out on the network, the global variable
\r
196 uip_len is set to a value > 0. */
\r
205 if( timer_expired( &periodic_timer ) )
\r
207 timer_reset( &periodic_timer );
\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
222 /* Call the ARP timer function every 10 seconds. */
\r
223 if( timer_expired( &arp_timer ) )
\r
225 timer_reset( &arp_timer );
\r
231 /* We did not receive a packet, and there was no periodic
\r
232 processing to perform. Block for a fixed period. If a packet
\r
233 is received during this period we will be woken by the ISR
\r
234 giving us the Semaphore. */
\r
235 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
240 /*-----------------------------------------------------------*/
\r
242 static void prvENET_Send(void)
\r
246 /* Copy the header into the Tx buffer. */
\r
247 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
248 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
250 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
253 DoSend_EMAC( uip_len );
\r
257 /* Copy the header into the Tx buffer. */
\r
258 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
259 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
261 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
264 DoSend_EMAC( uip_len );
\r
266 /*-----------------------------------------------------------*/
\r
268 static void prvSetMACAddress( void )
\r
270 struct uip_eth_addr xAddr;
\r
272 /* Configure the MAC address in the uIP stack. */
\r
273 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
274 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
275 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
276 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
277 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
278 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
279 uip_setethaddr( xAddr );
\r
281 /*-----------------------------------------------------------*/
\r
283 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
286 static portCHAR cMessageForDisplay[ 32 ];
\r
287 extern xQueueHandle xLCDQueue;
\r
288 xLCDMessage xLCDMessage;
\r
290 /* Process the form input sent by the IO page of the served HTML. */
\r
292 c = strstr( pcInputString, "?" );
\r
295 /* Turn LED's on or off in accordance with the check box status. */
\r
296 if( strstr( c, "LED0=1" ) != NULL )
\r
298 vParTestSetLED( 5, 0 );
\r
302 vParTestSetLED( 5, 1 );
\r
305 if( strstr( c, "LED1=1" ) != NULL )
\r
307 vParTestSetLED( 6, 0 );
\r
311 vParTestSetLED( 6, 1 );
\r
314 if( strstr( c, "LED2=1" ) != NULL )
\r
316 vParTestSetLED( 7, 0 );
\r
320 vParTestSetLED( 7, 1 );
\r
323 /* Find the start of the text to be displayed on the LCD. */
\r
324 pcText = strstr( c, "LCD=" );
\r
325 pcText += strlen( "LCD=" );
\r
327 /* Terminate the file name for further processing within uIP. */
\r
330 /* Terminate the LCD string. */
\r
331 c = strstr( pcText, " " );
\r
337 /* Add required spaces. */
\r
338 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
343 /* Write the message to the LCD. */
\r
344 strcpy( cMessageForDisplay, pcText );
\r
345 xLCDMessage.xColumn = 0;
\r
346 xLCDMessage.pcMessage = cMessageForDisplay;
\r
347 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r