]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ColdFire_MCF51CN128_CodeWarrior/Sources/httpd/uIP_Task.c
Update version number in readiness for V10.2.0 release.
[freertos] / FreeRTOS / Demo / ColdFire_MCF51CN128_CodeWarrior / Sources / httpd / uIP_Task.c
1 /*\r
2  * FreeRTOS Kernel V10.2.0\r
3  * Copyright (C) 2019 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Standard includes. */\r
29 #include <string.h>\r
30 \r
31 /* Scheduler includes. */\r
32 #include "FreeRTOS.h"\r
33 #include "task.h"\r
34 #include "semphr.h"\r
35 \r
36 /* uip includes. */\r
37 #include "uip.h"\r
38 #include "uip_arp.h"\r
39 #include "httpd.h"\r
40 #include "timer.h"\r
41 #include "clock-arch.h"\r
42 #include "timer.h"\r
43 \r
44 /* Demo includes. */\r
45 #include "FEC.h"\r
46 #include "partest.h"\r
47 \r
48 /*-----------------------------------------------------------*/\r
49 \r
50 /* Shortcut to the header within the Rx buffer. */\r
51 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
52 \r
53 /*-----------------------------------------------------------*/\r
54 \r
55 /*\r
56  * Port functions required by the uIP stack.\r
57  */\r
58 clock_time_t clock_time( void );\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 \r
62 /* The semaphore used by the ISR to wake the uIP task. */\r
63 extern SemaphoreHandle_t xFECSemaphore;\r
64 \r
65 /*-----------------------------------------------------------*/\r
66 \r
67 clock_time_t clock_time( void )\r
68 {\r
69         return xTaskGetTickCount();\r
70 }\r
71 \r
72 \r
73 void vuIP_Task( void *pvParameters )\r
74 {\r
75 portBASE_TYPE i;\r
76 uip_ipaddr_t xIPAddr;\r
77 struct timer periodic_timer, arp_timer;\r
78 extern void ( vEMAC_ISR )( void );\r
79 \r
80         /* Just to get rid of the compiler warning. */\r
81         ( void ) pvParameters;\r
82 \r
83         /* Enable/Reset the Ethernet Controller */\r
84 \r
85         /* Create the semaphore used by the ISR to wake this task. */\r
86         vSemaphoreCreateBinary( xFECSemaphore );\r
87         \r
88         /* Initialise the uIP stack. */\r
89         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
90         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
91         uip_init();\r
92         uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
93         uip_sethostaddr( xIPAddr );\r
94         uip_ipaddr( xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 );\r
95         uip_setnetmask( xIPAddr );              \r
96         httpd_init();\r
97 \r
98         vInitFEC();\r
99 \r
100         for( ;; )\r
101         {\r
102                 /* Is there received data ready to be processed? */\r
103                 uip_len = ( unsigned short ) ulFECRx();\r
104                 \r
105                 if( ( uip_len > 0 ) && ( uip_buf != NULL ) )\r
106                 {\r
107                         /* Standard uIP loop taken from the uIP manual. */\r
108 \r
109                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
110                         {\r
111                                 uip_arp_ipin();\r
112                                 uip_input();\r
113 \r
114                                 /* If the above function invocation resulted in data that\r
115                                 should be sent out on the network, the global variable\r
116                                 uip_len is set to a value > 0. */\r
117                                 if( uip_len > 0 )\r
118                                 {\r
119                                         uip_arp_out();\r
120                                         vFECTx();\r
121                                 }\r
122                         }\r
123                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
124                         {\r
125                                 uip_arp_arpin();\r
126 \r
127                                 /* If the above function invocation resulted in data that\r
128                                 should be sent out on the network, the global variable\r
129                                 uip_len is set to a value > 0. */\r
130                                 if( uip_len > 0 )\r
131                                 {\r
132                                         vFECTx();\r
133                                 }\r
134                         }                       \r
135                 }\r
136                 else\r
137                 {\r
138                         if( ( timer_expired( &periodic_timer ) ) && ( uip_buf != NULL ) )\r
139                         {\r
140                                 timer_reset( &periodic_timer );\r
141                                 for( i = 0; i < UIP_CONNS; i++ )\r
142                                 {\r
143                                         uip_periodic( i );\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                                                 uip_arp_out();\r
151                                                 vFECTx();\r
152                                         }\r
153                                 }       \r
154         \r
155                                 /* Call the ARP timer function every 10 seconds. */\r
156                                 if( timer_expired( &arp_timer ) )\r
157                                 {\r
158                                         timer_reset( &arp_timer );\r
159                                         uip_arp_timer();\r
160                                 }\r
161                         }\r
162                         else\r
163                         {                       \r
164                                 /* We did not receive a packet, and there was no periodic\r
165                                 processing to perform.  Block for a fixed period.  If a packet\r
166                                 is received during this period we will be woken by the ISR\r
167                                 giving us the Semaphore. */\r
168                                 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );                        \r
169                         }\r
170                 }\r
171         }\r
172 }\r
173 /*-----------------------------------------------------------*/\r
174 \r
175 void vApplicationProcessFormInput( char *pcInputString, portBASE_TYPE xInputLength )\r
176 {\r
177 char *c;\r
178 \r
179         /* Just to get rid of the compiler warning - other ports/demos use the parameter. */\r
180         ( void ) xInputLength;\r
181 \r
182         /* Process the form input sent by the IO page of the served HTML. */\r
183 \r
184         c = strstr( pcInputString, "?" );\r
185 \r
186     if( c )\r
187     {\r
188                 /* Turn LED's on or off in accordance with the check box status. */\r
189                 if( strstr( c, "LED3=1" ) != NULL )\r
190                 {\r
191                         /* Turn LED 3 on. */\r
192                         vParTestSetLED( 3, 1 );\r
193                 }\r
194                 else\r
195                 {\r
196                         /* Turn LED 3 off. */\r
197                         vParTestSetLED( 3, 0 );\r
198                 }               \r
199     }\r
200 }\r
201 \r