Comment the command line interpreter and lwIP sockets based server code.

This commit is contained in:
Richard Barry 2011-08-01 16:03:49 +00:00
parent 723bed71bf
commit 5ca1d4194d
10 changed files with 271 additions and 245 deletions

View file

@ -53,25 +53,11 @@
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* lwIP core includes */
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/timers.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/init.h"
#include "lwip/tcpip.h"
#include "lwip/netif.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/sockets.h"
/* lwIP netif includes */
#include "netif/etharp.h"
/* applications includes */
#include "apps/httpserver_raw_from_lwIP_download/httpd.h"
@ -79,71 +65,96 @@
/* include the port-dependent configuration */
#include "lwipcfg_msvc.h"
static struct netif netif;
/* Dimensions the cTxBuffer array - which is itself used to hold replies from
command line commands. cTxBuffer is a shared buffer, so protected by the
xTxBufferMutex mutex. */
#define lwipappsTX_BUFFER_SIZE 1024
static void apps_init( void );
/* The maximum time to block waiting to obtain the xTxBufferMutex to become
available. */
#define lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ( 100 / portTICK_RATE_MS )
/* Definitions of the various SSI callback functions within the pccSSITags
array. If pccSSITags is updated, then these definitions must also be updated. */
#define ssiTASK_STATS_INDEX 0
#define ssiRUN_TIME_STATS_INDEX 1
extern void vBasicTelnetServer( void *pvParameters );
/*-----------------------------------------------------------*/
/*
* The function that implements the lwIP based sockets command interpreter
* server.
*/
extern void vBasicSocketsCommandInterpreterTask( void *pvParameters );
/*
* The SSI handler callback function passed to lwIP.
*/
static unsigned short uslwIPAppsSSIHandler( int iIndex, char *pcBuffer, int iBufferLength );
/*-----------------------------------------------------------*/
/* The SSI strings that are embedded in the served html files. */
/* The SSI strings that are embedded in the served html files. If this array
is changed, then the index position defined by the #defines such as
ssiTASK_STATS_INDEX above must also be updated. */
static const char *pccSSITags[] =
{
"rtos_stats",
"run_stats"
};
/* Semaphore used to guard the Tx buffer. */
static xSemaphoreHandle xTxBufferMutex = NULL;
/* The Tx buffer itself. This is used to hold the text generated by the
execution of command line commands, and (hopefully) the execution of
server side include callbacks. It is a shared buffer so protected by the
xTxBufferMutex mutex. pcLwipAppsBlockingGetTxBuffer() and
vLwipAppsReleaseTxBuffer() are provided to obtain and release the
xTxBufferMutex respectively. pcLwipAppsBlockingGetTxBuffer() must be used with
caution as it has the potential to block. */
static signed char cTxBuffer[ lwipappsTX_BUFFER_SIZE ];
/*-----------------------------------------------------------*/
/* Called from the TCP/IP thread. */
void lwIPAppsInit( void *pvArgument )
{
ip_addr_t ipaddr, netmask, gw;
extern err_t ethernetif_init( struct netif *netif );
ip_addr_t xIPAddr, xNetMask, xGateway;
extern err_t ethernetif_init( struct netif *xNetIf );
static struct netif xNetIf;
( void ) pvArgument;
ip_addr_set_zero( &gw );
ip_addr_set_zero( &ipaddr );
ip_addr_set_zero( &netmask );
/* Set up the network interface. */
ip_addr_set_zero( &xGateway );
ip_addr_set_zero( &xIPAddr );
ip_addr_set_zero( &xNetMask );
LWIP_PORT_INIT_GW(&gw);
LWIP_PORT_INIT_IPADDR(&ipaddr);
LWIP_PORT_INIT_NETMASK(&netmask);
printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&ipaddr));
LWIP_PORT_INIT_GW(&xGateway);
LWIP_PORT_INIT_IPADDR(&xIPAddr);
LWIP_PORT_INIT_NETMASK(&xNetMask);
printf("Starting lwIP, local interface IP is %s\n", ip_ntoa(&xIPAddr));
netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input));
netif_set_default( netif_add( &xNetIf, &xIPAddr, &xNetMask, &xGateway, NULL, ethernetif_init, tcpip_input ) );
netif_set_up( &xNetIf );
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(&netif, status_callback);
#endif /* LWIP_NETIF_STATUS_CALLBACK */
#if LWIP_NETIF_LINK_CALLBACK
netif_set_link_callback(&netif, link_callback);
#endif /* LWIP_NETIF_LINK_CALLBACK */
netif_set_up( &netif );
apps_init();
/* Install the server side include handler. */
http_set_ssi_handler( uslwIPAppsSSIHandler, pccSSITags, sizeof( pccSSITags ) / sizeof( char * ) );
}
/*-----------------------------------------------------------*/
/* This function initializes applications */
static void apps_init( void )
{
/* Create the mutex used to ensure mutual exclusive access to the Tx
buffer. */
xTxBufferMutex = xSemaphoreCreateMutex();
configASSERT( xTxBufferMutex );
/* Create the httpd server from the standard lwIP code. This demonstrates
use of the lwIP raw API. */
httpd_init();
/* Create the FreeRTOS defined basic command server. This demonstrates use
of the lwIP sockets API. */
xTaskCreate( vBasicTelnetServer, ( signed char * ) "Telnet", configMINIMAL_STACK_SIZE * 10, NULL, configMAX_PRIORITIES - 2, NULL );
xTaskCreate( vBasicSocketsCommandInterpreterTask, ( signed char * ) "CmdInt", configMINIMAL_STACK_SIZE * 10, NULL, configMAX_PRIORITIES - 2, NULL );
}
/*-----------------------------------------------------------*/
@ -153,6 +164,7 @@ static unsigned int uiUpdateCount = 0;
static char cUpdateString[ 200 ];
extern char *pcMainGetTaskStatusMessage( void );
/* Unused parameter. */
( void ) iBufferLength;
/* The SSI handler function that generates text depending on the index of
@ -161,18 +173,50 @@ extern char *pcMainGetTaskStatusMessage( void );
switch( iIndex )
{
case ssiTASK_STATS_INDEX :
vTaskList( pcBuffer );
vTaskList( ( signed char * ) pcBuffer );
break;
case ssiRUN_TIME_STATS_INDEX :
vTaskGetRunTimeStats( pcBuffer );
vTaskGetRunTimeStats( ( signed char * ) pcBuffer );
break;
}
/* Include a count of the number of times an SSI function has been executed
in the returned string. */
uiUpdateCount++;
sprintf( cUpdateString, "\r\n\r\n%u\r\nStatus - %s", uiUpdateCount, pcMainGetTaskStatusMessage() );
strcat( pcBuffer, cUpdateString );
return strlen( pcBuffer );
}
/*-----------------------------------------------------------*/
signed char *pcLwipAppsBlockingGetTxBuffer( void )
{
signed char *pcReturn;
/* Attempt to obtain the semaphore that guards the Tx buffer. */
if( xSemaphoreTakeRecursive( xTxBufferMutex, lwipappsMAX_TIME_TO_WAIT_FOR_TX_BUFFER_MS ) == pdFAIL )
{
/* The semaphore could not be obtained before timing out. */
pcReturn = NULL;
}
else
{
/* The semaphore was obtained successfully. Return a pointer to the
Tx buffer. */
pcReturn = cTxBuffer;
}
return pcReturn;
}
/*-----------------------------------------------------------*/
void vLwipAppsReleaseTxBuffer( void )
{
/* Finished with the Tx buffer. Return the mutex. */
xSemaphoreGiveRecursive( xTxBufferMutex );
}