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
49 /* Standard includes. */
\r
52 /* Scheduler includes. */
\r
53 #include "FreeRTOS.h"
\r
59 #include "uip_arp.h"
\r
62 #include "clock-arch.h"
\r
64 /* Demo includes. */
\r
65 #include "EthDev_LPC17xx.h"
\r
67 #include "ParTest.h"
\r
69 /*-----------------------------------------------------------*/
\r
71 /* How long to wait before attempting to connect the MAC again. */
\r
72 #define uipINIT_WAIT ( 100 / portTICK_RATE_MS )
\r
74 /* Shortcut to the header within the Rx buffer. */
\r
75 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
77 /* Standard constant. */
\r
78 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
80 /*-----------------------------------------------------------*/
\r
83 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
85 static void prvSetMACAddress( void );
\r
88 * Port functions required by the uIP stack.
\r
90 void clock_init( void );
\r
91 clock_time_t clock_time( void );
\r
93 /*-----------------------------------------------------------*/
\r
95 /* The semaphore used by the ISR to wake the uIP task. */
\r
96 xSemaphoreHandle xEMACSemaphore = NULL;
\r
98 /*-----------------------------------------------------------*/
\r
100 void clock_init(void)
\r
102 /* This is done when the scheduler starts. */
\r
104 /*-----------------------------------------------------------*/
\r
106 clock_time_t clock_time( void )
\r
108 return xTaskGetTickCount();
\r
110 /*-----------------------------------------------------------*/
\r
112 void vuIP_Task( void *pvParameters )
\r
115 uip_ipaddr_t xIPAddr;
\r
116 struct timer periodic_timer, arp_timer;
\r
117 extern void ( vEMAC_ISR_Wrapper )( void );
\r
119 ( void ) pvParameters;
\r
121 /* Initialise the uIP stack. */
\r
122 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
123 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
125 uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
126 uip_sethostaddr( xIPAddr );
\r
127 uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
128 uip_setnetmask( xIPAddr );
\r
131 /* Create the semaphore used to wake the uIP task. */
\r
132 vSemaphoreCreateBinary( xEMACSemaphore );
\r
134 /* Initialise the MAC. */
\r
135 while( lEMACInit() != pdPASS )
\r
137 vTaskDelay( uipINIT_WAIT );
\r
140 portENTER_CRITICAL();
\r
142 EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
\r
144 /* Set the interrupt priority to the max permissible to cause some
\r
145 interrupt nesting. */
\r
146 NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
\r
148 /* Enable the interrupt. */
\r
149 NVIC_EnableIRQ( ENET_IRQn );
\r
150 prvSetMACAddress();
\r
152 portEXIT_CRITICAL();
\r
157 /* Is there received data ready to be processed? */
\r
158 uip_len = ulGetEMACRxData();
\r
160 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
162 /* Standard uIP loop taken from the uIP manual. */
\r
163 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
168 /* If the above function invocation resulted in data that
\r
169 should be sent out on the network, the global variable
\r
170 uip_len is set to a value > 0. */
\r
174 vSendEMACTxData( uip_len );
\r
177 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
181 /* If the above function invocation resulted in data that
\r
182 should be sent out on the network, the global variable
\r
183 uip_len is set to a value > 0. */
\r
186 vSendEMACTxData( uip_len );
\r
192 if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )
\r
194 timer_reset( &periodic_timer );
\r
195 for( i = 0; i < UIP_CONNS; i++ )
\r
199 /* If the above function invocation resulted in data that
\r
200 should be sent out on the network, the global variable
\r
201 uip_len is set to a value > 0. */
\r
205 vSendEMACTxData( uip_len );
\r
209 /* Call the ARP timer function every 10 seconds. */
\r
210 if( timer_expired( &arp_timer ) )
\r
212 timer_reset( &arp_timer );
\r
218 /* We did not receive a packet, and there was no periodic
\r
219 processing to perform. Block for a fixed period. If a packet
\r
220 is received during this period we will be woken by the ISR
\r
221 giving us the Semaphore. */
\r
222 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
227 /*-----------------------------------------------------------*/
\r
229 static void prvSetMACAddress( void )
\r
231 struct uip_eth_addr xAddr;
\r
233 /* Configure the MAC address in the uIP stack. */
\r
234 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
235 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
236 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
237 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
238 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
239 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
240 uip_setethaddr( xAddr );
\r
242 /*-----------------------------------------------------------*/
\r
244 void vApplicationProcessFormInput( char *pcInputString )
\r
247 extern void vParTestSetLEDState( long lState );
\r
249 /* Process the form input sent by the IO page of the served HTML. */
\r
251 c = strstr( pcInputString, "?" );
\r
254 /* Turn the FIO1 LED's on or off in accordance with the check box status. */
\r
255 if( strstr( c, "LED0=1" ) != NULL )
\r
257 vParTestSetLEDState( pdTRUE );
\r
261 vParTestSetLEDState( pdFALSE );
\r