2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
48 /* Standard includes. */
\r
51 /* Scheduler includes. */
\r
52 #include "FreeRTOS.h"
\r
58 #include "uip_arp.h"
\r
61 #include "clock-arch.h"
\r
63 /* Demo includes. */
\r
65 #include "partest.h"
\r
67 /*-----------------------------------------------------------*/
\r
69 /* MAC address configuration. */
\r
70 #define uipMAC_ADDR0 0x00
\r
71 #define uipMAC_ADDR1 0x12
\r
72 #define uipMAC_ADDR2 0x13
\r
73 #define uipMAC_ADDR3 0x10
\r
74 #define uipMAC_ADDR4 0x15
\r
75 #define uipMAC_ADDR5 0x11
\r
77 /* IP address configuration. */
\r
78 #define uipIP_ADDR0 192
\r
79 #define uipIP_ADDR1 168
\r
80 #define uipIP_ADDR2 0
\r
81 #define uipIP_ADDR3 200
\r
83 /* How long to wait before attempting to connect the MAC again. */
\r
84 #define uipINIT_WAIT 200
\r
86 /* Shortcut to the header within the Rx buffer. */
\r
87 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
89 /* Standard constant. */
\r
90 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
92 /*-----------------------------------------------------------*/
\r
95 * Send the uIP buffer to the MAC.
\r
97 static void prvENET_Send(void);
\r
100 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
102 static void prvSetMACAddress( void );
\r
105 * Port functions required by the uIP stack.
\r
107 void clock_init( void );
\r
108 clock_time_t clock_time( void );
\r
110 /*-----------------------------------------------------------*/
\r
112 /* The semaphore used by the ISR to wake the uIP task. */
\r
113 extern xSemaphoreHandle xEMACSemaphore;
\r
115 /*-----------------------------------------------------------*/
\r
117 void clock_init(void)
\r
119 /* This is done when the scheduler starts. */
\r
121 /*-----------------------------------------------------------*/
\r
123 clock_time_t clock_time( void )
\r
125 return xTaskGetTickCount();
\r
127 /*-----------------------------------------------------------*/
\r
129 void vuIP_Task( void *pvParameters )
\r
132 uip_ipaddr_t xIPAddr;
\r
133 struct timer periodic_timer, arp_timer;
\r
134 extern void ( vEMAC_ISR_Wrapper )( void );
\r
136 /* Create the semaphore used by the ISR to wake this task. */
\r
137 vSemaphoreCreateBinary( xEMACSemaphore );
\r
139 /* Initialise the uIP stack. */
\r
140 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
141 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
143 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
144 uip_sethostaddr( xIPAddr );
\r
147 /* Initialise the MAC. */
\r
148 while( Init_EMAC() != pdPASS )
\r
150 vTaskDelay( uipINIT_WAIT );
\r
153 portENTER_CRITICAL();
\r
155 IntEnable = INT_RX_DONE;
\r
156 VICIntEnable |= 0x00200000;
\r
157 VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
\r
158 prvSetMACAddress();
\r
160 portEXIT_CRITICAL();
\r
165 /* Is there received data ready to be processed? */
\r
166 uip_len = uiGetEMACRxData( uip_buf );
\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 if( timer_expired( &periodic_timer ) )
\r
202 timer_reset( &periodic_timer );
\r
203 for( i = 0; i < UIP_CONNS; i++ )
\r
207 /* If the above function invocation resulted in data that
\r
208 should be sent out on the network, the global variable
\r
209 uip_len is set to a value > 0. */
\r
217 /* Call the ARP timer function every 10 seconds. */
\r
218 if( timer_expired( &arp_timer ) )
\r
220 timer_reset( &arp_timer );
\r
226 /* We did not receive a packet, and there was no periodic
\r
227 processing to perform. Block for a fixed period. If a packet
\r
228 is received during this period we will be woken by the ISR
\r
229 giving us the Semaphore. */
\r
230 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
235 /*-----------------------------------------------------------*/
\r
237 static void prvENET_Send(void)
\r
241 /* Copy the header into the Tx buffer. */
\r
242 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
243 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
245 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
248 DoSend_EMAC( uip_len );
\r
252 /* Copy the header into the Tx buffer. */
\r
253 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
254 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
256 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
259 DoSend_EMAC( uip_len );
\r
261 /*-----------------------------------------------------------*/
\r
263 static void prvSetMACAddress( void )
\r
265 struct uip_eth_addr xAddr;
\r
267 /* Configure the MAC address in the uIP stack. */
\r
268 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
269 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
270 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
271 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
272 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
273 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
274 uip_setethaddr( xAddr );
\r
276 /*-----------------------------------------------------------*/
\r
278 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
281 static portCHAR cMessageForDisplay[ 32 ];
\r
282 extern xQueueHandle xLCDQueue;
\r
283 xLCDMessage xLCDMessage;
\r
285 /* Process the form input sent by the IO page of the served HTML. */
\r
287 c = strstr( pcInputString, "?" );
\r
290 /* Turn LED's on or off in accordance with the check box status. */
\r
291 if( strstr( c, "LED0=1" ) != NULL )
\r
293 vParTestSetLED( 5, 0 );
\r
297 vParTestSetLED( 5, 1 );
\r
300 if( strstr( c, "LED1=1" ) != NULL )
\r
302 vParTestSetLED( 6, 0 );
\r
306 vParTestSetLED( 6, 1 );
\r
309 if( strstr( c, "LED2=1" ) != NULL )
\r
311 vParTestSetLED( 7, 0 );
\r
315 vParTestSetLED( 7, 1 );
\r
318 /* Find the start of the text to be displayed on the LCD. */
\r
319 pcText = strstr( c, "LCD=" );
\r
320 pcText += strlen( "LCD=" );
\r
322 /* Terminate the file name for further processing within uIP. */
\r
325 /* Terminate the LCD string. */
\r
326 c = strstr( pcText, " " );
\r
332 /* Add required spaces. */
\r
333 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
338 /* Write the message to the LCD. */
\r
339 strcpy( cMessageForDisplay, pcText );
\r
340 xLCDMessage.xColumn = 0;
\r
341 xLCDMessage.pcMessage = cMessageForDisplay;
\r
342 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r