2 * Modified from an original work that is Copyright (c) 2001-2003, Adam Dunkels.
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
10 * 2. Redistributions in binary form must reproduce the above copyright
\r
11 * notice, this list of conditions and the following disclaimer in the
\r
12 * documentation and/or other materials provided with the distribution.
\r
13 * 3. The name of the author may not be used to endorse or promote
\r
14 * products derived from this software without specific prior
\r
15 * written permission.
\r
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
\r
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
\r
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
\r
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
\r
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
29 * This file is part of the uIP TCP/IP stack.
\r
31 * $Id: main.c,v 1.10.2.4 2003/10/21 21:27:51 adam Exp $
\r
35 /* Standard includes. */
\r
40 /* Scheduler includes. */
\r
41 #include "FreeRTOS.h"
\r
47 #include "uip_arp.h"
\r
50 #include "clock-arch.h"
\r
52 /* Demo includes. */
\r
53 #include "SAM7_EMAC.h"
\r
54 #include "partest.h"
\r
56 /* How long to wait before attempting to connect the MAC again. */
\r
57 #define uipINIT_WAIT ( 100 / portTICK_PERIOD_MS )
\r
59 /* Shortcut to the header within the Rx buffer. */
\r
60 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
62 /* The semaphore used by the ISR to wake the uIP task. */
\r
63 static SemaphoreHandle_t xEMACSemaphore;
\r
65 /*-----------------------------------------------------------*/
\r
67 void vuIP_Task( void *pvParameters )
\r
70 uip_ipaddr_t xIPAddr;
\r
71 struct timer periodic_timer, arp_timer;
\r
73 /* Initialise the uIP stack. */
\r
74 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
75 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
77 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
78 uip_sethostaddr( xIPAddr );
\r
81 /* Initialise the MAC. */
\r
84 vTaskDelay( uipINIT_WAIT );
\r
85 xEMACSemaphore = xEMACInit();
\r
86 } while( xEMACSemaphore == NULL );
\r
90 /* Is there received data ready to be processed? */
\r
91 uip_len = ulEMACPoll();
\r
95 /* Standard uIP loop taken from the uIP manual. */
\r
96 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
101 /* If the above function invocation resulted in data that
\r
102 should be sent out on the network, the global variable
\r
103 uip_len is set to a value > 0. */
\r
110 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
114 /* If the above function invocation resulted in data that
\r
115 should be sent out on the network, the global variable
\r
116 uip_len is set to a value > 0. */
\r
125 if( timer_expired( &periodic_timer ) )
\r
127 timer_reset( &periodic_timer );
\r
128 for( i = 0; i < UIP_CONNS; i++ )
\r
132 /* If the above function invocation resulted in data that
\r
133 should be sent out on the network, the global variable
\r
134 uip_len is set to a value > 0. */
\r
142 /* Call the ARP timer function every 10 seconds. */
\r
143 if( timer_expired( &arp_timer ) )
\r
145 timer_reset( &arp_timer );
\r
151 /* We did not receive a packet, and there was no periodic
\r
152 processing to perform. Block for a fixed period. If a packet
\r
153 is received during this period we will be woken by the ISR
\r
154 giving us the Semaphore. */
\r
155 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
160 /*-----------------------------------------------------------------------------------*/
\r
162 void clock_init(void)
\r
164 /* This is done when the scheduler starts. */
\r
166 /*-----------------------------------------------------------*/
\r
168 clock_time_t clock_time( void )
\r
170 return xTaskGetTickCount();
\r
172 /*-----------------------------------------------------------*/
\r
174 void vProcessInput( char *pcInput )
\r
178 /* Turn the LED on or off depending on the checkbox status. */
\r
180 c = strstr( pcInput, "?" );
\r
183 if( strstr( c, "LED0=1" ) != NULL )
\r
185 vParTestSetLED( 3, 0 );
\r
189 vParTestSetLED( 3, 1 );
\r