2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
64 /* Standard includes. */
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
73 #include "hw_types.h"
\r
75 #include "uip_arp.h"
\r
78 #include "clock-arch.h"
\r
79 #include "hw_ethernet.h"
\r
80 #include "ethernet.h"
\r
81 #include "hw_memmap.h"
\r
82 #include "lmi_flash.h"
\r
85 /* Demo includes. */
\r
87 #include "partest.h"
\r
88 #include "lcd_message.h"
\r
92 clock_time_t interval;
\r
96 /*-----------------------------------------------------------*/
\r
98 /* IP address configuration. */
\r
99 #define uipIP_ADDR0 172
\r
100 #define uipIP_ADDR1 25
\r
101 #define uipIP_ADDR2 218
\r
102 #define uipIP_ADDR3 19
\r
104 /* How long to wait before attempting to connect the MAC again. */
\r
105 #define uipINIT_WAIT 100
\r
107 /* Shortcut to the header within the Rx buffer. */
\r
108 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
110 /* Standard constant. */
\r
111 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
113 /*-----------------------------------------------------------*/
\r
116 * Send the uIP buffer to the MAC.
\r
118 static void prvENET_Send(void);
\r
121 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
123 static void prvSetMACAddress( void );
\r
126 * Port functions required by the uIP stack.
\r
128 void clock_init( void );
\r
129 clock_time_t clock_time( void );
\r
131 /*-----------------------------------------------------------*/
\r
133 /* The semaphore used by the ISR to wake the uIP task. */
\r
134 extern xSemaphoreHandle xEMACSemaphore;
\r
136 /*-----------------------------------------------------------*/
\r
138 void clock_init(void)
\r
140 /* This is done when the scheduler starts. */
\r
142 /*-----------------------------------------------------------*/
\r
144 /* Define clock functions here to avoid header file name clash between uIP
\r
145 and the Luminary Micro driver library. */
\r
146 clock_time_t clock_time( void )
\r
148 return xTaskGetTickCount();
\r
150 extern void timer_set(struct timer *t, clock_time_t interval);
\r
151 extern int timer_expired(struct timer *t);
\r
152 extern void timer_reset(struct timer *t);
\r
157 void vuIP_Task( void *pvParameters )
\r
160 uip_ipaddr_t xIPAddr;
\r
161 struct timer periodic_timer, arp_timer;
\r
162 extern void ( vEMAC_ISR )( void );
\r
164 /* Enable/Reset the Ethernet Controller */
\r
165 SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
\r
166 SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
\r
168 /* Create the semaphore used by the ISR to wake this task. */
\r
169 vSemaphoreCreateBinary( xEMACSemaphore );
\r
171 /* Initialise the uIP stack. */
\r
172 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
173 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
175 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
176 uip_sethostaddr( xIPAddr );
\r
179 while( vInitEMAC() != pdPASS )
\r
181 vTaskDelay( uipINIT_WAIT );
\r
183 prvSetMACAddress();
\r
188 /* Is there received data ready to be processed? */
\r
189 uip_len = uiGetEMACRxData( uip_buf );
\r
193 /* Standard uIP loop taken from the uIP manual. */
\r
195 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
200 /* If the above function invocation resulted in data that
\r
201 should be sent out on the network, the global variable
\r
202 uip_len is set to a value > 0. */
\r
209 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
213 /* If the above function invocation resulted in data that
\r
214 should be sent out on the network, the global variable
\r
215 uip_len is set to a value > 0. */
\r
224 if( timer_expired( &periodic_timer ) )
\r
226 timer_reset( &periodic_timer );
\r
227 for( i = 0; i < UIP_CONNS; i++ )
\r
231 /* If the above function invocation resulted in data that
\r
232 should be sent out on the network, the global variable
\r
233 uip_len is set to a value > 0. */
\r
241 /* Call the ARP timer function every 10 seconds. */
\r
242 if( timer_expired( &arp_timer ) )
\r
244 timer_reset( &arp_timer );
\r
250 /* We did not receive a packet, and there was no periodic
\r
251 processing to perform. Block for a fixed period. If a packet
\r
252 is received during this period we will be woken by the ISR
\r
253 giving us the Semaphore. */
\r
254 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
259 /*-----------------------------------------------------------*/
\r
261 static void prvENET_Send(void)
\r
264 vIncrementTxLength( uip_len );
\r
265 vSendBufferToMAC();
\r
267 /*-----------------------------------------------------------*/
\r
269 static void prvSetMACAddress( void )
\r
271 unsigned portLONG ulUser0, ulUser1;
\r
272 unsigned char pucMACArray[8];
\r
273 struct uip_eth_addr xAddr;
\r
275 /* Get the device MAC address from flash */
\r
276 FlashUserGet(&ulUser0, &ulUser1);
\r
278 /* Convert the MAC address from flash into sequence of bytes. */
\r
279 pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
\r
280 pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
\r
281 pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
\r
282 pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
\r
283 pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
\r
284 pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
\r
286 /* Program the MAC address. */
\r
287 EthernetMACAddrSet(ETH_BASE, pucMACArray);
\r
289 xAddr.addr[ 0 ] = pucMACArray[0];
\r
290 xAddr.addr[ 1 ] = pucMACArray[1];
\r
291 xAddr.addr[ 2 ] = pucMACArray[2];
\r
292 xAddr.addr[ 3 ] = pucMACArray[3];
\r
293 xAddr.addr[ 4 ] = pucMACArray[4];
\r
294 xAddr.addr[ 5 ] = pucMACArray[5];
\r
295 uip_setethaddr( xAddr );
\r
297 /*-----------------------------------------------------------*/
\r
299 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
302 static portCHAR cMessageForDisplay[ 32 ];
\r
303 extern xQueueHandle xOLEDQueue;
\r
304 xOLEDMessage xOLEDMessage;
\r
306 /* Process the form input sent by the IO page of the served HTML. */
\r
308 c = strstr( pcInputString, "?" );
\r
312 /* Turn LED's on or off in accordance with the check box status. */
\r
313 if( strstr( c, "LED0=1" ) != NULL )
\r
315 vParTestSetLED( 0, 1 );
\r
319 vParTestSetLED( 0, 0 );
\r
322 /* Find the start of the text to be displayed on the LCD. */
\r
323 pcText = strstr( c, "LCD=" );
\r
324 pcText += strlen( "LCD=" );
\r
326 /* Terminate the file name for further processing within uIP. */
\r
329 /* Terminate the LCD string. */
\r
330 c = strstr( pcText, " " );
\r
336 /* Add required spaces. */
\r
337 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
342 /* Write the message to the LCD. */
\r
343 strcpy( cMessageForDisplay, pcText );
\r
344 xOLEDMessage.pcMessage = ( signed portCHAR * ) cMessageForDisplay;
\r
345 xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
\r