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