]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/webserver/uIP_Task.c
Update the demo directory to use the version 8 type naming conventions.
[freertos] / FreeRTOS / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / webserver / uIP_Task.c
1 /*\r
2  * Modified from an original work that is Copyright (c) 2001-2003, Adam Dunkels.\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\r
8  * 1. Redistributions of source code must retain the above copyright\r
9  *    notice, this list of conditions and the following disclaimer.\r
10  * 2. Redistributions in binary form must reproduce the above copyright\r
11  *    notice, this list of conditions and the following disclaimer in the\r
12  *    documentation and/or other materials provided with the distribution.\r
13  * 3. The name of the author may not be used to endorse or promote\r
14  *    products derived from this software without specific prior\r
15  *    written permission.\r
16  *\r
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS\r
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY\r
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\r
23  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28  *\r
29  * This file is part of the uIP TCP/IP stack.\r
30  *\r
31  * $Id: main.c,v 1.10.2.4 2003/10/21 21:27:51 adam Exp $\r
32  *\r
33  */\r
34 \r
35 /* Standard includes. */\r
36 #include <stdlib.h>\r
37 #include <string.h>\r
38 #include <stdio.h>\r
39 \r
40 /* Scheduler includes. */\r
41 #include "FreeRTOS.h"\r
42 #include "task.h"\r
43 #include "semphr.h"\r
44 \r
45 /* uip includes. */\r
46 #include "uip.h"\r
47 #include "uip_arp.h"\r
48 #include "httpd.h"\r
49 #include "timer.h"\r
50 #include "clock-arch.h"\r
51 \r
52 /* Demo includes. */\r
53 #include "SAM7_EMAC.h"\r
54 #include "partest.h"\r
55 \r
56 /* How long to wait before attempting to connect the MAC again. */\r
57 #define uipINIT_WAIT    ( 100 / portTICK_PERIOD_MS )\r
58 \r
59 /* Shortcut to the header within the Rx buffer. */\r
60 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])\r
61 \r
62 /* The semaphore used by the ISR to wake the uIP task. */\r
63 static SemaphoreHandle_t xEMACSemaphore;\r
64 \r
65 /*-----------------------------------------------------------*/\r
66 \r
67 void vuIP_Task( void *pvParameters )\r
68 {\r
69 portBASE_TYPE i;\r
70 uip_ipaddr_t xIPAddr;\r
71 struct timer periodic_timer, arp_timer;\r
72 \r
73         /* Initialise the uIP stack. */\r
74         timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );\r
75         timer_set( &arp_timer, configTICK_RATE_HZ * 10 );\r
76         uip_init();\r
77         uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );\r
78         uip_sethostaddr( xIPAddr );\r
79         httpd_init();\r
80 \r
81         /* Initialise the MAC. */\r
82         do\r
83     {\r
84                 vTaskDelay( uipINIT_WAIT );\r
85                 xEMACSemaphore = xEMACInit();        \r
86     } while( xEMACSemaphore == NULL );\r
87 \r
88         for( ;; )\r
89         {\r
90                 /* Is there received data ready to be processed? */\r
91                 uip_len = ulEMACPoll();\r
92                 \r
93                 if( uip_len > 0 )\r
94                 {\r
95                         /* Standard uIP loop taken from the uIP manual. */\r
96                         if( xHeader->type == htons( UIP_ETHTYPE_IP ) )\r
97                         {\r
98                                 uip_arp_ipin();\r
99                                 uip_input();\r
100 \r
101                                 /* If the above function invocation resulted in data that \r
102                                 should be sent out on the network, the global variable \r
103                                 uip_len is set to a value > 0. */\r
104                                 if( uip_len > 0 )\r
105                                 {\r
106                                         uip_arp_out();\r
107                                         lEMACSend();\r
108                                 }\r
109                         }\r
110                         else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )\r
111                         {\r
112                                 uip_arp_arpin();\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                                         lEMACSend();\r
120                                 }\r
121                         }\r
122                 }\r
123                 else\r
124                 {\r
125                         if( timer_expired( &periodic_timer ) )\r
126                         {\r
127                                 timer_reset( &periodic_timer );\r
128                                 for( i = 0; i < UIP_CONNS; i++ )\r
129                                 {\r
130                                         uip_periodic( i );\r
131         \r
132                                         /* If the above function invocation resulted in data that \r
133                                         should be sent out on the network, the global variable \r
134                                         uip_len is set to a value > 0. */\r
135                                         if( uip_len > 0 )\r
136                                         {\r
137                                                 uip_arp_out();\r
138                                                 lEMACSend();\r
139                                         }\r
140                                 }       \r
141         \r
142                                 /* Call the ARP timer function every 10 seconds. */\r
143                                 if( timer_expired( &arp_timer ) )\r
144                                 {\r
145                                         timer_reset( &arp_timer );\r
146                                         uip_arp_timer();\r
147                                 }\r
148                         }\r
149                         else\r
150                         {                       \r
151                                 /* We did not receive a packet, and there was no periodic\r
152                                 processing to perform.  Block for a fixed period.  If a packet\r
153                                 is received during this period we will be woken by the ISR\r
154                                 giving us the Semaphore. */\r
155                                 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );                       \r
156                         }\r
157                 }\r
158         }\r
159 }\r
160 /*-----------------------------------------------------------------------------------*/\r
161 \r
162 void clock_init(void)\r
163 {\r
164         /* This is done when the scheduler starts. */\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 clock_time_t clock_time( void )\r
169 {\r
170         return xTaskGetTickCount();\r
171 }\r
172 /*-----------------------------------------------------------*/\r
173 \r
174 void vProcessInput( char *pcInput )\r
175 {\r
176 char *c;\r
177 \r
178         /* Turn the LED on or off depending on the checkbox status. */\r
179 \r
180         c = strstr( pcInput, "?" );\r
181         if( c )\r
182         {\r
183                 if( strstr( c, "LED0=1" ) != NULL )\r
184                 {\r
185                         vParTestSetLED( 3, 0 );\r
186                 }\r
187                 else\r
188                 {\r
189                         vParTestSetLED( 3, 1 );\r
190                 }               \r
191         }\r
192 }\r
193 \r
194 \r
195 \r
196 \r
197 \r