2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\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 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
47 /* Standard includes. */
\r
50 /* Scheduler includes. */
\r
51 #include "FreeRTOS.h"
\r
57 #include "uip_arp.h"
\r
60 #include "clock-arch.h"
\r
62 /* Demo includes. */
\r
64 #include "partest.h"
\r
66 /*-----------------------------------------------------------*/
\r
68 /* MAC address configuration. */
\r
69 #define uipMAC_ADDR0 0x00
\r
70 #define uipMAC_ADDR1 0x12
\r
71 #define uipMAC_ADDR2 0x13
\r
72 #define uipMAC_ADDR3 0x10
\r
73 #define uipMAC_ADDR4 0x15
\r
74 #define uipMAC_ADDR5 0x11
\r
76 /* IP address configuration. */
\r
77 #define uipIP_ADDR0 192
\r
78 #define uipIP_ADDR1 168
\r
79 #define uipIP_ADDR2 0
\r
80 #define uipIP_ADDR3 200
\r
82 /* How long to wait before attempting to connect the MAC again. */
\r
83 #define uipINIT_WAIT 200
\r
85 /* Shortcut to the header within the Rx buffer. */
\r
86 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
88 /* Standard constant. */
\r
89 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
91 /*-----------------------------------------------------------*/
\r
94 * Send the uIP buffer to the MAC.
\r
96 static void prvENET_Send(void);
\r
99 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
101 static void prvSetMACAddress( void );
\r
104 * Port functions required by the uIP stack.
\r
106 void clock_init( void );
\r
107 clock_time_t clock_time( void );
\r
109 /*-----------------------------------------------------------*/
\r
111 /* The semaphore used by the ISR to wake the uIP task. */
\r
112 extern xSemaphoreHandle xEMACSemaphore;
\r
114 /*-----------------------------------------------------------*/
\r
116 void clock_init(void)
\r
118 /* This is done when the scheduler starts. */
\r
120 /*-----------------------------------------------------------*/
\r
122 clock_time_t clock_time( void )
\r
124 return xTaskGetTickCount();
\r
126 /*-----------------------------------------------------------*/
\r
128 void vuIP_Task( void *pvParameters )
\r
131 uip_ipaddr_t xIPAddr;
\r
132 struct timer periodic_timer, arp_timer;
\r
133 extern void ( vEMAC_ISR_Wrapper )( void );
\r
135 /* Create the semaphore used by the ISR to wake this task. */
\r
136 vSemaphoreCreateBinary( xEMACSemaphore );
\r
138 /* Initialise the uIP stack. */
\r
139 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
140 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
142 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
143 uip_sethostaddr( xIPAddr );
\r
146 /* Initialise the MAC. */
\r
147 while( Init_EMAC() != pdPASS )
\r
149 vTaskDelay( uipINIT_WAIT );
\r
152 portENTER_CRITICAL();
\r
154 IntEnable = INT_RX_DONE;
\r
155 VICIntEnable |= 0x00200000;
\r
156 VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
\r
157 prvSetMACAddress();
\r
159 portEXIT_CRITICAL();
\r
164 /* Is there received data ready to be processed? */
\r
165 uip_len = uiGetEMACRxData( uip_buf );
\r
169 /* Standard uIP loop taken from the uIP manual. */
\r
170 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
175 /* If the above function invocation resulted in data that
\r
176 should be sent out on the network, the global variable
\r
177 uip_len is set to a value > 0. */
\r
184 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
188 /* If the above function invocation resulted in data that
\r
189 should be sent out on the network, the global variable
\r
190 uip_len is set to a value > 0. */
\r
199 if( timer_expired( &periodic_timer ) )
\r
201 timer_reset( &periodic_timer );
\r
202 for( i = 0; i < UIP_CONNS; i++ )
\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
216 /* Call the ARP timer function every 10 seconds. */
\r
217 if( timer_expired( &arp_timer ) )
\r
219 timer_reset( &arp_timer );
\r
225 /* We did not receive a packet, and there was no periodic
\r
226 processing to perform. Block for a fixed period. If a packet
\r
227 is received during this period we will be woken by the ISR
\r
228 giving us the Semaphore. */
\r
229 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
234 /*-----------------------------------------------------------*/
\r
236 static void prvENET_Send(void)
\r
240 /* Copy the header into the Tx buffer. */
\r
241 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
242 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
244 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
247 DoSend_EMAC( uip_len );
\r
251 /* Copy the header into the Tx buffer. */
\r
252 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
253 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
255 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
258 DoSend_EMAC( uip_len );
\r
260 /*-----------------------------------------------------------*/
\r
262 static void prvSetMACAddress( void )
\r
264 struct uip_eth_addr xAddr;
\r
266 /* Configure the MAC address in the uIP stack. */
\r
267 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
268 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
269 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
270 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
271 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
272 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
273 uip_setethaddr( xAddr );
\r
275 /*-----------------------------------------------------------*/
\r
277 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
280 static portCHAR cMessageForDisplay[ 32 ];
\r
281 extern xQueueHandle xLCDQueue;
\r
282 xLCDMessage xLCDMessage;
\r
284 /* Process the form input sent by the IO page of the served HTML. */
\r
286 c = strstr( pcInputString, "?" );
\r
289 /* Turn LED's on or off in accordance with the check box status. */
\r
290 if( strstr( c, "LED0=1" ) != NULL )
\r
292 vParTestSetLED( 5, 0 );
\r
296 vParTestSetLED( 5, 1 );
\r
299 if( strstr( c, "LED1=1" ) != NULL )
\r
301 vParTestSetLED( 6, 0 );
\r
305 vParTestSetLED( 6, 1 );
\r
308 if( strstr( c, "LED2=1" ) != NULL )
\r
310 vParTestSetLED( 7, 0 );
\r
314 vParTestSetLED( 7, 1 );
\r
317 /* Find the start of the text to be displayed on the LCD. */
\r
318 pcText = strstr( c, "LCD=" );
\r
319 pcText += strlen( "LCD=" );
\r
321 /* Terminate the file name for further processing within uIP. */
\r
324 /* Terminate the LCD string. */
\r
325 c = strstr( pcText, " " );
\r
331 /* Add required spaces. */
\r
332 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
337 /* Write the message to the LCD. */
\r
338 strcpy( cMessageForDisplay, pcText );
\r
339 xLCDMessage.xColumn = 0;
\r
340 xLCDMessage.pcMessage = cMessageForDisplay;
\r
341 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r