2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
53 /* Standard includes. */
\r
56 /* Scheduler includes. */
\r
57 #include "FreeRTOS.h"
\r
62 #include "hw_types.h"
\r
64 #include "uip_arp.h"
\r
67 #include "clock-arch.h"
\r
68 #include "hw_ethernet.h"
\r
69 #include "ethernet.h"
\r
70 #include "hw_memmap.h"
\r
71 #include "lmi_flash.h"
\r
74 /* Demo includes. */
\r
76 #include "partest.h"
\r
77 #include "lcd_message.h"
\r
81 clock_time_t interval;
\r
85 /*-----------------------------------------------------------*/
\r
87 /* IP address configuration. */
\r
88 #define uipIP_ADDR0 172
\r
89 #define uipIP_ADDR1 25
\r
90 #define uipIP_ADDR2 218
\r
91 #define uipIP_ADDR3 19
\r
93 /* How long to wait before attempting to connect the MAC again. */
\r
94 #define uipINIT_WAIT 100
\r
96 /* Shortcut to the header within the Rx buffer. */
\r
97 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
99 /* Standard constant. */
\r
100 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
102 /*-----------------------------------------------------------*/
\r
105 * Send the uIP buffer to the MAC.
\r
107 static void prvENET_Send(void);
\r
110 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
112 static void prvSetMACAddress( void );
\r
115 * Port functions required by the uIP stack.
\r
117 void clock_init( void );
\r
118 clock_time_t clock_time( void );
\r
120 /*-----------------------------------------------------------*/
\r
122 /* The semaphore used by the ISR to wake the uIP task. */
\r
123 extern xSemaphoreHandle xEMACSemaphore;
\r
125 /*-----------------------------------------------------------*/
\r
127 void clock_init(void)
\r
129 /* This is done when the scheduler starts. */
\r
131 /*-----------------------------------------------------------*/
\r
133 /* Define clock functions here to avoid header file name clash between uIP
\r
134 and the Luminary Micro driver library. */
\r
135 clock_time_t clock_time( void )
\r
137 return xTaskGetTickCount();
\r
139 extern void timer_set(struct timer *t, clock_time_t interval);
\r
140 extern int timer_expired(struct timer *t);
\r
141 extern void timer_reset(struct timer *t);
\r
146 void vuIP_Task( void *pvParameters )
\r
149 uip_ipaddr_t xIPAddr;
\r
150 struct timer periodic_timer, arp_timer;
\r
151 extern void ( vEMAC_ISR )( void );
\r
153 /* Enable/Reset the Ethernet Controller */
\r
154 SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
\r
155 SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
\r
157 /* Create the semaphore used by the ISR to wake this task. */
\r
158 vSemaphoreCreateBinary( xEMACSemaphore );
\r
160 /* Initialise the uIP stack. */
\r
161 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
162 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
164 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
165 uip_sethostaddr( xIPAddr );
\r
168 while( vInitEMAC() != pdPASS )
\r
170 vTaskDelay( uipINIT_WAIT );
\r
172 prvSetMACAddress();
\r
177 /* Is there received data ready to be processed? */
\r
178 uip_len = uiGetEMACRxData( uip_buf );
\r
182 /* Standard uIP loop taken from the uIP manual. */
\r
184 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
189 /* If the above function invocation resulted in data that
\r
190 should be sent out on the network, the global variable
\r
191 uip_len is set to a value > 0. */
\r
198 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
202 /* If the above function invocation resulted in data that
\r
203 should be sent out on the network, the global variable
\r
204 uip_len is set to a value > 0. */
\r
213 if( timer_expired( &periodic_timer ) )
\r
215 timer_reset( &periodic_timer );
\r
216 for( i = 0; i < UIP_CONNS; i++ )
\r
220 /* If the above function invocation resulted in data that
\r
221 should be sent out on the network, the global variable
\r
222 uip_len is set to a value > 0. */
\r
230 /* Call the ARP timer function every 10 seconds. */
\r
231 if( timer_expired( &arp_timer ) )
\r
233 timer_reset( &arp_timer );
\r
239 /* We did not receive a packet, and there was no periodic
\r
240 processing to perform. Block for a fixed period. If a packet
\r
241 is received during this period we will be woken by the ISR
\r
242 giving us the Semaphore. */
\r
243 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
248 /*-----------------------------------------------------------*/
\r
250 static void prvENET_Send(void)
\r
253 vIncrementTxLength( uip_len );
\r
254 vSendBufferToMAC();
\r
256 /*-----------------------------------------------------------*/
\r
258 static void prvSetMACAddress( void )
\r
260 unsigned portLONG ulUser0, ulUser1;
\r
261 unsigned char pucMACArray[8];
\r
262 struct uip_eth_addr xAddr;
\r
264 /* Get the device MAC address from flash */
\r
265 FlashUserGet(&ulUser0, &ulUser1);
\r
267 /* Convert the MAC address from flash into sequence of bytes. */
\r
268 pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
\r
269 pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
\r
270 pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
\r
271 pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
\r
272 pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
\r
273 pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
\r
275 /* Program the MAC address. */
\r
276 EthernetMACAddrSet(ETH_BASE, pucMACArray);
\r
278 xAddr.addr[ 0 ] = pucMACArray[0];
\r
279 xAddr.addr[ 1 ] = pucMACArray[1];
\r
280 xAddr.addr[ 2 ] = pucMACArray[2];
\r
281 xAddr.addr[ 3 ] = pucMACArray[3];
\r
282 xAddr.addr[ 4 ] = pucMACArray[4];
\r
283 xAddr.addr[ 5 ] = pucMACArray[5];
\r
284 uip_setethaddr( xAddr );
\r
286 /*-----------------------------------------------------------*/
\r
288 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
291 static portCHAR cMessageForDisplay[ 32 ];
\r
292 extern xQueueHandle xOLEDQueue;
\r
293 xOLEDMessage xOLEDMessage;
\r
295 /* Process the form input sent by the IO page of the served HTML. */
\r
297 c = strstr( pcInputString, "?" );
\r
301 /* Turn LED's on or off in accordance with the check box status. */
\r
302 if( strstr( c, "LED0=1" ) != NULL )
\r
304 vParTestSetLED( 0, 1 );
\r
308 vParTestSetLED( 0, 0 );
\r
311 /* Find the start of the text to be displayed on the LCD. */
\r
312 pcText = strstr( c, "LCD=" );
\r
313 pcText += strlen( "LCD=" );
\r
315 /* Terminate the file name for further processing within uIP. */
\r
318 /* Terminate the LCD string. */
\r
319 c = strstr( pcText, " " );
\r
325 /* Add required spaces. */
\r
326 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
331 /* Write the message to the LCD. */
\r
332 strcpy( cMessageForDisplay, pcText );
\r
333 xOLEDMessage.pcMessage = ( signed portCHAR * ) cMessageForDisplay;
\r
334 xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
\r