]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
f21a2ee121aeddbffe50a90fede641fe1261fe36
[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 /* Standard includes. */\r
33 #include <string.h>\r
34 \r
35 /* Scheduler includes. */\r
36 #include "FreeRTOS.h"\r
37 #include "task.h"\r
38 #include "semphr.h"\r
39 \r
40 /* uip includes. */\r
41 #include "uip.h"\r
42 #include "uip_arp.h"\r
43 #include "httpd.h"\r
44 #include "timer.h"\r
45 #include "clock-arch.h"\r
46 \r
47 /* Demo includes. */\r
48 #include "FEC.h"\r
49 #include "partest.h"\r
50 \r
51 //struct timer {\r
52 //  clock_time_t start;\r
53 //  clock_time_t interval;\r
54 //};\r
55 \r
56 \r
57 /*-----------------------------------------------------------*/\r
58 \r
59 /* How long to wait before attempting to connect the MAC again. */\r
60 #define uipINIT_WAIT    100\r
61 \r
62 /* Shortcut to the header within the Rx buffer. */\r
63 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
64 \r
65 /* Standard constant. */\r
66 #define uipTOTAL_FRAME_HEADER_SIZE      54\r
67 \r
68 /*-----------------------------------------------------------*/\r
69 \r
70 /*\r
71  * Port functions required by the uIP stack.\r
72  */\r
73 void clock_init( void );\r
74 clock_time_t clock_time( void );\r
75 \r
76 /*-----------------------------------------------------------*/\r
77 \r
78 /* The semaphore used by the ISR to wake the uIP task. */\r
79 extern xSemaphoreHandle xFECSemaphore;\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 void clock_init(void)\r
84 {\r
85         /* This is done when the scheduler starts. */\r
86 }\r
87 /*-----------------------------------------------------------*/\r
88 \r
89 /* Define clock functions here to avoid header file name clash between uIP\r
90 and the Luminary Micro driver library. */\r
91 clock_time_t clock_time( void )\r
92 {\r
93         return xTaskGetTickCount();\r
94 }\r
95 extern void timer_set(struct timer *t, clock_time_t interval);\r
96 extern int timer_expired(struct timer *t);\r
97 extern void timer_reset(struct timer *t);\r
98 \r
99 \r
100 \r
101 \r
102 void vuIP_Task( void *pvParameters )\r
103 {\r
104 portBASE_TYPE i;\r
105 uip_ipaddr_t xIPAddr;\r
106 struct timer periodic_timer, arp_timer;\r
107 extern void ( vEMAC_ISR )( void );\r
108 \r
109         /* To prevent compiler warnings. */\r
110         ( void ) pvParameters;\r
111 \r
112         /* Initialise the uIP stack. */\r
113         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
114         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
115         uip_init();\r
116         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
117         uip_sethostaddr( xIPAddr );\r
118         httpd_init();\r
119 \r
120         vInitFEC();\r
121 \r
122         for( ;; )\r
123         {\r
124                 /* Is there received data ready to be processed? */\r
125                 uip_len = usGetFECRxData();\r
126 \r
127                 if( uip_len > 0 )\r
128                 {\r
129                         /* Standard uIP loop taken from the uIP manual. */\r
130 \r
131                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
132                         {\r
133                                 uip_arp_ipin();\r
134                                 uip_input();\r
135 \r
136                                 /* If the above function invocation resulted in data that\r
137                                 should be sent out on the network, the global variable\r
138                                 uip_len is set to a value > 0. */\r
139                                 if( uip_len > 0 )\r
140                                 {\r
141                                         uip_arp_out();\r
142                                         vSendBufferToFEC();\r
143                                 }\r
144                                 else\r
145                                 {\r
146                                         vDiscardRxData();\r
147                                 }\r
148                         }\r
149                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
150                         {\r
151                                 uip_arp_arpin();\r
152 \r
153                                 /* If the above function invocation resulted in data that\r
154                                 should be sent out on the network, the global variable\r
155                                 uip_len is set to a value > 0. */\r
156                                 if( uip_len > 0 )\r
157                                 {\r
158                                         vSendBufferToFEC();\r
159                                 }\r
160                                 else\r
161                                 {\r
162                                         vDiscardRxData();\r
163                                 }\r
164                         }\r
165                         else\r
166                         {\r
167                                 vDiscardRxData();\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                                                 vSendBufferToFEC();\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 void vApplicationProcessFormInput( portCHAR *pcInputString )\r
210 {\r
211 char *c = pcInputString;\r
212 \r
213         /* Process the form input sent by the IO page of the served HTML. */\r
214         while( ( *c != '?' ) && ( *c != 0x00 ) )\r
215         {\r
216                 c++;\r
217         }\r
218 \r
219     if( *c == '?' )\r
220     {\r
221         c++;\r
222                 if( strcmp( c, "LED0=1" ) == 0 )\r
223                 {\r
224                         vParTestSetLED( 3, 1 );\r
225                 }\r
226                 else\r
227                 {\r
228                         vParTestSetLED( 3, 0 );\r
229                 }\r
230     }\r
231 }\r
232 \r
233 \r
234 \r