]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF51CN128_CodeWarrior/Sources/httpd/uIP_Task.c
6524f1cd9abd60c948827df8dabd7b7fbe12ac4c
[freertos] / Demo / ColdFire_MCF51CN128_CodeWarrior / Sources / httpd / uIP_Task.c
1 /*\r
2     FreeRTOS V6.0.0 - 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     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /* Standard includes. */\r
50 #include <string.h>\r
51 \r
52 /* Scheduler includes. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 #include "semphr.h"\r
56 \r
57 /* uip includes. */\r
58 #include "uip.h"\r
59 #include "uip_arp.h"\r
60 #include "httpd.h"\r
61 #include "timer.h"\r
62 #include "clock-arch.h"\r
63 #include "timer.h"\r
64 \r
65 /* Demo includes. */\r
66 #include "FEC.h"\r
67 #include "partest.h"\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 /* Shortcut to the header within the Rx buffer. */\r
72 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
73 \r
74 /*-----------------------------------------------------------*/\r
75 \r
76 /*\r
77  * Port functions required by the uIP stack.\r
78  */\r
79 clock_time_t clock_time( void );\r
80 \r
81 /*-----------------------------------------------------------*/\r
82 \r
83 /* The semaphore used by the ISR to wake the uIP task. */\r
84 extern xSemaphoreHandle xFECSemaphore;\r
85 \r
86 /*-----------------------------------------------------------*/\r
87 \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 extern void ( vEMAC_ISR )( void );\r
100 \r
101         /* Just to get rid of the compiler warning. */\r
102         ( void ) pvParameters;\r
103 \r
104         /* Enable/Reset the Ethernet Controller */\r
105 \r
106         /* Create the semaphore used by the ISR to wake this task. */\r
107         vSemaphoreCreateBinary( xFECSemaphore );\r
108         \r
109         /* Initialise the uIP stack. */\r
110         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
111         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
112         uip_init();\r
113         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
114         uip_sethostaddr( xIPAddr );\r
115         uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
116         uip_setnetmask( xIPAddr );              \r
117         httpd_init();\r
118 \r
119         vInitFEC();\r
120 \r
121         for( ;; )\r
122         {\r
123                 /* Is there received data ready to be processed? */\r
124                 uip_len = ( unsigned short ) ulFECRx();\r
125                 \r
126                 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
127                 {\r
128                         /* Standard uIP loop taken from the uIP manual. */\r
129 \r
130                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
131                         {\r
132                                 uip_arp_ipin();\r
133                                 uip_input();\r
134 \r
135                                 /* If the above function invocation resulted in data that\r
136                                 should be sent out on the network, the global variable\r
137                                 uip_len is set to a value > 0. */\r
138                                 if( uip_len > 0 )\r
139                                 {\r
140                                         uip_arp_out();\r
141                                         vFECTx();\r
142                                 }\r
143                         }\r
144                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
145                         {\r
146                                 uip_arp_arpin();\r
147 \r
148                                 /* If the above function invocation resulted in data that\r
149                                 should be sent out on the network, the global variable\r
150                                 uip_len is set to a value > 0. */\r
151                                 if( uip_len > 0 )\r
152                                 {\r
153                                         vFECTx();\r
154                                 }\r
155                         }                       \r
156                 }\r
157                 else\r
158                 {\r
159                         if( ( timer_expired( &periodic_timer ) ) && ( uip_buf != NULL ) )\r
160                         {\r
161                                 timer_reset( &periodic_timer );\r
162                                 for( i = 0; i < UIP_CONNS; i++ )\r
163                                 {\r
164                                         uip_periodic( i );\r
165         \r
166                                         /* If the above function invocation resulted in data that\r
167                                         should be sent out on the network, the global variable\r
168                                         uip_len is set to a value > 0. */\r
169                                         if( uip_len > 0 )\r
170                                         {\r
171                                                 uip_arp_out();\r
172                                                 vFECTx();\r
173                                         }\r
174                                 }       \r
175         \r
176                                 /* Call the ARP timer function every 10 seconds. */\r
177                                 if( timer_expired( &arp_timer ) )\r
178                                 {\r
179                                         timer_reset( &arp_timer );\r
180                                         uip_arp_timer();\r
181                                 }\r
182                         }\r
183                         else\r
184                         {                       \r
185                                 /* We did not receive a packet, and there was no periodic\r
186                                 processing to perform.  Block for a fixed period.  If a packet\r
187                                 is received during this period we will be woken by the ISR\r
188                                 giving us the Semaphore. */\r
189                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );                        \r
190                         }\r
191                 }\r
192         }\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 void vApplicationProcessFormInput( char *pcInputString, portBASE_TYPE xInputLength )\r
197 {\r
198 char *c;\r
199 \r
200         /* Just to get rid of the compiler warning - other ports/demos use the parameter. */\r
201         ( void ) xInputLength;\r
202 \r
203         /* Process the form input sent by the IO page of the served HTML. */\r
204 \r
205         c = strstr( pcInputString, "?" );\r
206 \r
207     if( c )\r
208     {\r
209                 /* Turn LED's on or off in accordance with the check box status. */\r
210                 if( strstr( c, "LED3=1" ) != NULL )\r
211                 {\r
212                         /* Turn LED 3 on. */\r
213                         vParTestSetLED( 3, 1 );\r
214                 }\r
215                 else\r
216                 {\r
217                         /* Turn LED 3 off. */\r
218                         vParTestSetLED( 3, 0 );\r
219                 }               \r
220     }\r
221 }\r
222 \r