]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF51CN128_CodeWarrior/Sources/httpd/uIP_Task.c
Prepare for V5.3.1 release.
[freertos] / Demo / ColdFire_MCF51CN128_CodeWarrior / Sources / httpd / uIP_Task.c
1 /*\r
2         FreeRTOS.org V5.3.1 - 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         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\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 /* 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 #include "timer.h"\r
67 \r
68 /* Demo includes. */\r
69 #include "FEC.h"\r
70 #include "partest.h"\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 clock_time_t clock_time( void );\r
83 \r
84 /*-----------------------------------------------------------*/\r
85 \r
86 /* The semaphore used by the ISR to wake the uIP task. */\r
87 extern xSemaphoreHandle xFECSemaphore;\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 clock_time_t clock_time( void )\r
92 {\r
93         return xTaskGetTickCount();\r
94 }\r
95 \r
96 \r
97 void vuIP_Task( void *pvParameters )\r
98 {\r
99 portBASE_TYPE i;\r
100 uip_ipaddr_t xIPAddr;\r
101 struct timer periodic_timer, arp_timer;\r
102 extern void ( vEMAC_ISR )( void );\r
103 \r
104         /* Just to get rid of the compiler warning. */\r
105         ( void ) pvParameters;\r
106 \r
107         /* Enable/Reset the Ethernet Controller */\r
108 \r
109         /* Create the semaphore used by the ISR to wake this task. */\r
110         vSemaphoreCreateBinary( xFECSemaphore );\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         uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
119         uip_setnetmask( xIPAddr );              \r
120         httpd_init();\r
121 \r
122         vInitFEC();\r
123 \r
124         for( ;; )\r
125         {\r
126                 /* Is there received data ready to be processed? */\r
127                 uip_len = ( unsigned short ) ulFECRx();\r
128                 \r
129                 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
130                 {\r
131                         /* Standard uIP loop taken from the uIP manual. */\r
132 \r
133                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
134                         {\r
135                                 uip_arp_ipin();\r
136                                 uip_input();\r
137 \r
138                                 /* If the above function invocation resulted in data that\r
139                                 should be sent out on the network, the global variable\r
140                                 uip_len is set to a value > 0. */\r
141                                 if( uip_len > 0 )\r
142                                 {\r
143                                         uip_arp_out();\r
144                                         vFECTx();\r
145                                 }\r
146                         }\r
147                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
148                         {\r
149                                 uip_arp_arpin();\r
150 \r
151                                 /* If the above function invocation resulted in data that\r
152                                 should be sent out on the network, the global variable\r
153                                 uip_len is set to a value > 0. */\r
154                                 if( uip_len > 0 )\r
155                                 {\r
156                                         vFECTx();\r
157                                 }\r
158                         }                       \r
159                 }\r
160                 else\r
161                 {\r
162                         if( ( timer_expired( &periodic_timer ) ) && ( uip_buf != NULL ) )\r
163                         {\r
164                                 timer_reset( &periodic_timer );\r
165                                 for( i = 0; i < UIP_CONNS; i++ )\r
166                                 {\r
167                                         uip_periodic( i );\r
168         \r
169                                         /* If the above function invocation resulted in data that\r
170                                         should be sent out on the network, the global variable\r
171                                         uip_len is set to a value > 0. */\r
172                                         if( uip_len > 0 )\r
173                                         {\r
174                                                 uip_arp_out();\r
175                                                 vFECTx();\r
176                                         }\r
177                                 }       \r
178         \r
179                                 /* Call the ARP timer function every 10 seconds. */\r
180                                 if( timer_expired( &arp_timer ) )\r
181                                 {\r
182                                         timer_reset( &arp_timer );\r
183                                         uip_arp_timer();\r
184                                 }\r
185                         }\r
186                         else\r
187                         {                       \r
188                                 /* We did not receive a packet, and there was no periodic\r
189                                 processing to perform.  Block for a fixed period.  If a packet\r
190                                 is received during this period we will be woken by the ISR\r
191                                 giving us the Semaphore. */\r
192                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );                        \r
193                         }\r
194                 }\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r
199 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )\r
200 {\r
201 char *c;\r
202 \r
203         /* Just to get rid of the compiler warning - other ports/demos use the parameter. */\r
204         ( void ) xInputLength;\r
205 \r
206         /* Process the form input sent by the IO page of the served HTML. */\r
207 \r
208         c = strstr( pcInputString, "?" );\r
209 \r
210     if( c )\r
211     {\r
212                 /* Turn LED's on or off in accordance with the check box status. */\r
213                 if( strstr( c, "LED3=1" ) != NULL )\r
214                 {\r
215                         /* Turn LED 3 on. */\r
216                         vParTestSetLED( 3, 1 );\r
217                 }\r
218                 else\r
219                 {\r
220                         /* Turn LED 3 off. */\r
221                         vParTestSetLED( 3, 0 );\r
222                 }               \r
223     }\r
224 }\r
225 \r