2 FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
53 /* Task that controls the uIP TCP/IP stack. */
\r
56 /* Standard includes. */
\r
59 /* Scheduler includes. */
\r
60 #include "FreeRTOS.h"
\r
66 #include "uip_arp.h"
\r
69 #include "clock-arch.h"
\r
71 /* Demo includes. */
\r
73 #include "partest.h"
\r
76 /*-----------------------------------------------------------*/
\r
78 /* Shortcut to the header within the Rx buffer. */
\r
79 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
81 /*-----------------------------------------------------------*/
\r
84 * Port functions required by the uIP stack.
\r
86 void clock_init( void );
\r
87 clock_time_t clock_time( void );
\r
88 extern void timer_set(struct timer *t, clock_time_t interval);
\r
89 extern int timer_expired(struct timer *t);
\r
90 extern void timer_reset(struct timer *t);
\r
92 /*-----------------------------------------------------------*/
\r
94 /* The semaphore used by the ISR to wake the uIP task. */
\r
95 extern xSemaphoreHandle xFECSemaphore;
\r
97 /*-----------------------------------------------------------*/
\r
99 void clock_init(void)
\r
101 /* This is done when the scheduler starts. */
\r
103 /*-----------------------------------------------------------*/
\r
105 /* Define clock functions here to avoid header file name clash between uIP
\r
106 and the Luminary Micro driver library. */
\r
107 clock_time_t clock_time( void )
\r
109 return xTaskGetTickCount();
\r
111 /*-----------------------------------------------------------*/
\r
113 void vuIP_Task( void *pvParameters )
\r
116 uip_ipaddr_t xIPAddr;
\r
117 struct timer periodic_timer, arp_timer;
\r
119 /* To prevent compiler warnings. */
\r
120 ( void ) pvParameters;
\r
122 /* Initialise the uIP stack. */
\r
123 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
124 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
126 uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
127 uip_sethostaddr( xIPAddr );
\r
129 /* Initialise the WEB server. */
\r
132 /* Initialise the Ethernet controller peripheral. */
\r
137 /* Is there received data ready to be processed? */
\r
138 uip_len = usFECGetRxedData();
\r
142 /* Standard uIP loop taken from the uIP manual. */
\r
144 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
149 /* If the above function invocation resulted in data that
\r
150 should be sent out on the network, the global variable
\r
151 uip_len is set to a value > 0. */
\r
159 /* If we are not sending data then let the FEC driver know
\r
160 the buffer is no longer required. */
\r
161 vFECRxProcessingCompleted();
\r
164 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
168 /* If the above function invocation resulted in data that
\r
169 should be sent out on the network, the global variable
\r
170 uip_len is set to a value > 0. */
\r
177 /* If we are not sending data then let the FEC driver know
\r
178 the buffer is no longer required. */
\r
179 vFECRxProcessingCompleted();
\r
184 /* If we are not sending data then let the FEC driver know
\r
185 the buffer is no longer required. */
\r
186 vFECRxProcessingCompleted();
\r
191 if( timer_expired( &periodic_timer ) )
\r
193 timer_reset( &periodic_timer );
\r
194 for( i = 0; i < UIP_CONNS; i++ )
\r
198 /* If the above function invocation resulted in data that
\r
199 should be sent out on the network, the global variable
\r
200 uip_len is set to a value > 0. */
\r
208 /* Call the ARP timer function every 10 seconds. */
\r
209 if( timer_expired( &arp_timer ) )
\r
211 timer_reset( &arp_timer );
\r
217 /* We did not receive a packet, and there was no periodic
\r
218 processing to perform. Block for a fixed period. If a packet
\r
219 is received during this period we will be woken by the ISR
\r
220 giving us the Semaphore. */
\r
221 xSemaphoreTake( xFECSemaphore, configTICK_RATE_HZ / 2 );
\r
226 /*-----------------------------------------------------------*/
\r