]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
8d24ca78c9b4cdaabd0c41161c9c59c1ac5bbff4
[freertos] / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / webserver / uIP_Task.c
1 /*\r
2         FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it \r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9 \r
10         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
11         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for \r
13         more details.\r
14 \r
15         You should have received a copy of the GNU General Public License along \r
16         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
17         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
18 \r
19         A special exception to the GPL is included to allow you to distribute a \r
20         combined work that includes FreeRTOS.org without being obliged to provide\r
21         the source code for any proprietary components.  See the licensing section\r
22         of http://www.FreeRTOS.org for full details.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 \r
53 /* Task that controls the uIP TCP/IP stack. */\r
54 \r
55 \r
56 /* Standard includes. */\r
57 #include <string.h>\r
58 \r
59 /* Scheduler includes. */\r
60 #include "FreeRTOS.h"\r
61 #include "task.h"\r
62 #include "semphr.h"\r
63 \r
64 /* uip includes. */\r
65 #include "uip.h"\r
66 #include "uip_arp.h"\r
67 #include "httpd.h"\r
68 #include "timer.h"\r
69 #include "clock-arch.h"\r
70 \r
71 /* Demo includes. */\r
72 #include "FEC.h"\r
73 #include "partest.h"\r
74 \r
75 \r
76 /*-----------------------------------------------------------*/\r
77 \r
78 /* Shortcut to the header within the Rx buffer. */\r
79 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 /*\r
84  * Port functions required by the uIP stack.\r
85  */\r
86 void clock_init( void );\r
87 clock_time_t clock_time( void );\r
88 extern void timer_set(struct timer *t, clock_time_t interval);\r
89 extern int timer_expired(struct timer *t);\r
90 extern void timer_reset(struct timer *t);\r
91 \r
92 /*-----------------------------------------------------------*/\r
93 \r
94 /* The semaphore used by the ISR to wake the uIP task. */\r
95 extern xSemaphoreHandle xFECSemaphore;\r
96 \r
97 /*-----------------------------------------------------------*/\r
98 \r
99 void clock_init(void)\r
100 {\r
101         /* This is done when the scheduler starts. */\r
102 }\r
103 /*-----------------------------------------------------------*/\r
104 \r
105 /* Define clock functions here to avoid header file name clash between uIP\r
106 and the Luminary Micro driver library. */\r
107 clock_time_t clock_time( void )\r
108 {\r
109         return xTaskGetTickCount();\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vuIP_Task( void *pvParameters )\r
114 {\r
115 portBASE_TYPE i;\r
116 uip_ipaddr_t xIPAddr;\r
117 struct timer periodic_timer, arp_timer;\r
118 \r
119         /* To prevent compiler warnings. */\r
120         ( void ) pvParameters;\r
121 \r
122         /* Initialise the uIP stack. */\r
123         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
124         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
125         uip_init();\r
126         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
127         uip_sethostaddr( xIPAddr );\r
128 \r
129         /* Initialise the WEB server. */\r
130         httpd_init();\r
131 \r
132         /* Initialise the Ethernet controller peripheral. */\r
133         vFECInit();\r
134 \r
135         for( ;; )\r
136         {\r
137                 /* Is there received data ready to be processed? */\r
138                 uip_len = usFECGetRxedData();\r
139 \r
140                 if( uip_len > 0 )\r
141                 {\r
142                         /* Standard uIP loop taken from the uIP manual. */\r
143 \r
144                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
145                         {\r
146                                 uip_arp_ipin();\r
147                                 uip_input();\r
148 \r
149                                 /* If the above function invocation resulted in data that\r
150                                 should be sent out on the network, the global variable\r
151                                 uip_len is set to a value > 0. */\r
152                                 if( uip_len > 0 )\r
153                                 {\r
154                                         uip_arp_out();\r
155                                         vFECSendData();\r
156                                 }\r
157                                 else\r
158                                 {\r
159                                         /* If we are not sending data then let the FEC driver know\r
160                                         the buffer is no longer required. */\r
161                                         vFECRxProcessingCompleted();\r
162                                 }\r
163                         }\r
164                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
165                         {\r
166                                 uip_arp_arpin();\r
167 \r
168                                 /* If the above function invocation resulted in data that\r
169                                 should be sent out on the network, the global variable\r
170                                 uip_len is set to a value > 0. */\r
171                                 if( uip_len > 0 )\r
172                                 {\r
173                                         vFECSendData();\r
174                                 }\r
175                                 else\r
176                                 {\r
177                                         /* If we are not sending data then let the FEC driver know\r
178                                         the buffer is no longer required. */\r
179                                         vFECRxProcessingCompleted();\r
180                                 }\r
181                         }\r
182                         else\r
183                         {\r
184                                 /* If we are not sending data then let the FEC driver know\r
185                                 the buffer is no longer required. */\r
186                                 vFECRxProcessingCompleted();\r
187                         }\r
188                 }\r
189                 else\r
190                 {\r
191                         if( timer_expired( &periodic_timer ) )\r
192                         {\r
193                                 timer_reset( &periodic_timer );\r
194                                 for( i = 0; i < UIP_CONNS; i++ )\r
195                                 {\r
196                                         uip_periodic( i );\r
197 \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
201                                         if( uip_len > 0 )\r
202                                         {\r
203                                                 uip_arp_out();\r
204                                                 vFECSendData();\r
205                                         }\r
206                                 }\r
207 \r
208                                 /* Call the ARP timer function every 10 seconds. */\r
209                                 if( timer_expired( &arp_timer ) )\r
210                                 {\r
211                                         timer_reset( &arp_timer );\r
212                                         uip_arp_timer();\r
213                                 }\r
214                         }\r
215                         else\r
216                         {\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( xFECSemaphore, configTICK_RATE_HZ / 2 );\r
222                         }\r
223                 }\r
224         }\r
225 }\r
226 /*-----------------------------------------------------------*/\r
227 \r
228 \r
229 \r