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