Initial version
This commit is contained in:
@ -0,0 +1,664 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* See the following URL for information on the commands defined in this file:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* FreeRTOS+CLI includes. */
|
||||
#include "FreeRTOS_CLI.h"
|
||||
|
||||
/* FreeRTOS+UDP includes, just to make the stats available to the CLI
|
||||
commands. */
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
|
||||
#define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Implements the run-time-stats command.
|
||||
*/
|
||||
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the task-stats command.
|
||||
*/
|
||||
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-three-parameters command.
|
||||
*/
|
||||
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-parameters command.
|
||||
*/
|
||||
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that prints out IP address information.
|
||||
*/
|
||||
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that prints out the gathered demo debug stats.
|
||||
*/
|
||||
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that sends an ICMP ping request to an IP address.
|
||||
*/
|
||||
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the "trace start" and "trace stop" commands;
|
||||
*/
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
|
||||
#endif
|
||||
|
||||
/* Structure that defines the "ip-config" command line command. */
|
||||
static const CLI_Command_Definition_t xIPConfig =
|
||||
{
|
||||
"ip-config",
|
||||
"ip-config:\r\n Displays IP address configuration\r\n\r\n",
|
||||
prvDisplayIPConfig,
|
||||
0
|
||||
};
|
||||
|
||||
#if configINCLUDE_DEMO_DEBUG_STATS != 0
|
||||
/* Structure that defines the "ip-debug-stats" command line command. */
|
||||
static const CLI_Command_Definition_t xIPDebugStats =
|
||||
{
|
||||
"ip-debug-stats", /* The command string to type. */
|
||||
"ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
|
||||
prvDisplayIPDebugStats, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
|
||||
|
||||
/* Structure that defines the "run-time-stats" command line command. This
|
||||
generates a table that shows how much run time each task has */
|
||||
static const CLI_Command_Definition_t xRunTimeStats =
|
||||
{
|
||||
"run-time-stats", /* The command string to type. */
|
||||
"run-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n\r\n",
|
||||
prvRunTimeStatsCommand, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "task-stats" command line command. This generates
|
||||
a table that gives information on each task in the system. */
|
||||
static const CLI_Command_Definition_t xTaskStats =
|
||||
{
|
||||
"task-stats", /* The command string to type. */
|
||||
"task-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n\r\n",
|
||||
prvTaskStatsCommand, /* The function to run. */
|
||||
0 /* No parameters are expected. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "echo_3_parameters" command line command. This
|
||||
takes exactly three parameters that the command simply echos back one at a
|
||||
time. */
|
||||
static const CLI_Command_Definition_t xThreeParameterEcho =
|
||||
{
|
||||
"echo-3-parameters",
|
||||
"echo-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n\r\n",
|
||||
prvThreeParameterEchoCommand, /* The function to run. */
|
||||
3 /* Three parameters are expected, which can take any value. */
|
||||
};
|
||||
|
||||
/* Structure that defines the "echo_parameters" command line command. This
|
||||
takes a variable number of parameters that the command simply echos back one at
|
||||
a time. */
|
||||
static const CLI_Command_Definition_t xParameterEcho =
|
||||
{
|
||||
"echo-parameters",
|
||||
"echo-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n\r\n",
|
||||
prvParameterEchoCommand, /* The function to run. */
|
||||
-1 /* The user can enter any number of commands. */
|
||||
};
|
||||
|
||||
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
|
||||
|
||||
/* Structure that defines the "ping" command line command. This takes an IP
|
||||
address or host name and (optionally) the number of bytes to ping as
|
||||
parameters. */
|
||||
static const CLI_Command_Definition_t xPing =
|
||||
{
|
||||
"ping",
|
||||
"ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",
|
||||
prvPingCommand, /* The function to run. */
|
||||
-1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
|
||||
};
|
||||
|
||||
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
/* Structure that defines the "trace" command line command. This takes a single
|
||||
parameter, which can be either "start" or "stop". */
|
||||
static const CLI_Command_Definition_t xStartStopTrace =
|
||||
{
|
||||
"trace",
|
||||
"trace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n\r\n",
|
||||
prvStartStopTraceCommand, /* The function to run. */
|
||||
1 /* One parameter is expected. Valid values are "start" and "stop". */
|
||||
};
|
||||
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vRegisterCLICommands( void )
|
||||
{
|
||||
/* Register all the command line commands defined immediately above. */
|
||||
FreeRTOS_CLIRegisterCommand( &xTaskStats );
|
||||
FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
|
||||
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
|
||||
FreeRTOS_CLIRegisterCommand( &xParameterEcho );
|
||||
FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
|
||||
FreeRTOS_CLIRegisterCommand( &xIPConfig );
|
||||
|
||||
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
|
||||
{
|
||||
FreeRTOS_CLIRegisterCommand( &xPing );
|
||||
}
|
||||
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
|
||||
#endif
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
const char *const pcHeader = " State\tPriority\tStack\t#\r\n************************************************\r\n";
|
||||
BaseType_t xSpacePadding;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Generate a table of task stats. */
|
||||
strcpy( pcWriteBuffer, "Task" );
|
||||
pcWriteBuffer += strlen( pcWriteBuffer );
|
||||
|
||||
/* Pad the string "task" with however many bytes necessary to make it the
|
||||
length of a task name. Minus three for the null terminator and half the
|
||||
number of characters in "Task" so the column lines up with the centre of
|
||||
the heading. */
|
||||
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
|
||||
{
|
||||
/* Add a space to align columns after the task's name. */
|
||||
*pcWriteBuffer = ' ';
|
||||
pcWriteBuffer++;
|
||||
|
||||
/* Ensure always terminated. */
|
||||
*pcWriteBuffer = 0x00;
|
||||
}
|
||||
strcpy( pcWriteBuffer, pcHeader );
|
||||
vTaskList( pcWriteBuffer + strlen( pcHeader ) );
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
|
||||
BaseType_t xSpacePadding;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Generate a table of task stats. */
|
||||
strcpy( pcWriteBuffer, "Task" );
|
||||
pcWriteBuffer += strlen( pcWriteBuffer );
|
||||
|
||||
/* Pad the string "task" with however many bytes necessary to make it the
|
||||
length of a task name. Minus three for the null terminator and half the
|
||||
number of characters in "Task" so the column lines up with the centre of
|
||||
the heading. */
|
||||
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
|
||||
{
|
||||
/* Add a space to align columns after the task's name. */
|
||||
*pcWriteBuffer = ' ';
|
||||
pcWriteBuffer++;
|
||||
|
||||
/* Ensure always terminated. */
|
||||
*pcWriteBuffer = 0x00;
|
||||
}
|
||||
|
||||
strcpy( pcWriteBuffer, pcHeader );
|
||||
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
const char *pcParameter;
|
||||
BaseType_t xParameterStringLength, xReturn;
|
||||
static BaseType_t lParameterNumber = 0;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
if( lParameterNumber == 0 )
|
||||
{
|
||||
/* The first time the function is called after the command has been
|
||||
entered just a header string is returned. */
|
||||
sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
|
||||
|
||||
/* Next time the function is called the first parameter will be echoed
|
||||
back. */
|
||||
lParameterNumber = 1L;
|
||||
|
||||
/* There is more data to be returned as no parameters have been echoed
|
||||
back yet. */
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
lParameterNumber, /* Return the next parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Return the parameter string. */
|
||||
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
|
||||
sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
|
||||
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
|
||||
|
||||
/* If this is the last of the three parameters then there are no more
|
||||
strings to return after this one. */
|
||||
if( lParameterNumber == 3L )
|
||||
{
|
||||
/* If this is the last of the three parameters then there are no more
|
||||
strings to return after this one. */
|
||||
xReturn = pdFALSE;
|
||||
lParameterNumber = 0L;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are more parameters to return after this one. */
|
||||
xReturn = pdTRUE;
|
||||
lParameterNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
const char *pcParameter;
|
||||
BaseType_t xParameterStringLength, xReturn;
|
||||
static BaseType_t lParameterNumber = 0;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
if( lParameterNumber == 0 )
|
||||
{
|
||||
/* The first time the function is called after the command has been
|
||||
entered just a header string is returned. */
|
||||
sprintf( pcWriteBuffer, "The parameters were:\r\n" );
|
||||
|
||||
/* Next time the function is called the first parameter will be echoed
|
||||
back. */
|
||||
lParameterNumber = 1L;
|
||||
|
||||
/* There is more data to be returned as no parameters have been echoed
|
||||
back yet. */
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
lParameterNumber, /* Return the next parameter. */
|
||||
&xParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
if( pcParameter != NULL )
|
||||
{
|
||||
/* Return the parameter string. */
|
||||
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
|
||||
sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
|
||||
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
|
||||
|
||||
/* There might be more parameters to return after this one. */
|
||||
xReturn = pdTRUE;
|
||||
lParameterNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No more parameters were found. Make sure the write buffer does
|
||||
not contain a valid string. */
|
||||
pcWriteBuffer[ 0 ] = 0x00;
|
||||
|
||||
/* No more data to return. */
|
||||
xReturn = pdFALSE;
|
||||
|
||||
/* Start over the next time this command is executed. */
|
||||
lParameterNumber = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
|
||||
|
||||
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
char * pcParameter;
|
||||
BaseType_t lParameterStringLength, xReturn;
|
||||
uint32_t ulIPAddress, ulBytesToPing;
|
||||
const uint32_t ulDefaultBytesToPing = 8UL;
|
||||
char cBuffer[ 16 ];
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Start with an empty string. */
|
||||
pcWriteBuffer[ 0 ] = 0x00;
|
||||
|
||||
/* Obtain the number of bytes to ping. */
|
||||
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
2, /* Return the second parameter. */
|
||||
&lParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
if( pcParameter == NULL )
|
||||
{
|
||||
/* The number of bytes was not specified, so default it. */
|
||||
ulBytesToPing = ulDefaultBytesToPing;
|
||||
}
|
||||
else
|
||||
{
|
||||
ulBytesToPing = atol( pcParameter );
|
||||
}
|
||||
|
||||
/* Obtain the IP address string. */
|
||||
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&lParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* Attempt to obtain the IP address. If the first character is not a
|
||||
digit, assume the host name has been passed in. */
|
||||
if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
|
||||
{
|
||||
ulIPAddress = FreeRTOS_inet_addr( pcParameter );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Terminate the host name. */
|
||||
pcParameter[ lParameterStringLength ] = 0x00;
|
||||
|
||||
/* Attempt to resolve host. */
|
||||
ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
|
||||
}
|
||||
|
||||
/* Convert IP address, which may have come from a DNS lookup, to string. */
|
||||
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
|
||||
|
||||
if( ulIPAddress != 0 )
|
||||
{
|
||||
xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
if( xReturn == pdFALSE )
|
||||
{
|
||||
sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, xReturn );
|
||||
}
|
||||
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
|
||||
|
||||
#if configINCLUDE_DEMO_DEBUG_STATS != 0
|
||||
|
||||
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
static BaseType_t xIndex = -1;
|
||||
extern xExampleDebugStatEntry_t xIPTraceValues[];
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
xIndex++;
|
||||
|
||||
if( xIndex < xExampleDebugStatEntries() )
|
||||
{
|
||||
sprintf( pcWriteBuffer, "%s %d\r\n", xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Reset the index for the next time it is called. */
|
||||
xIndex = -1;
|
||||
|
||||
/* Ensure nothing remains in the write buffer. */
|
||||
pcWriteBuffer[ 0 ] = 0x00;
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
|
||||
|
||||
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
static BaseType_t xIndex = 0;
|
||||
BaseType_t xReturn;
|
||||
uint32_t ulAddress;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
switch( xIndex )
|
||||
{
|
||||
case 0 :
|
||||
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
|
||||
sprintf( pcWriteBuffer, "\r\nIP address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
|
||||
sprintf( pcWriteBuffer, "\r\nNet mask " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
|
||||
sprintf( pcWriteBuffer, "\r\nGateway address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
|
||||
sprintf( pcWriteBuffer, "\r\nDNS server address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
default :
|
||||
ulAddress = 0;
|
||||
sprintf( pcWriteBuffer, "\r\n\r\n" );
|
||||
xReturn = pdFALSE;
|
||||
xIndex = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if( ulAddress != 0 )
|
||||
{
|
||||
FreeRTOS_inet_ntoa( ulAddress, &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) );
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
|
||||
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||
{
|
||||
const char *pcParameter;
|
||||
BaseType_t lParameterStringLength;
|
||||
|
||||
/* Remove compile time warnings about unused parameters, and check the
|
||||
write buffer is not NULL. NOTE - for simplicity, this example assumes the
|
||||
write buffer length is adequate, so does not check for buffer overflows. */
|
||||
( void ) pcCommandString;
|
||||
( void ) xWriteBufferLen;
|
||||
configASSERT( pcWriteBuffer );
|
||||
|
||||
/* Obtain the parameter string. */
|
||||
pcParameter = FreeRTOS_CLIGetParameter
|
||||
(
|
||||
pcCommandString, /* The command string itself. */
|
||||
1, /* Return the first parameter. */
|
||||
&lParameterStringLength /* Store the parameter string length. */
|
||||
);
|
||||
|
||||
/* Sanity check something was returned. */
|
||||
configASSERT( pcParameter );
|
||||
|
||||
/* There are only two valid parameter values. */
|
||||
if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
|
||||
{
|
||||
/* Start or restart the trace. */
|
||||
vTraceStop();
|
||||
vTraceClear();
|
||||
vTraceStart();
|
||||
|
||||
sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
|
||||
}
|
||||
else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
|
||||
{
|
||||
/* End the trace, if one is running. */
|
||||
vTraceStop();
|
||||
sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
|
||||
}
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
|
||||
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
#ifndef UDP_COMMAND_INTERPRETER_H
|
||||
#define UDP_COMMAND_INTERPRETER_H
|
||||
|
||||
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority );
|
||||
|
||||
#endif /* UDP_COMMAND_INTERPRETER_H */
|
@ -0,0 +1,206 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* FreeRTOS+CLI includes. */
|
||||
#include "FreeRTOS_CLI.h"
|
||||
|
||||
/* FreeRTOS+UDP includes. */
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* Demo app includes. */
|
||||
#include "UDPCommandInterpreter.h"
|
||||
|
||||
/* Dimensions the buffer into which input characters are placed. */
|
||||
#define cmdMAX_INPUT_SIZE 60
|
||||
|
||||
/* Dimensions the buffer into which string outputs can be placed. */
|
||||
#define cmdMAX_OUTPUT_SIZE 1250
|
||||
|
||||
/* Dimensions the buffer passed to the recvfrom() call. */
|
||||
#define cmdSOCKET_INPUT_BUFFER_SIZE 60
|
||||
|
||||
/*
|
||||
* The task that runs FreeRTOS+CLI.
|
||||
*/
|
||||
void vUDPCommandInterpreterTask( void *pvParameters );
|
||||
|
||||
/*
|
||||
* Open and configure the UDP socket.
|
||||
*/
|
||||
static xSocket_t prvOpenUDPServerSocket( uint16_t usPort );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority )
|
||||
{
|
||||
xTaskCreate( vUDPCommandInterpreterTask, "CLI", usStackSize, ( void * ) ulPort, uxPriority, NULL );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Task that provides the input and output for the FreeRTOS+CLI command
|
||||
* interpreter. In this case a UDP port is used. See the URL in the comments
|
||||
* within main.c for the location of the online documentation.
|
||||
*/
|
||||
void vUDPCommandInterpreterTask( void *pvParameters )
|
||||
{
|
||||
long lBytes, lByte;
|
||||
signed char cInChar, cInputIndex = 0;
|
||||
static char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ];
|
||||
BaseType_t xMoreDataToFollow;
|
||||
struct freertos_sockaddr xClient;
|
||||
socklen_t xClientAddressLength = 0; /* This is required as a parameter to maintain the sendto() Berkeley sockets API - but it is not actually used so can take any value. */
|
||||
xSocket_t xSocket;
|
||||
|
||||
/* Just to prevent compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Attempt to open the socket. The port number is passed in the task
|
||||
parameter. The strange casting is to remove compiler warnings on 32-bit
|
||||
machines. */
|
||||
xSocket = prvOpenUDPServerSocket( ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL );
|
||||
|
||||
if( xSocket != FREERTOS_INVALID_SOCKET )
|
||||
{
|
||||
for( ;; )
|
||||
{
|
||||
/* Wait for incoming data on the opened socket. */
|
||||
lBytes = FreeRTOS_recvfrom( xSocket, ( void * ) cLocalBuffer, sizeof( cLocalBuffer ), 0, &xClient, &xClientAddressLength );
|
||||
|
||||
if( lBytes != FREERTOS_SOCKET_ERROR )
|
||||
{
|
||||
/* Process each received byte in turn. */
|
||||
lByte = 0;
|
||||
while( lByte < lBytes )
|
||||
{
|
||||
/* The next character in the input buffer. */
|
||||
cInChar = cLocalBuffer[ lByte ];
|
||||
lByte++;
|
||||
|
||||
/* Newline characters are taken as the end of the command
|
||||
string. */
|
||||
if( cInChar == '\n' )
|
||||
{
|
||||
/* Process the input string received prior to the
|
||||
newline. */
|
||||
do
|
||||
{
|
||||
/* Pass the string to FreeRTOS+CLI. */
|
||||
xMoreDataToFollow = FreeRTOS_CLIProcessCommand( cInputString, cOutputString, cmdMAX_OUTPUT_SIZE );
|
||||
|
||||
/* Send the output generated by the command's
|
||||
implementation. */
|
||||
FreeRTOS_sendto( xSocket, cOutputString, strlen( cOutputString ), 0, &xClient, xClientAddressLength );
|
||||
|
||||
} while( xMoreDataToFollow != pdFALSE ); /* Until the command does not generate any more output. */
|
||||
|
||||
/* All the strings generated by the command processing
|
||||
have been sent. Clear the input string ready to receive
|
||||
the next command. */
|
||||
cInputIndex = 0;
|
||||
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
|
||||
|
||||
/* Transmit a spacer, just to make the command console
|
||||
easier to read. */
|
||||
FreeRTOS_sendto( xSocket, "\r\n", strlen( "\r\n" ), 0, &xClient, xClientAddressLength );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( cInChar == '\r' )
|
||||
{
|
||||
/* Ignore the character. Newlines are used to
|
||||
detect the end of the input string. */
|
||||
}
|
||||
else if( cInChar == '\b' )
|
||||
{
|
||||
/* Backspace was pressed. Erase the last character
|
||||
in the string - if any. */
|
||||
if( cInputIndex > 0 )
|
||||
{
|
||||
cInputIndex--;
|
||||
cInputString[ cInputIndex ] = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A character was entered. Add it to the string
|
||||
entered so far. When a \n is entered the complete
|
||||
string will be passed to the command interpreter. */
|
||||
if( cInputIndex < cmdMAX_INPUT_SIZE )
|
||||
{
|
||||
cInputString[ cInputIndex ] = cInChar;
|
||||
cInputIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The socket could not be opened. */
|
||||
vTaskDelete( NULL );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static xSocket_t prvOpenUDPServerSocket( uint16_t usPort )
|
||||
{
|
||||
struct freertos_sockaddr xServer;
|
||||
xSocket_t xSocket = FREERTOS_INVALID_SOCKET;
|
||||
|
||||
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
if( xSocket != FREERTOS_INVALID_SOCKET)
|
||||
{
|
||||
/* Zero out the server structure. */
|
||||
memset( ( void * ) &xServer, 0x00, sizeof( xServer ) );
|
||||
|
||||
/* Set family and port. */
|
||||
xServer.sin_port = FreeRTOS_htons( usPort );
|
||||
|
||||
/* Bind the address to the socket. */
|
||||
if( FreeRTOS_bind( xSocket, &xServer, sizeof( xServer ) ) == -1 )
|
||||
{
|
||||
FreeRTOS_closesocket( xSocket );
|
||||
xSocket = FREERTOS_INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
return xSocket;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,359 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* See the following web page for essential TwoEchoClient.c usage and
|
||||
* configuration details:
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Common_Echo_Clients.shtml
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* FreeRTOS+UDP includes. */
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* Small delay used between attempts to obtain a zero copy buffer. */
|
||||
#define echoTINY_DELAY ( ( TickType_t ) 2 )
|
||||
|
||||
/* The echo tasks create a socket, send out a number of echo requests
|
||||
(listening for each echo reply), then close the socket again before
|
||||
starting over. This delay is used between each iteration to ensure the
|
||||
network does not get too congested. */
|
||||
#define echoLOOP_DELAY ( ( TickType_t ) 250 / portTICK_RATE_MS )
|
||||
|
||||
#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
|
||||
/* When the trace recorder code is included user events are generated to
|
||||
mark the sending and receiving of the echoed data (only in the zero copy
|
||||
task. */
|
||||
#define echoMARK_SEND_IN_TRACE_BUFFER( x ) vTraceUserEvent( x )
|
||||
traceLabel xZeroCopySendEvent, xZeroCopyReceiveEvent;
|
||||
|
||||
#else
|
||||
/* When the trace recorder code is not included just #define away the call
|
||||
to post the user event. */
|
||||
#define echoMARK_SEND_IN_TRACE_BUFFER( x )
|
||||
#define xZeroCopySendEvent 0
|
||||
#define xZeroCopyReceiveEvent 0
|
||||
#endif
|
||||
|
||||
/* The echo server is assumed to be on port 7, which is the standard echo
|
||||
protocol port. */
|
||||
#define echoECHO_PORT ( 7 )
|
||||
|
||||
/*
|
||||
* Uses a socket to send data to, then receive data from, the standard echo
|
||||
* port number 7. prvEchoClientTask() uses the standard interface.
|
||||
* prvZeroCopyEchoClientTask() uses the zero copy interface.
|
||||
*/
|
||||
static void prvEchoClientTask( void *pvParameters );
|
||||
static void prvZeroCopyEchoClientTask( void *pvParameters );
|
||||
|
||||
/* The receive timeout is set shorter when the windows simulator is used
|
||||
because simulated time is slower than real time. */
|
||||
#ifdef _WINDOWS_
|
||||
const TickType_t xReceiveTimeOut = 50 / portTICK_RATE_MS;
|
||||
#else
|
||||
const TickType_t xReceiveTimeOut = 500 / portTICK_RATE_MS;
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartEchoClientTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority )
|
||||
{
|
||||
/* Create the echo client task that does not use the zero copy interface. */
|
||||
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
|
||||
"Echo0", /* Just a text name for the task to aid debugging. */
|
||||
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
|
||||
NULL, /* The task parameter, not used in this case. */
|
||||
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
|
||||
NULL ); /* The task handle is not used. */
|
||||
|
||||
/* Create the echo client task that does use the zero copy interface. */
|
||||
xTaskCreate( prvZeroCopyEchoClientTask, /* The function that implements the task. */
|
||||
"Echo1", /* Just a text name for the task to aid debugging. */
|
||||
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
|
||||
NULL, /* The task parameter, not used in this case. */
|
||||
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
|
||||
NULL ); /* The task handle is not used. */
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvEchoClientTask( void *pvParameters )
|
||||
{
|
||||
xSocket_t xSocket;
|
||||
struct freertos_sockaddr xEchoServerAddress;
|
||||
char cTxString[ 25 ], cRxString[ 25 ]; /* Make sure the stack is large enough to hold these. Turn on stack overflow checking during debug to be sure. */
|
||||
int32_t lLoopCount = 0UL;
|
||||
const int32_t lMaxLoopCount = 50;
|
||||
volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL;
|
||||
uint32_t xAddressLength = sizeof( xEchoServerAddress );
|
||||
|
||||
/* Remove compiler warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Echo requests are sent to the echo server. The address of the echo
|
||||
server is configured by the constants configECHO_SERVER_ADDR0 to
|
||||
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
|
||||
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
|
||||
xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
|
||||
configECHO_SERVER_ADDR1,
|
||||
configECHO_SERVER_ADDR2,
|
||||
configECHO_SERVER_ADDR3 );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Create a socket. */
|
||||
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* Set a time out so a missing reply does not cause the task to block
|
||||
indefinitely. */
|
||||
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||
|
||||
/* Send a number of echo requests. */
|
||||
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
|
||||
{
|
||||
/* Create the string that is sent to the echo server. */
|
||||
sprintf( cTxString, "Message number %u\r\n", ( unsigned int ) ulTxCount );
|
||||
|
||||
/* Send the string to the socket. ulFlags is set to 0, so the zero
|
||||
copy interface is not used. That means the data from cTxString is
|
||||
copied into a network buffer inside FreeRTOS_sendto(), and cTxString
|
||||
can be reused as soon as FreeRTOS_sendto() has returned. 1 is added
|
||||
to ensure the NULL string terminator is sent as part of the message. */
|
||||
FreeRTOS_sendto( xSocket, /* The socket being sent to. */
|
||||
( void * ) cTxString, /* The data being sent. */
|
||||
strlen( cTxString ) + 1,/* The length of the data being sent. */
|
||||
0, /* ulFlags with the FREERTOS_ZERO_COPY bit clear. */
|
||||
&xEchoServerAddress, /* The destination address. */
|
||||
sizeof( xEchoServerAddress ) );
|
||||
|
||||
/* Keep a count of how many echo requests have been transmitted so
|
||||
it can be compared to the number of echo replies received. It would
|
||||
be expected to loose at least one to an ARP message the first time
|
||||
the connection is created. */
|
||||
ulTxCount++;
|
||||
|
||||
/* Receive data echoed back to the socket. ulFlags is zero, so the
|
||||
zero copy option is not being used and the received data will be
|
||||
copied into the buffer pointed to by cRxString. xAddressLength is
|
||||
not actually used (at the time of writing this comment, anyway) by
|
||||
FreeRTOS_recvfrom(), but is set appropriately in case future
|
||||
versions do use it. */
|
||||
memset( ( void * ) cRxString, 0x00, sizeof( cRxString ) );
|
||||
FreeRTOS_recvfrom( xSocket, /* The socket being received from. */
|
||||
cRxString, /* The buffer into which the received data will be written. */
|
||||
sizeof( cRxString ), /* The size of the buffer provided to receive the data. */
|
||||
0, /* ulFlags with the FREERTOS_ZERO_COPY bit clear. */
|
||||
&xEchoServerAddress, /* The address from where the data was sent (the source address). */
|
||||
&xAddressLength );
|
||||
|
||||
/* Compare the transmitted string to the received string. */
|
||||
if( strcmp( cRxString, cTxString ) == 0 )
|
||||
{
|
||||
/* The echo reply was received without error. */
|
||||
ulRxCount++;
|
||||
}
|
||||
};
|
||||
|
||||
/* Pause for a short while to ensure the network is not too
|
||||
congested. */
|
||||
vTaskDelay( echoLOOP_DELAY );
|
||||
|
||||
/* Close this socket before looping back to create another. */
|
||||
FreeRTOS_closesocket( xSocket );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvZeroCopyEchoClientTask( void *pvParameters )
|
||||
{
|
||||
xSocket_t xSocket;
|
||||
struct freertos_sockaddr xEchoServerAddress;
|
||||
static char cTxString[ 40 ];
|
||||
int32_t lLoopCount = 0UL;
|
||||
volatile uint32_t ulRxCount = 0UL, ulTxCount = 0UL;
|
||||
uint32_t xAddressLength = sizeof( xEchoServerAddress );
|
||||
int32_t lReturned;
|
||||
uint8_t *pucUDPPayloadBuffer;
|
||||
|
||||
const int32_t lMaxLoopCount = 50;
|
||||
const char * const pcStringToSend = "Zero copy message number";
|
||||
/* The buffer is large enough to hold the string, a number, and the string terminator. */
|
||||
const size_t xBufferLength = strlen( pcStringToSend ) + 15;
|
||||
|
||||
#if ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS == 1
|
||||
{
|
||||
/* When the trace recorder code is included user events are generated to
|
||||
mark the sending and receiving of the echoed data (only in the zero copy
|
||||
task). */
|
||||
xZeroCopySendEvent = xTraceOpenLabel( "ZeroCopyTx" );
|
||||
xZeroCopyReceiveEvent = xTraceOpenLabel( "ZeroCopyRx" );
|
||||
}
|
||||
#endif /* ipconfigINCLUDE_EXAMPLE_FREERTOS_PLUS_TRACE_CALLS */
|
||||
|
||||
/* Remove compiler warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Delay for a little while to ensure the task is out of synch with the
|
||||
other echo task implemented above. */
|
||||
vTaskDelay( echoLOOP_DELAY >> 1 );
|
||||
|
||||
/* Echo requests are sent to the echo server. The address of the echo
|
||||
server is configured by the constants configECHO_SERVER_ADDR0 to
|
||||
configECHO_SERVER_ADDR3 in FreeRTOSConfig.h. */
|
||||
xEchoServerAddress.sin_port = FreeRTOS_htons( echoECHO_PORT );
|
||||
xEchoServerAddress.sin_addr = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
|
||||
configECHO_SERVER_ADDR1,
|
||||
configECHO_SERVER_ADDR2,
|
||||
configECHO_SERVER_ADDR3 );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Create a socket. */
|
||||
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* Set a time out so a missing reply does not cause the task to block
|
||||
indefinitely. */
|
||||
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
|
||||
|
||||
/* Send a number of echo requests. */
|
||||
for( lLoopCount = 0; lLoopCount < lMaxLoopCount; lLoopCount++ )
|
||||
{
|
||||
/* This task is going to send using the zero copy interface. The
|
||||
data being sent is therefore written directly into a buffer that is
|
||||
passed by reference into the FreeRTOS_sendto() function. First
|
||||
obtain a buffer of adequate size from the IP stack. Although a max
|
||||
delay is used, the actual delay will be capped to
|
||||
ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence the test to ensure a buffer
|
||||
was actually obtained. */
|
||||
pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xBufferLength, portMAX_DELAY );
|
||||
|
||||
if( pucUDPPayloadBuffer != NULL )
|
||||
{
|
||||
/* A buffer was successfully obtained. Create the string that is
|
||||
sent to the echo server. Note the string is written directly
|
||||
into the buffer obtained from the IP stack. */
|
||||
sprintf( ( char * ) pucUDPPayloadBuffer, "%s %u\r\n", "Zero copy message number", ( unsigned int ) ulTxCount );
|
||||
|
||||
/* Also copy the string into a local buffer so it can be compared
|
||||
with the string that is later received back from the echo server. */
|
||||
strcpy( cTxString, ( char * ) pucUDPPayloadBuffer );
|
||||
|
||||
/* Pass the buffer into the send function. ulFlags has the
|
||||
FREERTOS_ZERO_COPY bit set so the IP stack will take control of
|
||||
the buffer, rather than copy data out of the buffer. */
|
||||
echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopySendEvent );
|
||||
lReturned = FreeRTOS_sendto( xSocket, /* The socket being sent to. */
|
||||
( void * ) pucUDPPayloadBuffer, /* The buffer being passed into the IP stack. */
|
||||
strlen( cTxString ) + 1, /* The length of the data being sent. Plus 1 to ensure the null terminator is part of the data. */
|
||||
FREERTOS_ZERO_COPY, /* ulFlags with the zero copy bit is set. */
|
||||
&xEchoServerAddress, /* Where the data is being sent. */
|
||||
sizeof( xEchoServerAddress ) );
|
||||
|
||||
if( lReturned == 0 )
|
||||
{
|
||||
/* The send operation failed, so this task is still
|
||||
responsible for the buffer obtained from the IP stack. To
|
||||
ensure the buffer is not lost it must either be used again,
|
||||
or, as in this case, returned to the IP stack using
|
||||
FreeRTOS_ReleaseUDPPayloadBuffer(). pucUDPPayloadBuffer can
|
||||
be safely re-used to receive from the socket below once the
|
||||
buffer has been returned to the stack. */
|
||||
FreeRTOS_ReleaseUDPPayloadBuffer( ( void * ) pucUDPPayloadBuffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The send was successful so the IP stack is now managing
|
||||
the buffer pointed to by pucUDPPayloadBuffer, and the IP
|
||||
stack will return the buffer once it has been sent.
|
||||
pucUDPPayloadBuffer can be safely re-used to receive from
|
||||
the socket below. */
|
||||
}
|
||||
|
||||
/* Keep a count of how many echo requests have been transmitted
|
||||
so it can be compared to the number of echo replies received.
|
||||
It would be expected to loose at least one to an ARP message the
|
||||
first time the connection is created. */
|
||||
ulTxCount++;
|
||||
|
||||
/* Receive data on the socket. ulFlags has the zero copy bit set
|
||||
(FREERTOS_ZERO_COPY) indicating to the stack that a reference to
|
||||
the received data should be passed out to this task using the
|
||||
second parameter to the FreeRTOS_recvfrom() call. When this is
|
||||
done the IP stack is no longer responsible for releasing the
|
||||
buffer, and the task *must* return the buffer to the stack when
|
||||
it is no longer needed. By default the receive block time is
|
||||
portMAX_DELAY. */
|
||||
echoMARK_SEND_IN_TRACE_BUFFER( xZeroCopyReceiveEvent );
|
||||
lReturned = FreeRTOS_recvfrom( xSocket, /* The socket to receive from. */
|
||||
( void * ) &pucUDPPayloadBuffer, /* pucUDPPayloadBuffer will be set to point to the buffer that already contains the received data. */
|
||||
0, /* Ignored because the zero copy interface is being used. */
|
||||
FREERTOS_ZERO_COPY, /* ulFlags with the FREERTOS_ZERO_COPY bit set. */
|
||||
&xEchoServerAddress, /* The address from which the data was sent. */
|
||||
&xAddressLength );
|
||||
|
||||
if( lReturned > 0 )
|
||||
{
|
||||
/* Compare the string sent to the echo server with the string
|
||||
received back from the echo server. */
|
||||
if( strcmp( ( char * ) pucUDPPayloadBuffer, cTxString ) == 0 )
|
||||
{
|
||||
/* The strings matched. */
|
||||
ulRxCount++;
|
||||
}
|
||||
|
||||
/* The buffer that contains the data passed out of the stack
|
||||
*must* be returned to the stack. */
|
||||
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Pause for a short while to ensure the network is not too
|
||||
congested. */
|
||||
vTaskDelay( echoLOOP_DELAY );
|
||||
|
||||
/* Close this socket before looping back to create another. */
|
||||
FreeRTOS_closesocket( xSocket );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
#ifndef TWO_ECHO_CLIENTS_H
|
||||
#define TWO_ECHO_CLIENTS_H
|
||||
|
||||
/*
|
||||
* Create the two UDP echo client tasks. One task uses the standard interface
|
||||
* to send to and receive from an echo server. The other task uses the zero
|
||||
* copy interface to send to and receive from an echo server.
|
||||
*/
|
||||
void vStartEchoClientTasks( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
|
||||
|
||||
#endif /* TWO_ECHO_CLIENTS_H */
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file, along with DemoIPTrace.h, provides a basic example use of the
|
||||
* FreeRTOS+UDP trace macros. The statistics gathered here can be viewed in
|
||||
* the command line interface.
|
||||
* See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* FreeRTOS+UDP includes. */
|
||||
#include "FreeRTOS_UDP_IP.h"
|
||||
#include "DemoIPTrace.h"
|
||||
|
||||
/* It is possible to remove the trace macros using the
|
||||
configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
|
||||
#if configINCLUDE_DEMO_DEBUG_STATS == 1
|
||||
|
||||
/*
|
||||
* Each row in the xIPTraceValues[] table contains a pointer to a function that
|
||||
* updates the value for that row. Rows that latch the lowest value point to
|
||||
* this function (for example, this function can be used to latch the lowest
|
||||
* number of network buffers that were available during the execution of the
|
||||
* stack).
|
||||
*/
|
||||
static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount );
|
||||
|
||||
/*
|
||||
* Each row in the xIPTraceValues[] table contains a pointer to a function that
|
||||
* updates the value for that row. Rows that simply increment an event count
|
||||
* point to this function.
|
||||
*/
|
||||
static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount );
|
||||
|
||||
|
||||
xExampleDebugStatEntry_t xIPTraceValues[] =
|
||||
{
|
||||
/* Comment out array entries to remove individual trace items. */
|
||||
|
||||
{ iptraceID_NETWORK_INTERFACE_RECEIVE, ( const uint8_t * const ) "Packets received by the network interface", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_NETWORK_INTERFACE_TRANSMIT, ( const uint8_t * const ) "Count of transmitted packets", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, ( const uint8_t * const ) "Count of packets dropped to generate ARP", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_NETWORK_BUFFER_OBTAINED, ( const uint8_t * const ) "Lowest ever available network buffers", prvStoreLowest, 0xffffUL },
|
||||
{ iptraceID_NETWORK_EVENT_RECEIVED, ( const uint8_t * const ) "Lowest ever free space in network event queue", prvStoreLowest, 0xffffUL },
|
||||
{ iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, ( const uint8_t * const ) "Count of failed attempts to obtain a network buffer",prvIncrementEventCount, 0 },
|
||||
{ iptraceID_ARP_TABLE_ENTRY_EXPIRED, ( const uint8_t * const ) "Count of expired ARP entries", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_FAILED_TO_CREATE_SOCKET, ( const uint8_t * const ) "Count of failures to create a socket", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_RECVFROM_DISCARDING_BYTES, ( const uint8_t * const ) "Count of times recvfrom() has discarding bytes", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_ETHERNET_RX_EVENT_LOST, ( const uint8_t * const ) "Count of lost Ethenret Rx events (event queue full?)",prvIncrementEventCount, 0 },
|
||||
{ iptraceID_STACK_TX_EVENT_LOST, ( const uint8_t * const ) "Count of lost IP stack events (event queue full?)", prvIncrementEventCount, 0 },
|
||||
{ ipconfigID_BIND_FAILED, ( const uint8_t * const ) "Count of failed calls to bind()", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_RECVFROM_TIMEOUT, ( const uint8_t * const ) "Count of receive timeouts", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_SENDTO_DATA_TOO_LONG, ( const uint8_t * const ) "Count of failed sends due to oversized payload", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_SENDTO_SOCKET_NOT_BOUND, ( const uint8_t * const ) "Count of failed sends due to unbound socket", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_NO_BUFFER_FOR_SENDTO, ( const uint8_t * const ) "Count of failed transmits due to timeout", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, ( const uint8_t * const ) "Number of times task had to wait to obtain a DMA Tx descriptor", prvIncrementEventCount, 0 },
|
||||
{ iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, ( const uint8_t * const ) "Failed to notify select group", prvIncrementEventCount, 0 }
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
BaseType_t xExampleDebugStatEntries( void )
|
||||
{
|
||||
/* Return the number of entries in the xIPTraceValues[] table. */
|
||||
return ( BaseType_t ) ( sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t ) );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue )
|
||||
{
|
||||
BaseType_t xIndex;
|
||||
const BaseType_t xEntries = sizeof( xIPTraceValues ) / sizeof( xExampleDebugStatEntry_t );
|
||||
|
||||
/* Update an entry in the xIPTraceValues[] table. Each row in the table
|
||||
includes a pointer to a function that performs the actual update. This
|
||||
function just executes the update function from that table row. */
|
||||
for( xIndex = 0; xIndex < xEntries; xIndex++ )
|
||||
{
|
||||
if( xIPTraceValues[ xIndex ].ucIdentifier == ucIdentifier )
|
||||
{
|
||||
xIPTraceValues[ xIndex ].vPerformAction( &( xIPTraceValues[ xIndex ].ulData ), ulValue );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
configASSERT( xIndex != xEntries );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvIncrementEventCount( uint32_t *pulCurrentValue, uint32_t ulCount )
|
||||
{
|
||||
/* Each row in the xIPTraceValues[] table contains a pointer to a function
|
||||
that updates the value for that row. Rows that simply increment an event
|
||||
count point to this function. */
|
||||
( void ) ulCount;
|
||||
( *pulCurrentValue )++;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvStoreLowest( uint32_t *pulCurrentValue, uint32_t ulCount )
|
||||
{
|
||||
/* Each row in the xIPTraceValues[] table contains a pointer to a function
|
||||
that updates the value for that row. Rows that latch the lowest value
|
||||
point to this function (for example, this function can be used to latch
|
||||
the lowest number of network buffers that were available during the
|
||||
execution of the stack). */
|
||||
if( ulCount < *pulCurrentValue )
|
||||
{
|
||||
*pulCurrentValue = ulCount;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
#endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,121 @@
|
||||
/*
|
||||
* FreeRTOS Kernel V10.2.1
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* http://www.FreeRTOS.org
|
||||
* http://aws.amazon.com/freertos
|
||||
*
|
||||
* 1 tab == 4 spaces!
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file, along with DemoIPTrace.h, provides a basic example use of the
|
||||
* FreeRTOS+UDP trace macros. The statistics gathered here can be viewed in
|
||||
* the command line interface.
|
||||
* See http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/UDP_IP_Trace.shtml
|
||||
*/
|
||||
|
||||
#ifndef DEMO_IP_TRACE_MACROS_H
|
||||
#define DEMO_IP_TRACE_MACROS_H
|
||||
|
||||
typedef void ( *vTraceAction_t )( uint32_t *, uint32_t );
|
||||
|
||||
/* Type that defines each statistic being gathered. */
|
||||
typedef struct ExampleDebugStatEntry
|
||||
{
|
||||
uint8_t ucIdentifier; /* Unique identifier for statistic. */
|
||||
const uint8_t * const pucDescription; /* Text description for the statistic. */
|
||||
vTraceAction_t vPerformAction; /* Action to perform when the statistic is updated (increment counter, store minimum value, store maximum value, etc. */
|
||||
uint32_t ulData; /* The meaning of this data is dependent on the trace macro ID. */
|
||||
} xExampleDebugStatEntry_t;
|
||||
|
||||
/* Unique identifiers used to locate the entry for each trace macro in the
|
||||
xIPTraceValues[] table defined in DemoIPTrace.c. */
|
||||
#define iptraceID_NETWORK_INTERFACE_RECEIVE 0
|
||||
#define iptraceID_NETWORK_INTERFACE_TRANSMIT 1
|
||||
#define iptraceID_PACKET_DROPPED_TO_GENERATE_ARP 2
|
||||
/* Do not change IDs above this line as the ID is shared with a FreeRTOS+Nabto
|
||||
demo. */
|
||||
#define iptraceID_NETWORK_BUFFER_OBTAINED 3
|
||||
#define iptraceID_NETWORK_BUFFER_OBTAINED_FROM_ISR 4
|
||||
#define iptraceID_NETWORK_EVENT_RECEIVED 5
|
||||
#define iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER 6
|
||||
#define iptraceID_ARP_TABLE_ENTRY_EXPIRED 7
|
||||
#define iptraceID_FAILED_TO_CREATE_SOCKET 8
|
||||
#define iptraceID_RECVFROM_DISCARDING_BYTES 9
|
||||
#define iptraceID_ETHERNET_RX_EVENT_LOST 10
|
||||
#define iptraceID_STACK_TX_EVENT_LOST 11
|
||||
#define ipconfigID_BIND_FAILED 12
|
||||
#define iptraceID_RECVFROM_TIMEOUT 13
|
||||
#define iptraceID_SENDTO_DATA_TOO_LONG 14
|
||||
#define iptraceID_SENDTO_SOCKET_NOT_BOUND 15
|
||||
#define iptraceID_NO_BUFFER_FOR_SENDTO 16
|
||||
#define iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR 17
|
||||
#define iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP 18
|
||||
|
||||
/* It is possible to remove the trace macros using the
|
||||
configINCLUDE_DEMO_DEBUG_STATS setting in FreeRTOSIPConfig.h. */
|
||||
#if configINCLUDE_DEMO_DEBUG_STATS == 1
|
||||
|
||||
/* The trace macro definitions themselves. Any trace macros left undefined
|
||||
will default to be empty macros. */
|
||||
#define iptraceNETWORK_BUFFER_OBTAINED( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) )
|
||||
#define iptraceNETWORK_BUFFER_OBTAINED_FROM_ISR( pxBufferAddress ) vExampleDebugStatUpdate( iptraceID_NETWORK_BUFFER_OBTAINED, uxQueueMessagesWaiting( ( xQueueHandle ) xNetworkBufferSemaphore ) )
|
||||
|
||||
#define iptraceNETWORK_EVENT_RECEIVED( eEvent ) { \
|
||||
uint16_t usSpace; \
|
||||
usSpace = ( uint16_t ) uxQueueMessagesWaiting( xNetworkEventQueue ); \
|
||||
/* Minus one as an event was removed before the space was queried. */ \
|
||||
usSpace = ( ipconfigEVENT_QUEUE_LENGTH - usSpace ) - 1; \
|
||||
vExampleDebugStatUpdate( iptraceID_NETWORK_EVENT_RECEIVED, usSpace ); \
|
||||
}
|
||||
|
||||
#define iptraceFAILED_TO_OBTAIN_NETWORK_BUFFER() vExampleDebugStatUpdate( iptraceID_FAILED_TO_OBTAIN_NETWORK_BUFFER, 0 )
|
||||
#define iptraceARP_TABLE_ENTRY_EXPIRED( ulIPAddress ) vExampleDebugStatUpdate( iptraceID_ARP_TABLE_ENTRY_EXPIRED, 0 )
|
||||
#define iptracePACKET_DROPPED_TO_GENERATE_ARP( ulIPAddress ) vExampleDebugStatUpdate( iptraceID_PACKET_DROPPED_TO_GENERATE_ARP, 0 )
|
||||
#define iptraceFAILED_TO_CREATE_SOCKET() vExampleDebugStatUpdate( iptraceID_FAILED_TO_CREATE_SOCKET, 0 )
|
||||
#define iptraceRECVFROM_DISCARDING_BYTES( xNumberOfBytesDiscarded ) vExampleDebugStatUpdate( iptraceID_RECVFROM_DISCARDING_BYTES, 0 )
|
||||
#define iptraceETHERNET_RX_EVENT_LOST() vExampleDebugStatUpdate( iptraceID_ETHERNET_RX_EVENT_LOST, 0 )
|
||||
#define iptraceSTACK_TX_EVENT_LOST( xEvent ) vExampleDebugStatUpdate( iptraceID_STACK_TX_EVENT_LOST, 0 )
|
||||
#define iptraceBIND_FAILED( xSocket, usPort ) vExampleDebugStatUpdate( ipconfigID_BIND_FAILED, 0 )
|
||||
#define iptraceNETWORK_INTERFACE_TRANSMIT() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_TRANSMIT, 0 )
|
||||
#define iptraceRECVFROM_TIMEOUT() vExampleDebugStatUpdate( iptraceID_RECVFROM_TIMEOUT, 0 )
|
||||
#define iptraceSENDTO_DATA_TOO_LONG() vExampleDebugStatUpdate( iptraceID_SENDTO_DATA_TOO_LONG, 0 )
|
||||
#define iptraceSENDTO_SOCKET_NOT_BOUND() vExampleDebugStatUpdate( iptraceID_SENDTO_SOCKET_NOT_BOUND, 0 )
|
||||
#define iptraceNO_BUFFER_FOR_SENDTO() vExampleDebugStatUpdate( iptraceID_NO_BUFFER_FOR_SENDTO, 0 )
|
||||
#define iptraceWAITING_FOR_TX_DMA_DESCRIPTOR() vExampleDebugStatUpdate( iptraceID_WAIT_FOR_TX_DMA_DESCRIPTOR, 0 )
|
||||
#define iptraceFAILED_TO_NOTIFY_SELECT_GROUP( xSocket ) vExampleDebugStatUpdate( iptraceID_FAILED_TO_NOTIFY_SELECT_GROUP, 0 )
|
||||
#define iptraceNETWORK_INTERFACE_RECEIVE() vExampleDebugStatUpdate( iptraceID_NETWORK_INTERFACE_RECEIVE, 0 )
|
||||
|
||||
/*
|
||||
* The function that updates a line in the xIPTraceValues table.
|
||||
*/
|
||||
void vExampleDebugStatUpdate( uint8_t ucIdentifier, uint32_t ulValue );
|
||||
|
||||
/*
|
||||
* Returns the number of entries in the xIPTraceValues table.
|
||||
*/
|
||||
BaseType_t xExampleDebugStatEntries( void );
|
||||
|
||||
#endif /* configINCLUDE_DEMO_DEBUG_STATS == 1 */
|
||||
|
||||
|
||||
#endif /* DEMO_IP_TRACE_MACROS_H */
|
||||
|
Reference in New Issue
Block a user