2 FreeRTOS.org V4.8.0 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
30 ***************************************************************************
\r
32 /* Standard includes. */
\r
35 /* Scheduler includes. */
\r
36 #include "FreeRTOS.h"
\r
40 #include "lcd_message.h"
\r
43 #include "hw_types.h"
\r
46 #include "uip_arp.h"
\r
49 #include "clock-arch.h"
\r
50 #include "hw_ethernet.h"
\r
51 #include "ethernet.h"
\r
52 #include "hw_memmap.h"
\r
53 #include "lmi_flash.h"
\r
56 /* Demo includes. */
\r
58 #include "partest.h"
\r
60 /*-----------------------------------------------------------*/
\r
62 /* IP address configuration. */
\r
63 #define uipIP_ADDR0 172
\r
64 #define uipIP_ADDR1 25
\r
65 #define uipIP_ADDR2 218
\r
66 #define uipIP_ADDR3 19
\r
68 /* How long to wait before attempting to connect the MAC again. */
\r
69 #define uipINIT_WAIT 100
\r
71 /* Shortcut to the header within the Rx buffer. */
\r
72 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
74 /* Standard constant. */
\r
75 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
77 /*-----------------------------------------------------------*/
\r
80 * Send the uIP buffer to the MAC.
\r
82 static void prvENET_Send(void);
\r
85 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
87 static void prvSetMACAddress( void );
\r
90 * Port functions required by the uIP stack.
\r
92 void clock_init( void );
\r
93 clock_time_t clock_time( void );
\r
95 /*-----------------------------------------------------------*/
\r
97 /* The semaphore used by the ISR to wake the uIP task. */
\r
98 extern xSemaphoreHandle xEMACSemaphore;
\r
100 /*-----------------------------------------------------------*/
\r
102 void clock_init(void)
\r
104 /* This is done when the scheduler starts. */
\r
106 /*-----------------------------------------------------------*/
\r
108 clock_time_t clock_time( void )
\r
110 return xTaskGetTickCount();
\r
114 void vuIP_Task( void *pvParameters )
\r
117 uip_ipaddr_t xIPAddr;
\r
118 struct timer periodic_timer, arp_timer;
\r
119 extern void ( vEMAC_ISR )( void );
\r
121 /* Enable/Reset the Ethernet Controller */
\r
122 SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
\r
123 SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
\r
125 /* Create the semaphore used by the ISR to wake this task. */
\r
126 vSemaphoreCreateBinary( xEMACSemaphore );
\r
128 /* Initialise the uIP stack. */
\r
129 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
130 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
132 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
133 uip_sethostaddr( xIPAddr );
\r
136 while( vInitEMAC() != pdPASS )
\r
138 vTaskDelay( uipINIT_WAIT );
\r
140 prvSetMACAddress();
\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
152 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
157 /* If the above function invocation resulted in data that
\r
158 should be sent out on the network, the global variable
\r
159 uip_len is set to a value > 0. */
\r
166 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
170 /* If the above function invocation resulted in data that
\r
171 should be sent out on the network, the global variable
\r
172 uip_len is set to a value > 0. */
\r
181 if( timer_expired( &periodic_timer ) )
\r
183 timer_reset( &periodic_timer );
\r
184 for( i = 0; i < UIP_CONNS; i++ )
\r
188 /* If the above function invocation resulted in data that
\r
189 should be sent out on the network, the global variable
\r
190 uip_len is set to a value > 0. */
\r
198 /* Call the ARP timer function every 10 seconds. */
\r
199 if( timer_expired( &arp_timer ) )
\r
201 timer_reset( &arp_timer );
\r
207 /* We did not receive a packet, and there was no periodic
\r
208 processing to perform. Block for a fixed period. If a packet
\r
209 is received during this period we will be woken by the ISR
\r
210 giving us the Semaphore. */
\r
211 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
216 /*-----------------------------------------------------------*/
\r
218 static void prvENET_Send(void)
\r
221 vIncrementTxLength( uip_len );
\r
222 vSendBufferToMAC();
\r
224 /*-----------------------------------------------------------*/
\r
226 static void prvSetMACAddress( void )
\r
228 unsigned portLONG ulUser0, ulUser1;
\r
229 unsigned char pucMACArray[8];
\r
230 struct uip_eth_addr xAddr;
\r
232 /* Get the device MAC address from flash */
\r
233 FlashUserGet(&ulUser0, &ulUser1);
\r
235 /* Convert the MAC address from flash into sequence of bytes. */
\r
236 pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
\r
237 pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
\r
238 pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
\r
239 pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
\r
240 pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
\r
241 pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
\r
243 /* Program the MAC address. */
\r
244 EthernetMACAddrSet(ETH_BASE, pucMACArray);
\r
246 xAddr.addr[ 0 ] = pucMACArray[0];
\r
247 xAddr.addr[ 1 ] = pucMACArray[1];
\r
248 xAddr.addr[ 2 ] = pucMACArray[2];
\r
249 xAddr.addr[ 3 ] = pucMACArray[3];
\r
250 xAddr.addr[ 4 ] = pucMACArray[4];
\r
251 xAddr.addr[ 5 ] = pucMACArray[5];
\r
252 uip_setethaddr( xAddr );
\r
254 /*-----------------------------------------------------------*/
\r
256 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
259 static portCHAR cMessageForDisplay[ 32 ];
\r
260 extern xQueueHandle xOLEDQueue;
\r
261 xOLEDMessage xOLEDMessage;
\r
263 /* Process the form input sent by the IO page of the served HTML. */
\r
265 c = strstr( pcInputString, "?" );
\r
269 /* Turn LED's on or off in accordance with the check box status. */
\r
270 if( strstr( c, "LED0=1" ) != NULL )
\r
272 vParTestSetLED( 0, 1 );
\r
276 vParTestSetLED( 0, 0 );
\r
279 /* Find the start of the text to be displayed on the LCD. */
\r
280 pcText = strstr( c, "LCD=" );
\r
281 pcText += strlen( "LCD=" );
\r
283 /* Terminate the file name for further processing within uIP. */
\r
286 /* Terminate the LCD string. */
\r
287 c = strstr( pcText, " " );
\r
293 /* Add required spaces. */
\r
294 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
299 /* Write the message to the LCD. */
\r
300 strcpy( cMessageForDisplay, pcText );
\r
301 xOLEDMessage.pcMessage = cMessageForDisplay;
\r
302 xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
\r