]> git.sur5r.net Git - freertos/blob - Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
44b0a071918e974f34586478850193f63c4837ca
[freertos] / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / webserver / uIP_Task.c
1 /*\r
2     FreeRTOS V7.0.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 \r
55 /* Task that controls the uIP TCP/IP stack. */\r
56 \r
57 \r
58 /* Standard includes. */\r
59 #include <string.h>\r
60 \r
61 /* Scheduler includes. */\r
62 #include "FreeRTOS.h"\r
63 #include "task.h"\r
64 #include "semphr.h"\r
65 \r
66 /* uip includes. */\r
67 #include "uip.h"\r
68 #include "uip_arp.h"\r
69 #include "httpd.h"\r
70 #include "timer.h"\r
71 #include "clock-arch.h"\r
72 \r
73 /* Demo includes. */\r
74 #include "FEC.h"\r
75 #include "partest.h"\r
76 \r
77 \r
78 /*-----------------------------------------------------------*/\r
79 \r
80 /* Shortcut to the header within the Rx buffer. */\r
81 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
82 \r
83 /*-----------------------------------------------------------*/\r
84 \r
85 /*\r
86  * Port functions required by the uIP stack.\r
87  */\r
88 void clock_init( void );\r
89 clock_time_t clock_time( void );\r
90 extern void timer_set(struct timer *t, clock_time_t interval);\r
91 extern int timer_expired(struct timer *t);\r
92 extern void timer_reset(struct timer *t);\r
93 \r
94 /*-----------------------------------------------------------*/\r
95 \r
96 /* The semaphore used by the ISR to wake the uIP task. */\r
97 extern xSemaphoreHandle xFECSemaphore;\r
98 \r
99 /*-----------------------------------------------------------*/\r
100 \r
101 void clock_init(void)\r
102 {\r
103         /* This is done when the scheduler starts. */\r
104 }\r
105 /*-----------------------------------------------------------*/\r
106 \r
107 /* Define clock functions here to avoid header file name clash between uIP\r
108 and the Luminary Micro driver library. */\r
109 clock_time_t clock_time( void )\r
110 {\r
111         return xTaskGetTickCount();\r
112 }\r
113 /*-----------------------------------------------------------*/\r
114 \r
115 void vuIP_Task( void *pvParameters )\r
116 {\r
117 portBASE_TYPE i;\r
118 uip_ipaddr_t xIPAddr;\r
119 struct timer periodic_timer, arp_timer;\r
120 \r
121         /* To prevent compiler warnings. */\r
122         ( void ) pvParameters;\r
123 \r
124         /* Initialise the uIP stack. */\r
125         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
126         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
127         uip_init();\r
128         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
129         uip_sethostaddr( xIPAddr );\r
130 \r
131         /* Initialise the WEB server. */\r
132         httpd_init();\r
133 \r
134         /* Initialise the Ethernet controller peripheral. */\r
135         vFECInit();\r
136 \r
137         for( ;; )\r
138         {\r
139                 /* Is there received data ready to be processed? */\r
140                 uip_len = usFECGetRxedData();\r
141 \r
142                 if( uip_len > 0 )\r
143                 {\r
144                         /* Standard uIP loop taken from the uIP manual. */\r
145 \r
146                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
147                         {\r
148                                 uip_arp_ipin();\r
149                                 uip_input();\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                                         uip_arp_out();\r
157                                         vFECSendData();\r
158                                 }\r
159                                 else\r
160                                 {\r
161                                         /* If we are not sending data then let the FEC driver know\r
162                                         the buffer is no longer required. */\r
163                                         vFECRxProcessingCompleted();\r
164                                 }\r
165                         }\r
166                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
167                         {\r
168                                 uip_arp_arpin();\r
169 \r
170                                 /* If the above function invocation resulted in data that\r
171                                 should be sent out on the network, the global variable\r
172                                 uip_len is set to a value > 0. */\r
173                                 if( uip_len > 0 )\r
174                                 {\r
175                                         vFECSendData();\r
176                                 }\r
177                                 else\r
178                                 {\r
179                                         /* If we are not sending data then let the FEC driver know\r
180                                         the buffer is no longer required. */\r
181                                         vFECRxProcessingCompleted();\r
182                                 }\r
183                         }\r
184                         else\r
185                         {\r
186                                 /* If we are not sending data then let the FEC driver know\r
187                                 the buffer is no longer required. */\r
188                                 vFECRxProcessingCompleted();\r
189                         }\r
190                 }\r
191                 else\r
192                 {\r
193                         if( timer_expired( &periodic_timer ) )\r
194                         {\r
195                                 timer_reset( &periodic_timer );\r
196                                 for( i = 0; i < UIP_CONNS; i++ )\r
197                                 {\r
198                                         uip_periodic( i );\r
199 \r
200                                         /* If the above function invocation resulted in data that\r
201                                         should be sent out on the network, the global variable\r
202                                         uip_len is set to a value > 0. */\r
203                                         if( uip_len > 0 )\r
204                                         {\r
205                                                 uip_arp_out();\r
206                                                 vFECSendData();\r
207                                         }\r
208                                 }\r
209 \r
210                                 /* Call the ARP timer function every 10 seconds. */\r
211                                 if( timer_expired( &arp_timer ) )\r
212                                 {\r
213                                         timer_reset( &arp_timer );\r
214                                         uip_arp_timer();\r
215                                 }\r
216                         }\r
217                         else\r
218                         {\r
219                                 /* We did not receive a packet, and there was no periodic\r
220                                 processing to perform.  Block for a fixed period.  If a packet\r
221                                 is received during this period we will be woken by the ISR\r
222                                 giving us the Semaphore. */\r
223                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );\r
224                         }\r
225                 }\r
226         }\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 \r
231 \r