2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\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 modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or 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
61 #include "lcd_message.h"
\r
64 #include "hw_types.h"
\r
67 #include "uip_arp.h"
\r
70 #include "clock-arch.h"
\r
71 #include "hw_ethernet.h"
\r
72 #include "ethernet.h"
\r
73 #include "hw_memmap.h"
\r
74 #include "lmi_flash.h"
\r
77 /* Demo includes. */
\r
79 #include "partest.h"
\r
81 /*-----------------------------------------------------------*/
\r
83 /* IP address configuration. */
\r
84 #define uipIP_ADDR0 192
\r
85 #define uipIP_ADDR1 168
\r
86 #define uipIP_ADDR2 0
\r
87 #define uipIP_ADDR3 201
\r
89 /* Netmask configuration. */
\r
90 #define uipNETMASK_0 255
\r
91 #define uipNETMASK_1 255
\r
92 #define uipNETMASK_2 255
\r
93 #define uipNETMASK_3 0
\r
95 /* How long to wait before attempting to connect the MAC again. */
\r
96 #define uipINIT_WAIT 100
\r
98 /* Shortcut to the header within the Rx buffer. */
\r
99 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
101 /* Standard constant. */
\r
102 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
104 /*-----------------------------------------------------------*/
\r
107 * Send the uIP buffer to the MAC.
\r
109 static void prvENET_Send(void);
\r
112 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
114 static void prvSetMACAddress( void );
\r
117 * Port functions required by the uIP stack.
\r
119 void clock_init( void );
\r
120 clock_time_t clock_time( void );
\r
122 /*-----------------------------------------------------------*/
\r
124 /* The semaphore used by the ISR to wake the uIP task. */
\r
125 extern xSemaphoreHandle xEMACSemaphore;
\r
127 /*-----------------------------------------------------------*/
\r
129 void clock_init(void)
\r
131 /* This is done when the scheduler starts. */
\r
133 /*-----------------------------------------------------------*/
\r
135 clock_time_t clock_time( void )
\r
137 return xTaskGetTickCount();
\r
141 void vuIP_Task( void *pvParameters )
\r
144 uip_ipaddr_t xIPAddr;
\r
145 struct timer periodic_timer, arp_timer;
\r
146 extern void ( vEMAC_ISR )( void );
\r
148 /* Enable/Reset the Ethernet Controller */
\r
149 SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
\r
150 SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
\r
152 /* Create the semaphore used by the ISR to wake this task. */
\r
153 vSemaphoreCreateBinary( xEMACSemaphore );
\r
155 /* Initialise the uIP stack. */
\r
156 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
157 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
159 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
160 uip_sethostaddr( xIPAddr );
\r
161 uip_ipaddr( xIPAddr, uipNETMASK_0, uipNETMASK_1, uipNETMASK_2, uipNETMASK_3 );
\r
162 uip_setnetmask( xIPAddr );
\r
165 while( vInitEMAC() != pdPASS )
\r
167 vTaskDelay( uipINIT_WAIT );
\r
169 prvSetMACAddress();
\r
174 /* Is there received data ready to be processed? */
\r
175 uip_len = uiGetEMACRxData( uip_buf );
\r
179 /* Standard uIP loop taken from the uIP manual. */
\r
181 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\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
195 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
199 /* If the above function invocation resulted in data that
\r
200 should be sent out on the network, the global variable
\r
201 uip_len is set to a value > 0. */
\r
210 if( timer_expired( &periodic_timer ) )
\r
212 timer_reset( &periodic_timer );
\r
213 for( i = 0; i < UIP_CONNS; i++ )
\r
217 /* If the above function invocation resulted in data that
\r
218 should be sent out on the network, the global variable
\r
219 uip_len is set to a value > 0. */
\r
227 /* Call the ARP timer function every 10 seconds. */
\r
228 if( timer_expired( &arp_timer ) )
\r
230 timer_reset( &arp_timer );
\r
236 /* We did not receive a packet, and there was no periodic
\r
237 processing to perform. Block for a fixed period. If a packet
\r
238 is received during this period we will be woken by the ISR
\r
239 giving us the Semaphore. */
\r
240 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
245 /*-----------------------------------------------------------*/
\r
247 static void prvENET_Send(void)
\r
250 vIncrementTxLength( uip_len );
\r
251 vSendBufferToMAC();
\r
253 vIncrementTxLength( uip_len );
\r
254 vSendBufferToMAC();
\r
256 /*-----------------------------------------------------------*/
\r
258 static void prvSetMACAddress( void )
\r
260 unsigned long 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( char *pcInputString, portBASE_TYPE xInputLength )
\r
291 static char 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 = cMessageForDisplay;
\r
334 xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
\r