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