]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF52233_Eclipse/RTOSDemo/webserver/uIP_Task.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / ColdFire_MCF52233_Eclipse / RTOSDemo / webserver / uIP_Task.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 \r
30 /* Task that controls the uIP TCP/IP stack. */\r
31 \r
32 \r
33 /* Standard includes. */\r
34 #include <string.h>\r
35 \r
36 /* Scheduler includes. */\r
37 #include "FreeRTOS.h"\r
38 #include "task.h"\r
39 #include "semphr.h"\r
40 \r
41 /* uip includes. */\r
42 #include "uip.h"\r
43 #include "uip_arp.h"\r
44 #include "httpd.h"\r
45 #include "timer.h"\r
46 #include "clock-arch.h"\r
47 \r
48 /* Demo includes. */\r
49 #include "FEC.h"\r
50 #include "partest.h"\r
51 \r
52 \r
53 /*-----------------------------------------------------------*/\r
54 \r
55 /* Shortcut to the header within the Rx buffer. */\r
56 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
57 \r
58 /*-----------------------------------------------------------*/\r
59 \r
60 /*\r
61  * Port functions required by the uIP stack.\r
62  */\r
63 void clock_init( void );\r
64 clock_time_t clock_time( void );\r
65 extern void timer_set(struct timer *t, clock_time_t interval);\r
66 extern int timer_expired(struct timer *t);\r
67 extern void timer_reset(struct timer *t);\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 /* The semaphore used by the ISR to wake the uIP task. */\r
72 extern xSemaphoreHandle xFECSemaphore;\r
73 \r
74 /*-----------------------------------------------------------*/\r
75 \r
76 void clock_init(void)\r
77 {\r
78         /* This is done when the scheduler starts. */\r
79 }\r
80 /*-----------------------------------------------------------*/\r
81 \r
82 /* Define clock functions here to avoid header file name clash between uIP\r
83 and the Luminary Micro driver library. */\r
84 clock_time_t clock_time( void )\r
85 {\r
86         return xTaskGetTickCount();\r
87 }\r
88 /*-----------------------------------------------------------*/\r
89 \r
90 void vuIP_Task( void *pvParameters )\r
91 {\r
92 portBASE_TYPE i;\r
93 uip_ipaddr_t xIPAddr;\r
94 struct timer periodic_timer, arp_timer;\r
95 \r
96         /* To prevent compiler warnings. */\r
97         ( void ) pvParameters;\r
98 \r
99         /* Initialise the uIP stack. */\r
100         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
101         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
102         uip_init();\r
103         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
104         uip_sethostaddr( xIPAddr );\r
105 \r
106         /* Initialise the WEB server. */\r
107         httpd_init();\r
108 \r
109         /* Initialise the Ethernet controller peripheral. */\r
110         vFECInit();\r
111 \r
112         for( ;; )\r
113         {\r
114                 /* Is there received data ready to be processed? */\r
115                 uip_len = usFECGetRxedData();\r
116 \r
117                 if( uip_len > 0 )\r
118                 {\r
119                         /* Standard uIP loop taken from the uIP manual. */\r
120 \r
121                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
122                         {\r
123                                 uip_arp_ipin();\r
124                                 uip_input();\r
125 \r
126                                 /* If the above function invocation resulted in data that\r
127                                 should be sent out on the network, the global variable\r
128                                 uip_len is set to a value > 0. */\r
129                                 if( uip_len > 0 )\r
130                                 {\r
131                                         uip_arp_out();\r
132                                         vFECSendData();\r
133                                 }\r
134                                 else\r
135                                 {\r
136                                         /* If we are not sending data then let the FEC driver know\r
137                                         the buffer is no longer required. */\r
138                                         vFECRxProcessingCompleted();\r
139                                 }\r
140                         }\r
141                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
142                         {\r
143                                 uip_arp_arpin();\r
144 \r
145                                 /* If the above function invocation resulted in data that\r
146                                 should be sent out on the network, the global variable\r
147                                 uip_len is set to a value > 0. */\r
148                                 if( uip_len > 0 )\r
149                                 {\r
150                                         vFECSendData();\r
151                                 }\r
152                                 else\r
153                                 {\r
154                                         /* If we are not sending data then let the FEC driver know\r
155                                         the buffer is no longer required. */\r
156                                         vFECRxProcessingCompleted();\r
157                                 }\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\r
167                 {\r
168                         if( timer_expired( &periodic_timer ) )\r
169                         {\r
170                                 timer_reset( &periodic_timer );\r
171                                 for( i = 0; i < UIP_CONNS; i++ )\r
172                                 {\r
173                                         uip_periodic( i );\r
174 \r
175                                         /* If the above function invocation resulted in data that\r
176                                         should be sent out on the network, the global variable\r
177                                         uip_len is set to a value > 0. */\r
178                                         if( uip_len > 0 )\r
179                                         {\r
180                                                 uip_arp_out();\r
181                                                 vFECSendData();\r
182                                         }\r
183                                 }\r
184 \r
185                                 /* Call the ARP timer function every 10 seconds. */\r
186                                 if( timer_expired( &arp_timer ) )\r
187                                 {\r
188                                         timer_reset( &arp_timer );\r
189                                         uip_arp_timer();\r
190                                 }\r
191                         }\r
192                         else\r
193                         {\r
194                                 /* We did not receive a packet, and there was no periodic\r
195                                 processing to perform.  Block for a fixed period.  If a packet\r
196                                 is received during this period we will be woken by the ISR\r
197                                 giving us the Semaphore. */\r
198                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );\r
199                         }\r
200                 }\r
201         }\r
202 }\r
203 /*-----------------------------------------------------------*/\r
204 \r
205 \r
206 \r