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
39 /* Scheduler includes. */
\r
40 #include "FreeRTOS.h"
\r
44 /* Demo app includes. */
\r
45 #include "SAM7_EMAC.h"
\r
50 #include "uip_arp.h"
\r
54 /* The start of the uIP buffer, which will contain the frame headers. */
\r
55 #define pucUIP_Buffer ( ( struct uip_eth_hdr * ) &uip_buf[ 0 ] )
\r
57 /* uIP update frequencies. */
\r
58 #define RT_CLOCK_SECOND ( configTICK_RATE_HZ )
\r
59 #define uipARP_FREQUENCY ( 20 )
\r
60 #define uipMAX_BLOCK_TIME ( RT_CLOCK_SECOND / 4 )
\r
62 /*-----------------------------------------------------------*/
\r
64 void vuIP_TASK( void *pvParameters )
\r
66 /* The semaphore used by the EMAC ISR to indicate that an Rx frame is ready
\r
68 xSemaphoreHandle xSemaphore = NULL;
\r
69 portBASE_TYPE xARPTimer;
\r
70 unsigned portBASE_TYPE uxPriority;
\r
71 static volatile portTickType xStartTime, xCurrentTime;
\r
73 /* Initialize the uIP TCP/IP stack. */
\r
77 /* Initialize the HTTP server. */
\r
80 /* Initialise the local timers. */
\r
81 xStartTime = xTaskGetTickCount();
\r
84 /* Initialise the EMAC. A semaphore will be returned when this is
\r
85 successful. This routine contains code that polls status bits. If the
\r
86 Ethernet cable is not plugged in then this can take a considerable time.
\r
87 To prevent this starving lower priority tasks of processing time we
\r
88 lower our priority prior to the call, then raise it back again once the
\r
89 initialisation is complete. */
\r
90 uxPriority = uxTaskPriorityGet( NULL );
\r
91 vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
\r
92 while( xSemaphore == NULL )
\r
94 xSemaphore = xEMACInit();
\r
96 vTaskPrioritySet( NULL, uxPriority );
\r
100 /* Let the network device driver read an entire IP packet
\r
101 into the uip_buf. If it returns > 0, there is a packet in the
\r
103 uip_len = ulEMACPoll();
\r
105 /* Was a packet placed in the uIP buffer? */
\r
108 /* A packet is present in the uIP buffer. We call the
\r
109 appropriate ARP functions depending on what kind of packet we
\r
110 have received. If the packet is an IP packet, we should call
\r
111 uip_input() as well. */
\r
112 if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_IP ) )
\r
117 /* If the above function invocation resulted in data that
\r
118 should be sent out on the network, the global variable
\r
119 uip_len is set to a value > 0. */
\r
126 else if( pucUIP_Buffer->type == htons( UIP_ETHTYPE_ARP ) )
\r
130 /* If the above function invocation resulted in data that
\r
131 should be sent out on the network, the global variable
\r
132 uip_len is set to a value > 0. */
\r
141 /* The poll function returned 0, so no packet was
\r
142 received. Instead we check if it is time that we do the
\r
143 periodic processing. */
\r
144 xCurrentTime = xTaskGetTickCount();
\r
146 if( ( xCurrentTime - xStartTime ) >= RT_CLOCK_SECOND )
\r
150 /* Reset the timer. */
\r
151 xStartTime = xCurrentTime;
\r
153 /* Periodic check of all connections. */
\r
154 for( i = 0; i < UIP_CONNS; i++ )
\r
158 /* If the above function invocation resulted in data that
\r
159 should be sent out on the network, the global variable
\r
160 uip_len is set to a value > 0. */
\r
169 for( i = 0; i < UIP_UDP_CONNS; i++ )
\r
171 uip_udp_periodic( i );
\r
173 /* If the above function invocation resulted in data that
\r
174 should be sent out on the network, the global variable
\r
175 uip_len is set to a value > 0. */
\r
182 #endif /* UIP_UDP */
\r
184 /* Periodically call the ARP timer function. */
\r
185 if( ++xARPTimer == uipARP_FREQUENCY )
\r
193 /* We did not receive a packet, and there was no periodic
\r
194 processing to perform. Block for a fixed period. If a packet
\r
195 is received during this period we will be woken by the ISR
\r
196 giving us the Semaphore. */
\r
197 xSemaphoreTake( xSemaphore, uipMAX_BLOCK_TIME );
\r
202 /*-----------------------------------------------------------------------------------*/
\r