2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 /* Task that controls the uIP TCP/IP stack. */
\r
33 /* Standard includes. */
\r
36 /* Scheduler includes. */
\r
37 #include "FreeRTOS.h"
\r
43 #include "uip_arp.h"
\r
46 #include "clock-arch.h"
\r
48 /* Demo includes. */
\r
50 #include "partest.h"
\r
53 /*-----------------------------------------------------------*/
\r
55 /* Shortcut to the header within the Rx buffer. */
\r
56 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
58 /*-----------------------------------------------------------*/
\r
61 * Port functions required by the uIP stack.
\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
69 /*-----------------------------------------------------------*/
\r
71 /* The semaphore used by the ISR to wake the uIP task. */
\r
72 extern xSemaphoreHandle xFECSemaphore;
\r
74 /*-----------------------------------------------------------*/
\r
76 void clock_init(void)
\r
78 /* This is done when the scheduler starts. */
\r
80 /*-----------------------------------------------------------*/
\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
86 return xTaskGetTickCount();
\r
88 /*-----------------------------------------------------------*/
\r
90 void vuIP_Task( void *pvParameters )
\r
93 uip_ipaddr_t xIPAddr;
\r
94 struct timer periodic_timer, arp_timer;
\r
96 /* To prevent compiler warnings. */
\r
97 ( void ) pvParameters;
\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
103 uip_ipaddr( xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );
\r
104 uip_sethostaddr( xIPAddr );
\r
106 /* Initialise the WEB server. */
\r
109 /* Initialise the Ethernet controller peripheral. */
\r
114 /* Is there received data ready to be processed? */
\r
115 uip_len = usFECGetRxedData();
\r
119 /* Standard uIP loop taken from the uIP manual. */
\r
121 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\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
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
141 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\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
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
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
168 if( timer_expired( &periodic_timer ) )
\r
170 timer_reset( &periodic_timer );
\r
171 for( i = 0; i < UIP_CONNS; i++ )
\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
185 /* Call the ARP timer function every 10 seconds. */
\r
186 if( timer_expired( &arp_timer ) )
\r
188 timer_reset( &arp_timer );
\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
203 /*-----------------------------------------------------------*/
\r