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
28 /* Standard includes. */
\r
31 /* Scheduler includes. */
\r
32 #include "FreeRTOS.h"
\r
38 #include "uip_arp.h"
\r
41 #include "clock-arch.h"
\r
43 /* Demo includes. */
\r
45 #include "partest.h"
\r
47 /*-----------------------------------------------------------*/
\r
49 /* MAC address configuration. */
\r
50 #define uipMAC_ADDR0 0x00
\r
51 #define uipMAC_ADDR1 0x12
\r
52 #define uipMAC_ADDR2 0x13
\r
53 #define uipMAC_ADDR3 0x10
\r
54 #define uipMAC_ADDR4 0x15
\r
55 #define uipMAC_ADDR5 0x11
\r
57 /* IP address configuration. */
\r
58 #define uipIP_ADDR0 192
\r
59 #define uipIP_ADDR1 168
\r
60 #define uipIP_ADDR2 0
\r
61 #define uipIP_ADDR3 200
\r
63 /* How long to wait before attempting to connect the MAC again. */
\r
64 #define uipINIT_WAIT 200
\r
66 /* Shortcut to the header within the Rx buffer. */
\r
67 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
69 /* Standard constant. */
\r
70 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
72 /*-----------------------------------------------------------*/
\r
75 * Send the uIP buffer to the MAC.
\r
77 static void prvENET_Send(void);
\r
80 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
82 static void prvSetMACAddress( void );
\r
85 * Port functions required by the uIP stack.
\r
87 void clock_init( void );
\r
88 clock_time_t clock_time( void );
\r
90 /*-----------------------------------------------------------*/
\r
92 /* The semaphore used by the ISR to wake the uIP task. */
\r
93 extern SemaphoreHandle_t xEMACSemaphore;
\r
95 /*-----------------------------------------------------------*/
\r
97 void clock_init(void)
\r
99 /* This is done when the scheduler starts. */
\r
101 /*-----------------------------------------------------------*/
\r
103 clock_time_t clock_time( void )
\r
105 return xTaskGetTickCount();
\r
107 /*-----------------------------------------------------------*/
\r
109 void vuIP_Task( void *pvParameters )
\r
112 uip_ipaddr_t xIPAddr;
\r
113 struct timer periodic_timer, arp_timer;
\r
114 extern void ( vEMAC_ISR_Wrapper )( void );
\r
116 /* Create the semaphore used by the ISR to wake this task. */
\r
117 vSemaphoreCreateBinary( xEMACSemaphore );
\r
119 /* Initialise the uIP stack. */
\r
120 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
121 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
123 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
124 uip_sethostaddr( xIPAddr );
\r
127 /* Initialise the MAC. */
\r
128 while( Init_EMAC() != pdPASS )
\r
130 vTaskDelay( uipINIT_WAIT );
\r
133 portENTER_CRITICAL();
\r
135 IntEnable = INT_RX_DONE;
\r
136 VICIntEnable |= 0x00200000;
\r
137 VICVectAddr21 = ( long ) vEMAC_ISR_Wrapper;
\r
138 prvSetMACAddress();
\r
140 portEXIT_CRITICAL();
\r
145 /* Is there received data ready to be processed? */
\r
146 uip_len = uiGetEMACRxData( uip_buf );
\r
150 /* Standard uIP loop taken from the uIP manual. */
\r
151 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
156 /* If the above function invocation resulted in data that
\r
157 should be sent out on the network, the global variable
\r
158 uip_len is set to a value > 0. */
\r
165 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
169 /* If the above function invocation resulted in data that
\r
170 should be sent out on the network, the global variable
\r
171 uip_len is set to a value > 0. */
\r
180 if( timer_expired( &periodic_timer ) )
\r
182 timer_reset( &periodic_timer );
\r
183 for( i = 0; i < UIP_CONNS; i++ )
\r
187 /* If the above function invocation resulted in data that
\r
188 should be sent out on the network, the global variable
\r
189 uip_len is set to a value > 0. */
\r
197 /* Call the ARP timer function every 10 seconds. */
\r
198 if( timer_expired( &arp_timer ) )
\r
200 timer_reset( &arp_timer );
\r
206 /* We did not receive a packet, and there was no periodic
\r
207 processing to perform. Block for a fixed period. If a packet
\r
208 is received during this period we will be woken by the ISR
\r
209 giving us the Semaphore. */
\r
210 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvENET_Send(void)
\r
221 /* Copy the header into the Tx buffer. */
\r
222 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
223 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
225 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
228 DoSend_EMAC( uip_len );
\r
232 /* Copy the header into the Tx buffer. */
\r
233 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
234 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
236 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
239 DoSend_EMAC( uip_len );
\r
241 /*-----------------------------------------------------------*/
\r
243 static void prvSetMACAddress( void )
\r
245 struct uip_eth_addr xAddr;
\r
247 /* Configure the MAC address in the uIP stack. */
\r
248 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
249 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
250 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
251 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
252 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
253 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
254 uip_setethaddr( xAddr );
\r
256 /*-----------------------------------------------------------*/
\r
258 void vApplicationProcessFormInput( char *pcInputString, portBASE_TYPE xInputLength )
\r
261 static char cMessageForDisplay[ 32 ];
\r
262 extern QueueHandle_t xLCDQueue;
\r
263 xLCDMessage xLCDMessage;
\r
265 /* Process the form input sent by the IO page of the served HTML. */
\r
267 c = strstr( pcInputString, "?" );
\r
270 /* Turn LED's on or off in accordance with the check box status. */
\r
271 if( strstr( c, "LED0=1" ) != NULL )
\r
273 vParTestSetLED( 5, 0 );
\r
277 vParTestSetLED( 5, 1 );
\r
280 if( strstr( c, "LED1=1" ) != NULL )
\r
282 vParTestSetLED( 6, 0 );
\r
286 vParTestSetLED( 6, 1 );
\r
289 if( strstr( c, "LED2=1" ) != NULL )
\r
291 vParTestSetLED( 7, 0 );
\r
295 vParTestSetLED( 7, 1 );
\r
298 /* Find the start of the text to be displayed on the LCD. */
\r
299 pcText = strstr( c, "LCD=" );
\r
300 pcText += strlen( "LCD=" );
\r
302 /* Terminate the file name for further processing within uIP. */
\r
305 /* Terminate the LCD string. */
\r
306 c = strstr( pcText, " " );
\r
312 /* Add required spaces. */
\r
313 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
318 /* Write the message to the LCD. */
\r
319 strcpy( cMessageForDisplay, pcText );
\r
320 xLCDMessage.xColumn = 0;
\r
321 xLCDMessage.pcMessage = cMessageForDisplay;
\r
322 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r