2 FreeRTOS V7.0.2 - 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
54 /* Standard includes. */
\r
57 /* FreeRTOS includes. */
\r
58 #include "FreeRTOS.h"
\r
62 /* lwIP core includes */
\r
63 #include "lwip/opt.h"
\r
64 #include "lwip/tcpip.h"
\r
66 /* applications includes */
\r
67 #include "apps/httpserver_raw_from_lwIP_download/httpd.h"
\r
69 /* include the port-dependent configuration */
\r
70 #include "lwipcfg_msvc.h"
\r
72 /* Dimensions the cTxBuffer array - which is itself used to hold replies from
\r
73 command line commands. cTxBuffer is a shared buffer, so protected by the
\r
74 xTxBufferMutex mutex. */
\r
75 #define lwipappsTX_BUFFER_SIZE 1024
\r
77 /* The maximum time to block waiting to obtain the xTxBufferMutex to become
\r
79 #define lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ( 100 / portTICK_RATE_MS )
\r
81 /* Definitions of the various SSI callback functions within the pccSSITags
\r
82 array. If pccSSITags is updated, then these definitions must also be updated. */
\r
83 #define ssiTASK_STATS_INDEX 0
\r
84 #define ssiRUN_TIME_STATS_INDEX 1
\r
86 /*-----------------------------------------------------------*/
\r
89 * The function that implements the lwIP based sockets command interpreter
\r
92 extern void vBasicSocketsCommandInterpreterTask( void *pvParameters );
\r
95 * The SSI handler callback function passed to lwIP.
\r
97 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );
\r
99 /*-----------------------------------------------------------*/
\r
101 /* The SSI strings that are embedded in the served html files. If this array
\r
102 is changed, then the index position defined by the #defines such as
\r
103 ssiTASK_STATS_INDEX above must also be updated. */
\r
104 static const char *pccSSITags[] =
\r
110 /* Semaphore used to guard the Tx buffer. */
\r
111 static xSemaphoreHandle xTxBufferMutex = NULL;
\r
113 /* The Tx buffer itself. This is used to hold the text generated by the
\r
114 execution of command line commands, and (hopefully) the execution of
\r
115 server side include callbacks. It is a shared buffer so protected by the
\r
116 xTxBufferMutex mutex. pcLwipAppsBlockingGetTxBuffer() and
\r
117 vLwipAppsReleaseTxBuffer() are provided to obtain and release the
\r
118 xTxBufferMutex respectively. pcLwipAppsBlockingGetTxBuffer() must be used with
\r
119 caution as it has the potential to block. */
\r
120 static signed char cTxBuffer[ lwipappsTX_BUFFER_SIZE ];
\r
122 /*-----------------------------------------------------------*/
\r
125 /* Called from the TCP/IP thread. */
\r
126 void lwIPAppsInit( void *pvArgument )
\r
128 ip_addr_t xIPAddr, xNetMask, xGateway;
\r
129 extern err_t xemacpsif_init( struct netif *netif );
\r
130 extern void xemacif_input_thread( struct netif *netif );
\r
131 static struct netif xNetIf;
\r
133 ( void ) pvArgument;
\r
135 /* Set up the network interface. */
\r
136 ip_addr_set_zero( &xGateway );
\r
137 ip_addr_set_zero( &xIPAddr );
\r
138 ip_addr_set_zero( &xNetMask );
\r
140 LWIP_PORT_INIT_GW(&xGateway);
\r
141 LWIP_PORT_INIT_IPADDR( &xIPAddr );
\r
142 LWIP_PORT_INIT_NETMASK(&xNetMask);
\r
144 /* Set mac address */
\r
145 xNetIf.hwaddr_len = 6;
\r
146 xNetIf.hwaddr[ 0 ] = configMAC_ADDR0;
\r
147 xNetIf.hwaddr[ 1 ] = configMAC_ADDR1;
\r
148 xNetIf.hwaddr[ 2 ] = configMAC_ADDR2;
\r
149 xNetIf.hwaddr[ 3 ] = configMAC_ADDR3;
\r
150 xNetIf.hwaddr[ 4 ] = configMAC_ADDR4;
\r
151 xNetIf.hwaddr[ 5 ] = configMAC_ADDR5;
\r
153 netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, XPAR_XEMACPS_0_BASEADDR, xemacpsif_init, tcpip_input ) );
\r
154 netif_set_up( &xNetIf );
\r
156 /* Install the server side include handler. */
\r
157 http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );
\r
159 /* Create the mutex used to ensure mutual exclusive access to the Tx
\r
161 xTxBufferMutex = xSemaphoreCreateMutex();
\r
162 configASSERT( xTxBufferMutex );
\r
164 /* Create the httpd server from the standard lwIP code. This demonstrates
\r
165 use of the lwIP raw API. */
\r
168 sys_thread_new( "lwIP Input", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE, configMAC_INPUT_TASK_PRIORITY );
\r
170 /* Create the FreeRTOS defined basic command server. This demonstrates use
\r
171 of the lwIP sockets API. */
\r
172 #warning Commented out CLI
\r
173 // xTaskCreate( vBasicSocketsCommandInterpreterTask, "CmdInt", configMINIMAL_STACK_SIZE * 10, NULL, configMAX_PRIORITIES - 2, NULL );
\r
175 /*-----------------------------------------------------------*/
\r
177 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )
\r
179 static unsigned int uiUpdateCount = 0;
\r
180 static char cUpdateString[ 200 ];
\r
181 extern char *pcMainGetTaskStatusMessage( void );
\r
183 /* Unused parameter. */
\r
184 ( void ) iBufferLength;
\r
186 /* The SSI handler function that generates text depending on the index of
\r
187 the SSI tag encountered. */
\r
191 case ssiTASK_STATS_INDEX :
\r
192 vTaskList( pcBuffer );
\r
195 case ssiRUN_TIME_STATS_INDEX :
\r
196 vTaskGetRunTimeStats( pcBuffer );
\r
200 /* Include a count of the number of times an SSI function has been executed
\r
201 in the returned string. */
\r
203 sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );
\r
204 strcat( pcBuffer, cUpdateString );
\r
206 return strlen( pcBuffer );
\r
208 /*-----------------------------------------------------------*/
\r
210 signed char *pcLwipAppsBlockingGetTxBuffer( void )
\r
212 signed char *pcReturn;
\r
214 /* Attempt to obtain the semaphore that guards the Tx buffer. */
\r
215 if( xSemaphoreTakeRecursive( xTxBufferMutex, lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ) == pdFAIL )
\r
217 /* The semaphore could not be obtained before timing out. */
\r
222 /* The semaphore was obtained successfully. Return a pointer to the
\r
224 pcReturn = cTxBuffer;
\r
229 /*-----------------------------------------------------------*/
\r
231 void vLwipAppsReleaseTxBuffer( void )
\r
233 /* Finished with the Tx buffer. Return the mutex. */
\r
234 xSemaphoreGiveRecursive( xTxBufferMutex );
\r