2 FreeRTOS V5.4.2 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
47 /* Standard includes. */
\r
50 /* Scheduler includes. */
\r
51 #include "FreeRTOS.h"
\r
55 #include "lcd_message.h"
\r
58 #include "hw_types.h"
\r
61 #include "uip_arp.h"
\r
64 #include "clock-arch.h"
\r
65 #include "hw_ethernet.h"
\r
66 #include "ethernet.h"
\r
67 #include "hw_memmap.h"
\r
68 #include "lmi_flash.h"
\r
71 /* Demo includes. */
\r
73 #include "partest.h"
\r
75 /*-----------------------------------------------------------*/
\r
77 /* IP address configuration. */
\r
78 #define uipIP_ADDR0 192
\r
79 #define uipIP_ADDR1 168
\r
80 #define uipIP_ADDR2 0
\r
81 #define uipIP_ADDR3 201
\r
83 /* Netmask configuration. */
\r
84 #define uipNETMASK_0 255
\r
85 #define uipNETMASK_1 255
\r
86 #define uipNETMASK_2 255
\r
87 #define uipNETMASK_3 0
\r
89 /* How long to wait before attempting to connect the MAC again. */
\r
90 #define uipINIT_WAIT 100
\r
92 /* Shortcut to the header within the Rx buffer. */
\r
93 #define xHeader ((struct uip_eth_hdr *) &uip_buf[ 0 ])
\r
95 /* Standard constant. */
\r
96 #define uipTOTAL_FRAME_HEADER_SIZE 54
\r
98 /*-----------------------------------------------------------*/
\r
101 * Send the uIP buffer to the MAC.
\r
103 static void prvENET_Send(void);
\r
106 * Setup the MAC address in the MAC itself, and in the uIP stack.
\r
108 static void prvSetMACAddress( void );
\r
111 * Port functions required by the uIP stack.
\r
113 void clock_init( void );
\r
114 clock_time_t clock_time( void );
\r
116 /*-----------------------------------------------------------*/
\r
118 /* The semaphore used by the ISR to wake the uIP task. */
\r
119 extern xSemaphoreHandle xEMACSemaphore;
\r
121 /*-----------------------------------------------------------*/
\r
123 void clock_init(void)
\r
125 /* This is done when the scheduler starts. */
\r
127 /*-----------------------------------------------------------*/
\r
129 clock_time_t clock_time( void )
\r
131 return xTaskGetTickCount();
\r
135 void vuIP_Task( void *pvParameters )
\r
138 uip_ipaddr_t xIPAddr;
\r
139 struct timer periodic_timer, arp_timer;
\r
140 extern void ( vEMAC_ISR )( void );
\r
142 /* Enable/Reset the Ethernet Controller */
\r
143 SysCtlPeripheralEnable( SYSCTL_PERIPH_ETH );
\r
144 SysCtlPeripheralReset( SYSCTL_PERIPH_ETH );
\r
146 /* Create the semaphore used by the ISR to wake this task. */
\r
147 vSemaphoreCreateBinary( xEMACSemaphore );
\r
149 /* Initialise the uIP stack. */
\r
150 timer_set( &periodic_timer, configTICK_RATE_HZ / 2 );
\r
151 timer_set( &arp_timer, configTICK_RATE_HZ * 10 );
\r
153 uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
\r
154 uip_sethostaddr( xIPAddr );
\r
155 uip_ipaddr( xIPAddr, uipNETMASK_0, uipNETMASK_1, uipNETMASK_2, uipNETMASK_3 );
\r
156 uip_setnetmask( xIPAddr );
\r
159 while( vInitEMAC() != pdPASS )
\r
161 vTaskDelay( uipINIT_WAIT );
\r
163 prvSetMACAddress();
\r
168 /* Is there received data ready to be processed? */
\r
169 uip_len = uiGetEMACRxData( uip_buf );
\r
173 /* Standard uIP loop taken from the uIP manual. */
\r
175 if( xHeader->type == htons( UIP_ETHTYPE_IP ) )
\r
180 /* If the above function invocation resulted in data that
\r
181 should be sent out on the network, the global variable
\r
182 uip_len is set to a value > 0. */
\r
189 else if( xHeader->type == htons( UIP_ETHTYPE_ARP ) )
\r
193 /* If the above function invocation resulted in data that
\r
194 should be sent out on the network, the global variable
\r
195 uip_len is set to a value > 0. */
\r
204 if( timer_expired( &periodic_timer ) )
\r
206 timer_reset( &periodic_timer );
\r
207 for( i = 0; i < UIP_CONNS; i++ )
\r
211 /* If the above function invocation resulted in data that
\r
212 should be sent out on the network, the global variable
\r
213 uip_len is set to a value > 0. */
\r
221 /* Call the ARP timer function every 10 seconds. */
\r
222 if( timer_expired( &arp_timer ) )
\r
224 timer_reset( &arp_timer );
\r
230 /* We did not receive a packet, and there was no periodic
\r
231 processing to perform. Block for a fixed period. If a packet
\r
232 is received during this period we will be woken by the ISR
\r
233 giving us the Semaphore. */
\r
234 xSemaphoreTake( xEMACSemaphore, configTICK_RATE_HZ / 2 );
\r
239 /*-----------------------------------------------------------*/
\r
241 static void prvENET_Send(void)
\r
244 vIncrementTxLength( uip_len );
\r
245 vSendBufferToMAC();
\r
247 vIncrementTxLength( uip_len );
\r
248 vSendBufferToMAC();
\r
250 /*-----------------------------------------------------------*/
\r
252 static void prvSetMACAddress( void )
\r
254 unsigned portLONG ulUser0, ulUser1;
\r
255 unsigned char pucMACArray[8];
\r
256 struct uip_eth_addr xAddr;
\r
258 /* Get the device MAC address from flash */
\r
259 FlashUserGet(&ulUser0, &ulUser1);
\r
261 /* Convert the MAC address from flash into sequence of bytes. */
\r
262 pucMACArray[0] = ((ulUser0 >> 0) & 0xff);
\r
263 pucMACArray[1] = ((ulUser0 >> 8) & 0xff);
\r
264 pucMACArray[2] = ((ulUser0 >> 16) & 0xff);
\r
265 pucMACArray[3] = ((ulUser1 >> 0) & 0xff);
\r
266 pucMACArray[4] = ((ulUser1 >> 8) & 0xff);
\r
267 pucMACArray[5] = ((ulUser1 >> 16) & 0xff);
\r
269 /* Program the MAC address. */
\r
270 EthernetMACAddrSet(ETH_BASE, pucMACArray);
\r
272 xAddr.addr[ 0 ] = pucMACArray[0];
\r
273 xAddr.addr[ 1 ] = pucMACArray[1];
\r
274 xAddr.addr[ 2 ] = pucMACArray[2];
\r
275 xAddr.addr[ 3 ] = pucMACArray[3];
\r
276 xAddr.addr[ 4 ] = pucMACArray[4];
\r
277 xAddr.addr[ 5 ] = pucMACArray[5];
\r
278 uip_setethaddr( xAddr );
\r
280 /*-----------------------------------------------------------*/
\r
282 void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )
\r
285 static portCHAR cMessageForDisplay[ 32 ];
\r
286 extern xQueueHandle xOLEDQueue;
\r
287 xOLEDMessage xOLEDMessage;
\r
289 /* Process the form input sent by the IO page of the served HTML. */
\r
291 c = strstr( pcInputString, "?" );
\r
295 /* Turn LED's on or off in accordance with the check box status. */
\r
296 if( strstr( c, "LED0=1" ) != NULL )
\r
298 vParTestSetLED( 0, 1 );
\r
302 vParTestSetLED( 0, 0 );
\r
305 /* Find the start of the text to be displayed on the LCD. */
\r
306 pcText = strstr( c, "LCD=" );
\r
307 pcText += strlen( "LCD=" );
\r
309 /* Terminate the file name for further processing within uIP. */
\r
312 /* Terminate the LCD string. */
\r
313 c = strstr( pcText, " " );
\r
319 /* Add required spaces. */
\r
320 while( ( c = strstr( pcText, "+" ) ) != NULL )
\r
325 /* Write the message to the LCD. */
\r
326 strcpy( cMessageForDisplay, pcText );
\r
327 xOLEDMessage.pcMessage = cMessageForDisplay;
\r
328 xQueueSend( xOLEDQueue, &xOLEDMessage, portMAX_DELAY );
\r