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
48 /* Standard includes. */
\r
51 /* Scheduler includes. */
\r
52 #include "FreeRTOS.h"
\r
58 #include "uip_arp.h"
\r
61 #include "clock-arch.h"
\r
63 /* Demo includes. */
\r
64 #include "EthDev_LPC17xx.h"
\r
66 #include "ParTest.h"
\r
68 /*-----------------------------------------------------------*/
\r
70 /* How long to wait before attempting to connect the MAC again. */
\r
71 #define uipINIT_WAIT ( 100 / portTICK_RATE_MS )
\r
73 /* Shortcut to the header within the Rx buffer. */
\r
74 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
76 /* Standard constant. */
\r
77 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
79 /*-----------------------------------------------------------*/
\r
82 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
84 static void prvSetMACAddress( void );
\r
87 * Port functions required by the uIP stack.
\r
89 void clock_init( void );
\r
90 clock_time_t clock_time( void );
\r
92 /*-----------------------------------------------------------*/
\r
94 /* The semaphore used by the ISR to wake the uIP task. */
\r
95 xSemaphoreHandle xEMACSemaphore = NULL;
\r
97 /*-----------------------------------------------------------*/
\r
99 void clock_init(void)
\r
101 /* This is done when the scheduler starts. */
\r
103 /*-----------------------------------------------------------*/
\r
105 clock_time_t clock_time( void )
\r
107 return xTaskGetTickCount();
\r
109 /*-----------------------------------------------------------*/
\r
111 void vuIP_Task( void *pvParameters )
\r
114 uip_ipaddr_t xIPAddr;
\r
115 struct timer periodic_timer, arp_timer;
\r
116 extern void ( vEMAC_ISR_Wrapper )( void );
\r
118 ( void ) pvParameters;
\r
120 /* Initialise the uIP stack. */
\r
121 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
122 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
124 uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
125 uip_sethostaddr( xIPAddr );
\r
126 uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );
\r
127 uip_setnetmask( xIPAddr );
\r
130 /* Create the semaphore used to wake the uIP task. */
\r
131 vSemaphoreCreateBinary( xEMACSemaphore );
\r
133 /* Initialise the MAC. */
\r
134 while( lEMACInit() != pdPASS )
\r
136 vTaskDelay( uipINIT_WAIT );
\r
139 portENTER_CRITICAL();
\r
141 EMAC->IntEnable = ( INT_RX_DONE | INT_TX_DONE );
\r
143 /* Set the interrupt priority to the max permissible to cause some
\r
144 interrupt nesting. */
\r
145 NVIC_SetPriority( ENET_IRQn, configEMAC_INTERRUPT_PRIORITY );
\r
147 /* Enable the interrupt. */
\r
148 NVIC_EnableIRQ( ENET_IRQn );
\r
149 prvSetMACAddress();
\r
151 portEXIT_CRITICAL();
\r
156 /* Is there received data ready to be processed? */
\r
157 uip_len = ulGetEMACRxData();
\r
159 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )
\r
161 /* Standard uIP loop taken from the uIP manual. */
\r
162 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
167 /* If the above function invocation resulted in data that
\r
168 should be sent out on the network, the global variable
\r
169 uip_len is set to a value > 0. */
\r
173 vSendEMACTxData( uip_len );
\r
176 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
180 /* If the above function invocation resulted in data that
\r
181 should be sent out on the network, the global variable
\r
182 uip_len is set to a value > 0. */
\r
185 vSendEMACTxData( uip_len );
\r
191 if( timer_expired( &periodic_timer ) && ( uip_buf != NULL ) )
\r
193 timer_reset( &periodic_timer );
\r
194 for( i = 0; i < UIP_CONNS; i++ )
\r
198 /* If the above function invocation resulted in data that
\r
199 should be sent out on the network, the global variable
\r
200 uip_len is set to a value > 0. */
\r
204 vSendEMACTxData( uip_len );
\r
208 /* Call the ARP timer function every 10 seconds. */
\r
209 if( timer_expired( &arp_timer ) )
\r
211 timer_reset( &arp_timer );
\r
217 /* We did not receive a packet, and there was no periodic
\r
218 processing to perform. Block for a fixed period. If a packet
\r
219 is received during this period we will be woken by the ISR
\r
220 giving us the Semaphore. */
\r
221 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
226 /*-----------------------------------------------------------*/
\r
228 static void prvSetMACAddress( void )
\r
230 struct uip_eth_addr xAddr;
\r
232 /* Configure the MAC address in the uIP stack. */
\r
233 xAddr.addr[ 0 ] = configMAC_ADDR0;
\r
234 xAddr.addr[ 1 ] = configMAC_ADDR1;
\r
235 xAddr.addr[ 2 ] = configMAC_ADDR2;
\r
236 xAddr.addr[ 3 ] = configMAC_ADDR3;
\r
237 xAddr.addr[ 4 ] = configMAC_ADDR4;
\r
238 xAddr.addr[ 5 ] = configMAC_ADDR5;
\r
239 uip_setethaddr( xAddr );
\r
241 /*-----------------------------------------------------------*/
\r
243 void vApplicationProcessFormInput( portCHAR *pcInputString )
\r
246 const unsigned long ulLEDNo = 3;
\r
248 /* Process the form input sent by the IO page of the served HTML. */
\r
250 c = strstr( pcInputString, "?" );
\r
253 /* Turn LED's on or off in accordance with the check box status. */
\r
254 if( strstr( c, "LED0=1" ) != NULL )
\r
257 vParTestSetLED( ulLEDNo, pdFALSE );
\r
262 vParTestSetLED( ulLEDNo, pdTRUE );
\r