2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
64 /* Standard includes. */
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
74 #include "uip_arp.h"
\r
77 #include "clock-arch.h"
\r
79 /* Demo includes. */
\r
81 #include "partest.h"
\r
83 /*-----------------------------------------------------------*/
\r
85 /* MAC address configuration. */
\r
86 #define uipMAC_ADDR0 0x00
\r
87 #define uipMAC_ADDR1 0x12
\r
88 #define uipMAC_ADDR2 0x13
\r
89 #define uipMAC_ADDR3 0x10
\r
90 #define uipMAC_ADDR4 0x15
\r
91 #define uipMAC_ADDR5 0x11
\r
93 /* IP address configuration. */
\r
94 #define uipIP_ADDR0 192
\r
95 #define uipIP_ADDR1 168
\r
96 #define uipIP_ADDR2 0
\r
97 #define uipIP_ADDR3 200
\r
99 /* How long to wait before attempting to connect the MAC again. */
\r
100 #define uipINIT_WAIT 200
\r
102 /* Shortcut to the header within the Rx buffer. */
\r
103 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
105 /* Standard constant. */
\r
106 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
108 /*-----------------------------------------------------------*/
\r
111 * Send the uIP buffer to the MAC.
\r
113 static void prvENET_Send(void);
\r
116 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
118 static void prvSetMACAddress( void );
\r
121 * Port functions required by the uIP stack.
\r
123 void clock_init( void );
\r
124 clock_time_t clock_time( void );
\r
126 /*-----------------------------------------------------------*/
\r
128 /* The semaphore used by the ISR to wake the uIP task. */
\r
129 extern xSemaphoreHandle xEMACSemaphore;
\r
131 /*-----------------------------------------------------------*/
\r
133 void clock_init(void)
\r
135 /* This is done when the scheduler starts. */
\r
137 /*-----------------------------------------------------------*/
\r
139 clock_time_t clock_time( void )
\r
141 return xTaskGetTickCount();
\r
143 /*-----------------------------------------------------------*/
\r
145 void vuIP_Task( void *pvParameters )
\r
148 uip_ipaddr_t xIPAddr;
\r
149 struct timer periodic_timer, arp_timer;
\r
150 extern void ( vEMAC_ISR_Wrapper )( void );
\r
152 /* Create the semaphore used by the ISR to wake this task. */
\r
153 vSemaphoreCreateBinary( xEMACSemaphore );
\r
155 /* Initialise the uIP stack. */
\r
156 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
157 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
159 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
160 uip_sethostaddr( xIPAddr );
\r
163 /* Initialise the MAC. */
\r
164 while( Init_EMAC() != pdPASS )
\r
166 vTaskDelay( uipINIT_WAIT );
\r
169 portENTER_CRITICAL();
\r
171 IntEnable = INT_RX_DONE;
\r
172 VICIntEnable |= 0x00200000;
\r
173 VICVectAddr21 = ( portLONG ) vEMAC_ISR_Wrapper;
\r
174 prvSetMACAddress();
\r
176 portEXIT_CRITICAL();
\r
181 /* Is there received data ready to be processed? */
\r
182 uip_len = uiGetEMACRxData( uip_buf );
\r
186 /* Standard uIP loop taken from the uIP manual. */
\r
187 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
192 /* If the above function invocation resulted in data that
\r
193 should be sent out on the network, the global variable
\r
194 uip_len is set to a value > 0. */
\r
201 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
205 /* If the above function invocation resulted in data that
\r
206 should be sent out on the network, the global variable
\r
207 uip_len is set to a value > 0. */
\r
216 if( timer_expired( &periodic_timer ) )
\r
218 timer_reset( &periodic_timer );
\r
219 for( i = 0; i < UIP_CONNS; i++ )
\r
223 /* If the above function invocation resulted in data that
\r
224 should be sent out on the network, the global variable
\r
225 uip_len is set to a value > 0. */
\r
233 /* Call the ARP timer function every 10 seconds. */
\r
234 if( timer_expired( &arp_timer ) )
\r
236 timer_reset( &arp_timer );
\r
242 /* We did not receive a packet, and there was no periodic
\r
243 processing to perform. Block for a fixed period. If a packet
\r
244 is received during this period we will be woken by the ISR
\r
245 giving us the Semaphore. */
\r
246 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
251 /*-----------------------------------------------------------*/
\r
253 static void prvENET_Send(void)
\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
268 /* Copy the header into the Tx buffer. */
\r
269 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
270 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
272 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
275 DoSend_EMAC( uip_len );
\r
277 /*-----------------------------------------------------------*/
\r
279 static void prvSetMACAddress( void )
\r
281 struct uip_eth_addr xAddr;
\r
283 /* Configure the MAC address in the uIP stack. */
\r
284 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
285 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
286 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
287 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
288 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
289 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
290 uip_setethaddr( xAddr );
\r
292 /*-----------------------------------------------------------*/
\r
294 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
297 static portCHAR cMessageForDisplay[ 32 ];
\r
298 extern xQueueHandle xLCDQueue;
\r
299 xLCDMessage xLCDMessage;
\r
301 /* Process the form input sent by the IO page of the served HTML. */
\r
303 c = strstr( pcInputString, "?" );
\r
306 /* Turn LED's on or off in accordance with the check box status. */
\r
307 if( strstr( c, "LED0=1" ) != NULL )
\r
309 vParTestSetLED( 5, 0 );
\r
313 vParTestSetLED( 5, 1 );
\r
316 if( strstr( c, "LED1=1" ) != NULL )
\r
318 vParTestSetLED( 6, 0 );
\r
322 vParTestSetLED( 6, 1 );
\r
325 if( strstr( c, "LED2=1" ) != NULL )
\r
327 vParTestSetLED( 7, 0 );
\r
331 vParTestSetLED( 7, 1 );
\r
334 /* Find the start of the text to be displayed on the LCD. */
\r
335 pcText = strstr( c, "LCD=" );
\r
336 pcText += strlen( "LCD=" );
\r
338 /* Terminate the file name for further processing within uIP. */
\r
341 /* Terminate the LCD string. */
\r
342 c = strstr( pcText, " " );
\r
348 /* Add required spaces. */
\r
349 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
354 /* Write the message to the LCD. */
\r
355 strcpy( cMessageForDisplay, pcText );
\r
356 xLCDMessage.xColumn = 0;
\r
357 xLCDMessage.pcMessage = cMessageForDisplay;
\r
358 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r