]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/uIP_Demo_Rowley_ARM7/uip/uIP_Task.c
Prepare for V9.0.0 release.
[freertos] / FreeRTOS / Demo / uIP_Demo_Rowley_ARM7 / uip / uIP_Task.c
1 /*\r
2  * Copyright (c) 2001-2003, Adam Dunkels.\r
3  * All rights reserved. \r
4  *\r
5  * Redistribution and use in source and binary forms, with or without \r
6  * modification, are permitted provided that the following conditions \r
7  * are met: \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
16  *\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
28  *\r
29  * This file is part of the uIP TCP/IP stack.\r
30  *\r
31  * $Id: main.c,v 1.10.2.4 2003/10/21 21:27:51 adam Exp $\r
32  *\r
33  */\r
34 \r
35 \r
36 #include <stdlib.h>   /* For system(). */\r
37 #include <stdio.h>    /* For printf(). */\r
38 \r
39 #include "FreeRTOS.h"\r
40 #include "task.h"\r
41 \r
42 #undef HTONS\r
43 \r
44 #include "cs8900a.h"\r
45 #include "uip.h"\r
46 #include "uip_arp.h"\r
47 #include "tapdev.h"\r
48 #include "httpd.h"\r
49 \r
50 static const struct uip_eth_addr ethaddr = {{0x00,0x00,0xe2,0x58,0xb6,0x6b}};\r
51 \r
52 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])\r
53 #define uipSHORT_DELAY          ( ( TickType_t ) 2 / portTICK_PERIOD_MS )\r
54 \r
55 #ifndef NULL\r
56 #define NULL (void *)0\r
57 #endif /* NULL */\r
58 \r
59 static volatile TickType_t start, current;\r
60 \r
61 #define RT_CLOCK_SECOND ( configTICK_RATE_HZ / 2 )\r
62 \r
63 /*-----------------------------------------------------------------------------------*/\r
64 /**\r
65  * \internal\r
66  * A real-time clock.\r
67  *\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
73  *\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
77  * \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
80  */\r
81 #define rt_ticks xTaskGetTickCount\r
82 \r
83 /*-----------------------------------------------------------------------------------*/\r
84 void vuIP_TASK( void *pvParameters )\r
85 {\r
86 u8_t i, arptimer;\r
87 u16_t addr[2];\r
88 int z = 3;\r
89 \r
90         /* Initialize the uIP TCP/IP stack. */\r
91         uip_init();\r
92         uip_arp_init();\r
93 \r
94         /* Initialize the device driver. */ \r
95         cs8900a_init();\r
96 \r
97         /* Initialize the HTTP server. */\r
98         httpd_init();\r
99 \r
100         start = rt_ticks();\r
101         arptimer = 0;\r
102   \r
103         while(1) \r
104         {\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
107                 uip_buf buffer. */\r
108                 uip_len = cs8900a_poll();\r
109 \r
110                 if(uip_len > 0) \r
111                 {\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
117                         {\r
118                                 uip_arp_ipin();\r
119                                 uip_input();\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
123                                 if(uip_len > 0) \r
124                                 {\r
125                                         uip_arp_out();\r
126                                         cs8900a_send();\r
127                                 }\r
128                         } \r
129                         else if(BUF->type == htons(UIP_ETHTYPE_ARP)) \r
130                         {\r
131                                 uip_arp_arpin();\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
135                                 if(uip_len > 0) \r
136                                 {       \r
137                                         cs8900a_send();\r
138                                 }\r
139                         }\r
140                 } \r
141                 else \r
142                 {\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
147 \r
148                         if((u16_t)(current - start) >= (u16_t)RT_CLOCK_SECOND / 2) \r
149                         {\r
150                                 start = current;\r
151 \r
152                                 for(i = 0; i < UIP_CONNS; i++) \r
153                                 {\r
154                                         uip_periodic(i);\r
155 \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
159                                         \r
160                                         if(uip_len > 0) \r
161                                         {\r
162                                                 uip_arp_out();\r
163                                                 cs8900a_send();\r
164                                         }\r
165                                 }\r
166 \r
167                                 #if UIP_UDP\r
168                                         for(i = 0; i < UIP_UDP_CONNS; i++) \r
169                                         {\r
170                                                 uip_udp_periodic(i);\r
171 \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
175 \r
176                                                 if(uip_len > 0) \r
177                                                 {\r
178                                                         uip_arp_out();\r
179                                                         tapdev_send();\r
180                                                 }\r
181                                         }\r
182                                 #endif /* UIP_UDP */\r
183 \r
184                                 /* Call the ARP timer function every 10 seconds. */\r
185                                 if(++arptimer == 20) \r
186                                 {       \r
187                                         uip_arp_timer();\r
188                                         arptimer = 0;\r
189                                 }\r
190                         }\r
191                         else\r
192                         {\r
193                                 vTaskDelay( uipSHORT_DELAY );\r
194                 }   }\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------------------------------*/\r
198 \r
199 \r
200 \r
201 \r