2 FreeRTOS V5.4.1 - 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 * 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 172
\r
78 #define uipIP_ADDR1 25
\r
79 #define uipIP_ADDR2 218
\r
80 #define uipIP_ADDR3 16
\r
82 /* How long to wait before attempting to connect the MAC again. */
\r
83 #define uipINIT_WAIT 100
\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 MAC_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
249 /*-----------------------------------------------------------*/
\r
251 static void prvSetMACAddress( void )
\r
253 struct uip_eth_addr xAddr;
\r
255 /* Configure the MAC address in the uIP stack. */
\r
256 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
257 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
258 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
259 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
260 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
261 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
262 uip_setethaddr( xAddr );
\r
264 /*-----------------------------------------------------------*/
\r
266 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
269 static portCHAR cMessageForDisplay[ 32 ];
\r
270 extern xQueueHandle xLCDQueue;
\r
271 xLCDMessage xLCDMessage;
\r
273 /* Process the form input sent by the IO page of the served HTML. */
\r
275 c = strstr( pcInputString, "?" );
\r
278 /* Turn LED's on or off in accordance with the check box status. */
\r
279 if( strstr( c, "LED0=1" ) != NULL )
\r
281 vParTestSetLED( 5, 0 );
\r
285 vParTestSetLED( 5, 1 );
\r
288 if( strstr( c, "LED1=1" ) != NULL )
\r
290 vParTestSetLED( 6, 0 );
\r
294 vParTestSetLED( 6, 1 );
\r
297 if( strstr( c, "LED2=1" ) != NULL )
\r
299 vParTestSetLED( 7, 0 );
\r
303 vParTestSetLED( 7, 1 );
\r
306 /* Find the start of the text to be displayed on the LCD. */
\r
307 pcText = strstr( c, "LCD=" );
\r
308 pcText += strlen( "LCD=" );
\r
310 /* Terminate the file name for further processing within uIP. */
\r
313 /* Terminate the LCD string. */
\r
314 c = strstr( pcText, " " );
\r
320 /* Add required spaces. */
\r
321 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
326 /* Write the message to the LCD. */
\r
327 strcpy( cMessageForDisplay, pcText );
\r
328 xLCDMessage.xColumn = 0;
\r
329 xLCDMessage.pcMessage = cMessageForDisplay;
\r
330 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r