2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
75 #include "FreeRTOS.h"
\r
79 /* lwIP core includes */
\r
80 #include "lwip/opt.h"
\r
81 #include "lwip/tcpip.h"
\r
83 /* applications includes */
\r
84 #include "apps/httpserver_raw_from_lwIP_download/httpd.h"
\r
86 /* include the port-dependent configuration */
\r
87 #include "lwipcfg_msvc.h"
\r
89 /* Dimensions the cTxBuffer array - which is itself used to hold replies from
\r
90 command line commands. cTxBuffer is a shared buffer, so protected by the
\r
91 xTxBufferMutex mutex. */
\r
92 #define lwipappsTX_BUFFER_SIZE 1024
\r
94 /* The maximum time to block waiting to obtain the xTxBufferMutex to become
\r
96 #define lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ( 100 / portTICK_RATE_MS )
\r
98 /* Definitions of the various SSI callback functions within the pccSSITags
\r
99 array. If pccSSITags is updated, then these definitions must also be updated. */
\r
100 #define ssiTASK_STATS_INDEX 0
\r
101 #define ssiRUN_TIME_STATS_INDEX 1
\r
103 /*-----------------------------------------------------------*/
\r
106 * The function that implements the lwIP based sockets command interpreter
\r
109 extern void vBasicSocketsCommandInterpreterTask( void *pvParameters );
\r
112 * The SSI handler callback function passed to lwIP.
\r
114 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );
\r
116 /*-----------------------------------------------------------*/
\r
118 /* The SSI strings that are embedded in the served html files. If this array
\r
119 is changed, then the index position defined by the #defines such as
\r
120 ssiTASK_STATS_INDEX above must also be updated. */
\r
121 static const char *pccSSITags[] =
\r
127 /* Semaphore used to guard the Tx buffer. */
\r
128 static xSemaphoreHandle xTxBufferMutex = NULL;
\r
130 /* The Tx buffer itself. This is used to hold the text generated by the
\r
131 execution of command line commands, and (hopefully) the execution of
\r
132 server side include callbacks. It is a shared buffer so protected by the
\r
133 xTxBufferMutex mutex. pcLwipAppsBlockingGetTxBuffer() and
\r
134 vLwipAppsReleaseTxBuffer() are provided to obtain and release the
\r
135 xTxBufferMutex respectively. pcLwipAppsBlockingGetTxBuffer() must be used with
\r
136 caution as it has the potential to block. */
\r
137 static signed char cTxBuffer[ lwipappsTX_BUFFER_SIZE ];
\r
139 /*-----------------------------------------------------------*/
\r
142 /* Called from the TCP/IP thread. */
\r
143 void lwIPAppsInit( void *pvArgument )
\r
145 ip_addr_t xIPAddr, xNetMask, xGateway;
\r
146 extern err_t ethernetif_init( struct netif *xNetIf );
\r
147 static struct netif xNetIf;
\r
149 ( void ) pvArgument;
\r
151 /* Set up the network interface. */
\r
152 ip_addr_set_zero( &xGateway );
\r
153 ip_addr_set_zero( &xIPAddr );
\r
154 ip_addr_set_zero( &xNetMask );
\r
156 LWIP_PORT_INIT_GW(&xGateway);
\r
157 LWIP_PORT_INIT_IPADDR(&xIPAddr);
\r
158 LWIP_PORT_INIT_NETMASK(&xNetMask);
\r
159 printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&xIPAddr));
\r
161 netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, NULL, ethernetif_init, tcpip_input ) );
\r
162 netif_set_up( &xNetIf );
\r
164 /* Install the server side include handler. */
\r
165 http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );
\r
167 /* Create the mutex used to ensure mutual exclusive access to the Tx
\r
169 xTxBufferMutex = xSemaphoreCreateMutex();
\r
170 configASSERT( xTxBufferMutex );
\r
172 /* Create the httpd server from the standard lwIP code. This demonstrates
\r
173 use of the lwIP raw API. */
\r
176 /* Create the FreeRTOS defined basic command server. This demonstrates use
\r
177 of the lwIP sockets API. */
\r
178 xTaskCreate( vBasicSocketsCommandInterpreterTask, ( signed char * ) "CmdInt", configMINIMAL_STACK_SIZE * 10, NULL, configMAX_PRIORITIES - 2, NULL );
\r
180 /*-----------------------------------------------------------*/
\r
182 static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength )
\r
184 static unsigned int uiUpdateCount = 0;
\r
185 static char cUpdateString[ 200 ];
\r
186 extern char *pcMainGetTaskStatusMessage( void );
\r
188 /* Unused parameter. */
\r
189 ( void ) iBufferLength;
\r
191 /* The SSI handler function that generates text depending on the index of
\r
192 the SSI tag encountered. */
\r
196 case ssiTASK_STATS_INDEX :
\r
197 vTaskList( ( signed char * ) pcBuffer );
\r
200 case ssiRUN_TIME_STATS_INDEX :
\r
201 vTaskGetRunTimeStats( ( signed char * ) pcBuffer );
\r
205 /* Include a count of the number of times an SSI function has been executed
\r
206 in the returned string. */
\r
208 sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );
\r
209 strcat( pcBuffer, cUpdateString );
\r
211 return strlen( pcBuffer );
\r
213 /*-----------------------------------------------------------*/
\r
215 signed char *pcLwipAppsBlockingGetTxBuffer( void )
\r
217 signed char *pcReturn;
\r
219 /* Attempt to obtain the semaphore that guards the Tx buffer. */
\r
220 if( xSemaphoreTakeRecursive( xTxBufferMutex, lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ) == pdFAIL )
\r
222 /* The semaphore could not be obtained before timing out. */
\r
227 /* The semaphore was obtained successfully. Return a pointer to the
\r
229 pcReturn = cTxBuffer;
\r
234 /*-----------------------------------------------------------*/
\r
236 void vLwipAppsReleaseTxBuffer( void )
\r
238 /* Finished with the Tx buffer. Return the mutex. */
\r
239 xSemaphoreGiveRecursive( xTxBufferMutex );
\r