]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / webserver / 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 \r
50 /* Task that controls the uIP TCP/IP stack. */\r
51 \r
52 \r
53 /* Standard includes. */\r
54 #include <string.h>\r
55 \r
56 /* Scheduler includes. */\r
57 #include "FreeRTOS.h"\r
58 #include "task.h"\r
59 #include "semphr.h"\r
60 \r
61 /* uip includes. */\r
62 #include "uip.h"\r
63 #include "uip_arp.h"\r
64 #include "httpd.h"\r
65 #include "timer.h"\r
66 #include "clock-arch.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 \r
75 /* Shortcut to the header within the Rx buffer. */\r
76 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
77 \r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /*\r
81  * Port functions required by the uIP stack.\r
82  */\r
83 void clock_init( void );\r
84 clock_time_t clock_time( void );\r
85 extern void timer_set(struct timer *t, clock_time_t interval);\r
86 extern int timer_expired(struct timer *t);\r
87 extern void timer_reset(struct timer *t);\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /* The semaphore used by the ISR to wake the uIP task. */\r
92 extern xSemaphoreHandle xFECSemaphore;\r
93 \r
94 /*-----------------------------------------------------------*/\r
95 \r
96 void clock_init(void)\r
97 {\r
98         /* This is done when the scheduler starts. */\r
99 }\r
100 /*-----------------------------------------------------------*/\r
101 \r
102 /* Define clock functions here to avoid header file name clash between uIP\r
103 and the Luminary Micro driver library. */\r
104 clock_time_t clock_time( void )\r
105 {\r
106         return xTaskGetTickCount();\r
107 }\r
108 /*-----------------------------------------------------------*/\r
109 \r
110 void vuIP_Task( void *pvParameters )\r
111 {\r
112 portBASE_TYPE i;\r
113 uip_ipaddr_t xIPAddr;\r
114 struct timer periodic_timer, arp_timer;\r
115 \r
116         /* To prevent compiler warnings. */\r
117         ( void ) pvParameters;\r
118 \r
119         /* Initialise the uIP stack. */\r
120         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
121         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
122         uip_init();\r
123         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
124         uip_sethostaddr( xIPAddr );\r
125 \r
126         /* Initialise the WEB server. */\r
127         httpd_init();\r
128 \r
129         /* Initialise the Ethernet controller peripheral. */\r
130         vFECInit();\r
131 \r
132         for( ;; )\r
133         {\r
134                 /* Is there received data ready to be processed? */\r
135                 uip_len = usFECGetRxedData();\r
136 \r
137                 if( uip_len > 0 )\r
138                 {\r
139                         /* Standard uIP loop taken from the uIP manual. */\r
140 \r
141                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
142                         {\r
143                                 uip_arp_ipin();\r
144                                 uip_input();\r
145 \r
146                                 /* If the above function invocation resulted in data that\r
147                                 should be sent out on the network, the global variable\r
148                                 uip_len is set to a value > 0. */\r
149                                 if( uip_len > 0 )\r
150                                 {\r
151                                         uip_arp_out();\r
152                                         vFECSendData();\r
153                                 }\r
154                                 else\r
155                                 {\r
156                                         /* If we are not sending data then let the FEC driver know\r
157                                         the buffer is no longer required. */\r
158                                         vFECRxProcessingCompleted();\r
159                                 }\r
160                         }\r
161                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
162                         {\r
163                                 uip_arp_arpin();\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                                         vFECSendData();\r
171                                 }\r
172                                 else\r
173                                 {\r
174                                         /* If we are not sending data then let the FEC driver know\r
175                                         the buffer is no longer required. */\r
176                                         vFECRxProcessingCompleted();\r
177                                 }\r
178                         }\r
179                         else\r
180                         {\r
181                                 /* If we are not sending data then let the FEC driver know\r
182                                 the buffer is no longer required. */\r
183                                 vFECRxProcessingCompleted();\r
184                         }\r
185                 }\r
186                 else\r
187                 {\r
188                         if( timer_expired( &periodic_timer ) )\r
189                         {\r
190                                 timer_reset( &periodic_timer );\r
191                                 for( i = 0; i < UIP_CONNS; i++ )\r
192                                 {\r
193                                         uip_periodic( i );\r
194 \r
195                                         /* If the above function invocation resulted in data that\r
196                                         should be sent out on the network, the global variable\r
197                                         uip_len is set to a value > 0. */\r
198                                         if( uip_len > 0 )\r
199                                         {\r
200                                                 uip_arp_out();\r
201                                                 vFECSendData();\r
202                                         }\r
203                                 }\r
204 \r
205                                 /* Call the ARP timer function every 10 seconds. */\r
206                                 if( timer_expired( &arp_timer ) )\r
207                                 {\r
208                                         timer_reset( &arp_timer );\r
209                                         uip_arp_timer();\r
210                                 }\r
211                         }\r
212                         else\r
213                         {\r
214                                 /* We did not receive a packet, and there was no periodic\r
215                                 processing to perform.  Block for a fixed period.  If a packet\r
216                                 is received during this period we will be woken by the ISR\r
217                                 giving us the Semaphore. */\r
218                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );\r
219                         }\r
220                 }\r
221         }\r
222 }\r
223 /*-----------------------------------------------------------*/\r
224 \r
225 \r
226 \r