2 * 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
36 #include <stdlib.h> /* For system(). */
\r
37 #include <stdio.h> /* For printf(). */
\r
39 #include "FreeRTOS.h"
\r
44 #include "cs8900a.h"
\r
46 #include "uip_arp.h"
\r
50 static const struct uip_eth_addr ethaddr = {{0x00,0x00,0xe2,0x58,0xb6,0x6b}};
\r
52 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
\r
53 #define uipSHORT_DELAY ( ( TickType_t ) 2 / portTICK_PERIOD_MS )
\r
56 #define NULL (void *)0
\r
59 static volatile TickType_t start, current;
\r
61 #define RT_CLOCK_SECOND ( configTICK_RATE_HZ / 2 )
\r
63 /*-----------------------------------------------------------------------------------*/
\r
66 * A real-time clock.
\r
68 * This example main() function uses polling of a real-time clock in
\r
69 * order to know when the periodic processing should be
\r
70 * performed. This is implemented using this function - rt_ticks(). In
\r
71 * this example unix implementation, it simply calls the unix function
\r
72 * gettimeofday() which returns the current wall clock time.
\r
74 * For a micro-controller, a simple way to implement this function is
\r
75 * by having a counter that is incremented by a timer interrupt and
\r
76 * read by this function.
\r
78 * The macro RT_CLOCK_SECOND should be defined as the approximate
\r
79 * number of ticks that are elapsed during one second.
\r
81 #define rt_ticks xTaskGetTickCount
\r
83 /*-----------------------------------------------------------------------------------*/
\r
84 void vuIP_TASK( void *pvParameters )
\r
90 /* Initialize the uIP TCP/IP stack. */
\r
94 /* Initialize the device driver. */
\r
97 /* Initialize the HTTP server. */
\r
100 start = rt_ticks();
\r
105 /* Let the network device driver read an entire IP packet
\r
106 into the uip_buf. If it returns > 0, there is a packet in the
\r
108 uip_len = cs8900a_poll();
\r
112 /* A packet is present in the packet buffer. We call the
\r
113 appropriate ARP functions depending on what kind of packet we
\r
114 have received. If the packet is an IP packet, we should call
\r
115 uip_input() as well. */
\r
116 if(BUF->type == htons(UIP_ETHTYPE_IP))
\r
120 /* If the above function invocation resulted in data that
\r
121 should be sent out on the network, the global variable
\r
122 uip_len is set to a value > 0. */
\r
129 else if(BUF->type == htons(UIP_ETHTYPE_ARP))
\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
143 /* The poll function returned 0, so no packet was
\r
144 received. Instead we check if there is time that we do the
\r
145 periodic processing. */
\r
146 current = rt_ticks();
\r
148 if((u16_t)(current - start) >= (u16_t)RT_CLOCK_SECOND / 2)
\r
152 for(i = 0; i < UIP_CONNS; i++)
\r
156 /* If the above function invocation resulted in data that
\r
157 should be sent out on the network, the global variable
\r
158 uip_len is set to a value > 0. */
\r
168 for(i = 0; i < UIP_UDP_CONNS; i++)
\r
170 uip_udp_periodic(i);
\r
172 /* If the above function invocation resulted in data that
\r
173 should be sent out on the network, the global variable
\r
174 uip_len is set to a value > 0. */
\r
182 #endif /* UIP_UDP */
\r
184 /* Call the ARP timer function every 10 seconds. */
\r
185 if(++arptimer == 20)
\r
193 vTaskDelay( uipSHORT_DELAY );
\r
197 /*-----------------------------------------------------------------------------------*/
\r