2 * FreeRTOS Kernel V10.0.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
27 /* Standard includes. */
\r
30 /* Scheduler includes. */
\r
31 #include "FreeRTOS.h"
\r
37 #include "uip_arp.h"
\r
40 #include "clock-arch.h"
\r
42 /* Demo includes. */
\r
44 #include "partest.h"
\r
46 /*-----------------------------------------------------------*/
\r
48 /* MAC address configuration. */
\r
49 #define uipMAC_ADDR0 0x00
\r
50 #define uipMAC_ADDR1 0x12
\r
51 #define uipMAC_ADDR2 0x13
\r
52 #define uipMAC_ADDR3 0x10
\r
53 #define uipMAC_ADDR4 0x15
\r
54 #define uipMAC_ADDR5 0x11
\r
56 /* IP address configuration. */
\r
57 #define uipIP_ADDR0 172
\r
58 #define uipIP_ADDR1 25
\r
59 #define uipIP_ADDR2 218
\r
60 #define uipIP_ADDR3 16
\r
62 /* How long to wait before attempting to connect the MAC again. */
\r
63 #define uipINIT_WAIT 100
\r
65 /* Shortcut to the header within the Rx buffer. */
\r
66 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
68 /* Standard constant. */
\r
69 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
71 /*-----------------------------------------------------------*/
\r
74 * Send the uIP buffer to the MAC.
\r
76 static void prvENET_Send(void);
\r
79 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
81 static void prvSetMACAddress( void );
\r
84 * Port functions required by the uIP stack.
\r
86 void clock_init( void );
\r
87 clock_time_t clock_time( void );
\r
89 /*-----------------------------------------------------------*/
\r
91 /* The semaphore used by the ISR to wake the uIP task. */
\r
92 extern SemaphoreHandle_t xEMACSemaphore;
\r
94 /*-----------------------------------------------------------*/
\r
96 void clock_init(void)
\r
98 /* This is done when the scheduler starts. */
\r
100 /*-----------------------------------------------------------*/
\r
102 clock_time_t clock_time( void )
\r
104 return xTaskGetTickCount();
\r
106 /*-----------------------------------------------------------*/
\r
108 void vuIP_Task( void *pvParameters )
\r
111 uip_ipaddr_t xIPAddr;
\r
112 struct timer periodic_timer, arp_timer;
\r
113 extern void ( vEMAC_ISR_Wrapper )( void );
\r
115 /* Create the semaphore used by the ISR to wake this task. */
\r
116 vSemaphoreCreateBinary( xEMACSemaphore );
\r
118 /* Initialise the uIP stack. */
\r
119 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
120 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
122 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
123 uip_sethostaddr( xIPAddr );
\r
126 /* Initialise the MAC. */
\r
127 while( Init_EMAC() != pdPASS )
\r
129 vTaskDelay( uipINIT_WAIT );
\r
132 portENTER_CRITICAL();
\r
134 MAC_INTENABLE = INT_RX_DONE;
\r
135 VICIntEnable |= 0x00200000;
\r
136 VICVectAddr21 = ( long ) vEMAC_ISR_Wrapper;
\r
137 prvSetMACAddress();
\r
139 portEXIT_CRITICAL();
\r
144 /* Is there received data ready to be processed? */
\r
145 uip_len = uiGetEMACRxData( uip_buf );
\r
149 /* Standard uIP loop taken from the uIP manual. */
\r
150 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
155 /* If the above function invocation resulted in data that
\r
156 should be sent out on the network, the global variable
\r
157 uip_len is set to a value > 0. */
\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
179 if( timer_expired( &periodic_timer ) )
\r
181 timer_reset( &periodic_timer );
\r
182 for( i = 0; i < UIP_CONNS; i++ )
\r
186 /* If the above function invocation resulted in data that
\r
187 should be sent out on the network, the global variable
\r
188 uip_len is set to a value > 0. */
\r
196 /* Call the ARP timer function every 10 seconds. */
\r
197 if( timer_expired( &arp_timer ) )
\r
199 timer_reset( &arp_timer );
\r
205 /* We did not receive a packet, and there was no periodic
\r
206 processing to perform. Block for a fixed period. If a packet
\r
207 is received during this period we will be woken by the ISR
\r
208 giving us the Semaphore. */
\r
209 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
214 /*-----------------------------------------------------------*/
\r
216 static void prvENET_Send(void)
\r
220 /* Copy the header into the Tx buffer. */
\r
221 CopyToFrame_EMAC( uip_buf, uipTOTAL_FRAME_HEADER_SIZE );
\r
222 if( uip_len > uipTOTAL_FRAME_HEADER_SIZE )
\r
224 CopyToFrame_EMAC( uip_appdata, ( uip_len - uipTOTAL_FRAME_HEADER_SIZE ) );
\r
227 DoSend_EMAC( uip_len );
\r
229 /*-----------------------------------------------------------*/
\r
231 static void prvSetMACAddress( void )
\r
233 struct uip_eth_addr xAddr;
\r
235 /* Configure the MAC address in the uIP stack. */
\r
236 xAddr.addr[ 0 ] = uipMAC_ADDR0;
\r
237 xAddr.addr[ 1 ] = uipMAC_ADDR1;
\r
238 xAddr.addr[ 2 ] = uipMAC_ADDR2;
\r
239 xAddr.addr[ 3 ] = uipMAC_ADDR3;
\r
240 xAddr.addr[ 4 ] = uipMAC_ADDR4;
\r
241 xAddr.addr[ 5 ] = uipMAC_ADDR5;
\r
242 uip_setethaddr( xAddr );
\r
244 /*-----------------------------------------------------------*/
\r
246 void vApplicationProcessFormInput( char *pcInputString, portBASE_TYPE xInputLength )
\r
249 static char cMessageForDisplay[ 32 ];
\r
250 extern QueueHandle_t xLCDQueue;
\r
251 xLCDMessage xLCDMessage;
\r
253 /* Process the form input sent by the IO page of the served HTML. */
\r
255 c = strstr( pcInputString, "?" );
\r
258 /* Turn LED's on or off in accordance with the check box status. */
\r
259 if( strstr( c, "LED0=1" ) != NULL )
\r
261 vParTestSetLED( 5, 0 );
\r
265 vParTestSetLED( 5, 1 );
\r
268 if( strstr( c, "LED1=1" ) != NULL )
\r
270 vParTestSetLED( 6, 0 );
\r
274 vParTestSetLED( 6, 1 );
\r
277 if( strstr( c, "LED2=1" ) != NULL )
\r
279 vParTestSetLED( 7, 0 );
\r
283 vParTestSetLED( 7, 1 );
\r
286 /* Find the start of the text to be displayed on the LCD. */
\r
287 pcText = strstr( c, "LCD=" );
\r
288 pcText += strlen( "LCD=" );
\r
290 /* Terminate the file name for further processing within uIP. */
\r
293 /* Terminate the LCD string. */
\r
294 c = strstr( pcText, " " );
\r
300 /* Add required spaces. */
\r
301 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
306 /* Write the message to the LCD. */
\r
307 strcpy( cMessageForDisplay, pcText );
\r
308 xLCDMessage.xColumn = 0;
\r
309 xLCDMessage.pcMessage = cMessageForDisplay;
\r
310 xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );
\r