]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
Change version numbers ready for V8.0.0 release candidate 1 tag.
[freertos] / FreeRTOS / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / webserver / uIP_Task.c
1 /*\r
2     FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 \r
67 /* Task that controls the uIP TCP/IP stack. */\r
68 \r
69 \r
70 /* Standard includes. */\r
71 #include <string.h>\r
72 \r
73 /* Scheduler includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 #include "semphr.h"\r
77 \r
78 /* uip includes. */\r
79 #include "uip.h"\r
80 #include "uip_arp.h"\r
81 #include "httpd.h"\r
82 #include "timer.h"\r
83 #include "clock-arch.h"\r
84 \r
85 /* Demo includes. */\r
86 #include "FEC.h"\r
87 #include "partest.h"\r
88 \r
89 \r
90 /*-----------------------------------------------------------*/\r
91 \r
92 /* Shortcut to the header within the Rx buffer. */\r
93 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
94 \r
95 /*-----------------------------------------------------------*/\r
96 \r
97 /*\r
98  * Port functions required by the uIP stack.\r
99  */\r
100 void clock_init( void );\r
101 clock_time_t clock_time( void );\r
102 extern void timer_set(struct timer *t, clock_time_t interval);\r
103 extern int timer_expired(struct timer *t);\r
104 extern void timer_reset(struct timer *t);\r
105 \r
106 /*-----------------------------------------------------------*/\r
107 \r
108 /* The semaphore used by the ISR to wake the uIP task. */\r
109 extern xSemaphoreHandle xFECSemaphore;\r
110 \r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void clock_init(void)\r
114 {\r
115         /* This is done when the scheduler starts. */\r
116 }\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 /* Define clock functions here to avoid header file name clash between uIP\r
120 and the Luminary Micro driver library. */\r
121 clock_time_t clock_time( void )\r
122 {\r
123         return xTaskGetTickCount();\r
124 }\r
125 /*-----------------------------------------------------------*/\r
126 \r
127 void vuIP_Task( void *pvParameters )\r
128 {\r
129 portBASE_TYPE i;\r
130 uip_ipaddr_t xIPAddr;\r
131 struct timer periodic_timer, arp_timer;\r
132 \r
133         /* To prevent compiler warnings. */\r
134         ( void ) pvParameters;\r
135 \r
136         /* Initialise the uIP stack. */\r
137         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
138         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
139         uip_init();\r
140         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
141         uip_sethostaddr( xIPAddr );\r
142 \r
143         /* Initialise the WEB server. */\r
144         httpd_init();\r
145 \r
146         /* Initialise the Ethernet controller peripheral. */\r
147         vFECInit();\r
148 \r
149         for( ;; )\r
150         {\r
151                 /* Is there received data ready to be processed? */\r
152                 uip_len = usFECGetRxedData();\r
153 \r
154                 if( uip_len > 0 )\r
155                 {\r
156                         /* Standard uIP loop taken from the uIP manual. */\r
157 \r
158                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
159                         {\r
160                                 uip_arp_ipin();\r
161                                 uip_input();\r
162 \r
163                                 /* If the above function invocation resulted in data that\r
164                                 should be sent out on the network, the global variable\r
165                                 uip_len is set to a value > 0. */\r
166                                 if( uip_len > 0 )\r
167                                 {\r
168                                         uip_arp_out();\r
169                                         vFECSendData();\r
170                                 }\r
171                                 else\r
172                                 {\r
173                                         /* If we are not sending data then let the FEC driver know\r
174                                         the buffer is no longer required. */\r
175                                         vFECRxProcessingCompleted();\r
176                                 }\r
177                         }\r
178                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
179                         {\r
180                                 uip_arp_arpin();\r
181 \r
182                                 /* If the above function invocation resulted in data that\r
183                                 should be sent out on the network, the global variable\r
184                                 uip_len is set to a value > 0. */\r
185                                 if( uip_len > 0 )\r
186                                 {\r
187                                         vFECSendData();\r
188                                 }\r
189                                 else\r
190                                 {\r
191                                         /* If we are not sending data then let the FEC driver know\r
192                                         the buffer is no longer required. */\r
193                                         vFECRxProcessingCompleted();\r
194                                 }\r
195                         }\r
196                         else\r
197                         {\r
198                                 /* If we are not sending data then let the FEC driver know\r
199                                 the buffer is no longer required. */\r
200                                 vFECRxProcessingCompleted();\r
201                         }\r
202                 }\r
203                 else\r
204                 {\r
205                         if( timer_expired( &periodic_timer ) )\r
206                         {\r
207                                 timer_reset( &periodic_timer );\r
208                                 for( i = 0; i < UIP_CONNS; i++ )\r
209                                 {\r
210                                         uip_periodic( i );\r
211 \r
212                                         /* If the above function invocation resulted in data that\r
213                                         should be sent out on the network, the global variable\r
214                                         uip_len is set to a value > 0. */\r
215                                         if( uip_len > 0 )\r
216                                         {\r
217                                                 uip_arp_out();\r
218                                                 vFECSendData();\r
219                                         }\r
220                                 }\r
221 \r
222                                 /* Call the ARP timer function every 10 seconds. */\r
223                                 if( timer_expired( &arp_timer ) )\r
224                                 {\r
225                                         timer_reset( &arp_timer );\r
226                                         uip_arp_timer();\r
227                                 }\r
228                         }\r
229                         else\r
230                         {\r
231                                 /* We did not receive a packet, and there was no periodic\r
232                                 processing to perform.  Block for a fixed period.  If a packet\r
233                                 is received during this period we will be woken by the ISR\r
234                                 giving us the Semaphore. */\r
235                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );\r
236                         }\r
237                 }\r
238         }\r
239 }\r
240 /*-----------------------------------------------------------*/\r
241 \r
242 \r
243 \r