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