2 FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the 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.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 /* Standard includes. */
\r
55 /* Scheduler includes. */
\r
56 #include "FreeRTOS.h"
\r
62 #include "uip_arp.h"
\r
65 #include "clock-arch.h"
\r
67 /* Demo includes. */
\r
68 #include "EthDev_LPC17xx.h"
\r
70 #include "ParTest.h"
\r
72 #include "LPC17xx.h"
\r
73 #include "core_cm3.h"
\r
74 /*-----------------------------------------------------------*/
\r
76 /* How long to wait before attempting to connect the MAC again. */
\r
77 #define uipINIT_WAIT 100
\r
79 /* Shortcut to the header within the Rx buffer. */
\r
80 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
82 /* Standard constant. */
\r
83 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
85 /*-----------------------------------------------------------*/
\r
88 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
90 static void prvSetMACAddress( void );
\r
93 * Port functions required by the uIP stack.
\r
95 void clock_init( void );
\r
96 clock_time_t clock_time( void );
\r
98 /*-----------------------------------------------------------*/
\r
100 /* The semaphore used by the ISR to wake the uIP task. */
\r
101 xSemaphoreHandle xEMACSemaphore = NULL;
\r
103 /*-----------------------------------------------------------*/
\r
105 void clock_init(void)
\r
107 /* This is done when the scheduler starts. */
\r
109 /*-----------------------------------------------------------*/
\r
111 clock_time_t clock_time( void )
\r
113 return xTaskGetTickCount();
\r
115 /*-----------------------------------------------------------*/
\r
117 void vuIP_Task( void *pvParameters )
\r
120 uip_ipaddr_t xIPAddr;
\r
121 struct timer periodic_timer, arp_timer;
\r
122 extern void ( vEMAC_ISR_Wrapper )( void );
\r
124 ( void ) pvParameters;
\r
126 /* Initialise the uIP stack. */
\r
127 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
128 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
130 uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
131 uip_sethostaddr( xIPAddr );
\r
132 uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
133 uip_setnetmask( xIPAddr );
\r
136 /* Create the semaphore used to wake the uIP task. */
\r
137 vSemaphoreCreateBinary( xEMACSemaphore );
\r
139 /* Initialise the MAC. */
\r
140 while( lEMACInit() != pdPASS )
\r
142 vTaskDelay( uipINIT_WAIT );
\r
145 portENTER_CRITICAL();
\r
147 ETH_INTENABLE = ( INT_RX_DONE | INT_TX_DONE );
\r
148 /* set the interrupt priority */
\r
149 NVIC_SetPriority( ENET_IRQn, configMAX_SYSCALL_INTERRUPT_PRIORITY );
\r
150 /* enable the interrupt */
\r
151 NVIC_EnableIRQ( ENET_IRQn );
\r
152 prvSetMACAddress();
\r
154 portEXIT_CRITICAL();
\r
159 /* Is there received data ready to be processed? */
\r
160 uip_len = ulGetEMACRxData();
\r
162 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
164 /* Standard uIP loop taken from the uIP manual. */
\r
165 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
170 /* If the above function invocation resulted in data that
\r
171 should be sent out on the network, the global variable
\r
172 uip_len is set to a value > 0. */
\r
176 vSendEMACTxData( uip_len );
\r
179 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
183 /* If the above function invocation resulted in data that
\r
184 should be sent out on the network, the global variable
\r
185 uip_len is set to a value > 0. */
\r
188 vSendEMACTxData( uip_len );
\r
194 if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )
\r
196 timer_reset( &periodic_timer );
\r
197 for( i = 0; i < UIP_CONNS; i++ )
\r
201 /* If the above function invocation resulted in data that
\r
202 should be sent out on the network, the global variable
\r
203 uip_len is set to a value > 0. */
\r
207 vSendEMACTxData( uip_len );
\r
211 /* Call the ARP timer function every 10 seconds. */
\r
212 if( timer_expired( &arp_timer ) )
\r
214 timer_reset( &arp_timer );
\r
220 /* We did not receive a packet, and there was no periodic
\r
221 processing to perform. Block for a fixed period. If a packet
\r
222 is received during this period we will be woken by the ISR
\r
223 giving us the Semaphore. */
\r
224 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvSetMACAddress( void )
\r
233 struct uip_eth_addr xAddr;
\r
235 /* Configure the MAC address in the uIP stack. */
\r
236 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
237 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
238 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
239 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
240 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
241 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
242 uip_setethaddr( xAddr );
\r
244 /*-----------------------------------------------------------*/
\r
246 void vApplicationProcessFormInput( portCHAR *pcInputString )
\r
249 static portCHAR cMessageForDisplay[ 32 ];
\r
250 extern xQueueHandle xLCDQueue;
\r
251 xLCDMessage xLCDMessage;
\r
253 /* Process the form input sent by the IO page of the served HTML. */
\r
255 c = strstr( pcInputString, "?" );
\r
258 /* Turn LED's on or off in accordance with the check box status. */
\r
259 if( strstr( c, "LED0=1" ) != NULL )
\r
262 vParTestSetLED( 1 << 7, 1 );
\r
267 vParTestSetLED( 1 << 7, 0 );
\r
270 /* Find the start of the text to be displayed on the LCD. */
\r
271 pcText = strstr( c, "LCD=" );
\r
272 pcText += strlen( "LCD=" );
\r
274 /* Terminate the file name for further processing within uIP. */
\r
277 /* Terminate the LCD string. */
\r
278 c = strstr( pcText, " " );
\r
284 /* Add required spaces. */
\r
285 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
290 /* Write the message to the LCD. */
\r
291 strcpy( cMessageForDisplay, pcText );
\r
292 xLCDMessage.pcMessage = cMessageForDisplay;
\r
293 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r