Add UDP demo running FreeRTOS+TCP (#425)
* Add FreeRTOS+TCP UDP only demo. * Update folder name and remove old one * Update the network interface to be used. * Update headers * Update header * Header update and folder name correction * Remove WinPCap folderpull/416/head^2
parent
eec68e8790
commit
9a452918d1
@ -0,0 +1,630 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* See the following URL for information on the commands defined in this file:
|
||||
* http://localhost/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 portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the task-stats command.
|
||||
*/
|
||||
static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-three-parameters command.
|
||||
*/
|
||||
static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the echo-parameters command.
|
||||
*/
|
||||
static portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that prints out IP address information.
|
||||
*/
|
||||
static portBASE_TYPE prvDisplayIPConfig( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that prints out the gathered demo debug stats.
|
||||
*/
|
||||
static portBASE_TYPE prvDisplayIPDebugStats( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Defines a command that sends an ICMP ping request to an IP address.
|
||||
*/
|
||||
static portBASE_TYPE prvPingCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
|
||||
/*
|
||||
* Implements the "trace start" and "trace stop" commands;
|
||||
*/
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
|
||||
#endif
|
||||
|
||||
/* Structure that defines the "ip-config" command line command. */
|
||||
static const CLI_Command_Definition_t xIPConfig =
|
||||
{
|
||||
( const int8_t * const ) "ip-config",
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "ip-debug-stats", /* The command string to type. */
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "run-time-stats", /* The command string to type. */
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "task-stats", /* The command string to type. */
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "echo-3-parameters",
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "echo-parameters",
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "ping",
|
||||
( const int8_t * const ) "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 =
|
||||
{
|
||||
( const int8_t * const ) "trace",
|
||||
( const int8_t * const ) "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( &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 portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
const int8_t *const pcHeader = ( int8_t * ) "Task State Priority Stack #\r\n************************************************\r\n";
|
||||
|
||||
/* 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( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
|
||||
vTaskList( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
const int8_t * const pcHeader = ( int8_t * ) "Task Abs Time % Time\r\n****************************************\r\n";
|
||||
|
||||
/* 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( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
|
||||
|
||||
#if ( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )
|
||||
vTaskGetRunTimeStats( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
|
||||
#endif
|
||||
|
||||
/* There is no more data to return after this single string, so return
|
||||
pdFALSE. */
|
||||
return pdFALSE;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength, xReturn;
|
||||
static portBASE_TYPE 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( ( char * ) 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 = ( int8_t * ) 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( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
|
||||
strncat( ( char * ) 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 portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE xParameterStringLength, xReturn;
|
||||
static portBASE_TYPE 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( ( char * ) 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 = ( int8_t * ) 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( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
|
||||
strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
|
||||
strncat( ( char * ) 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 portBASE_TYPE prvPingCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t * pcParameter;
|
||||
portBASE_TYPE lParameterStringLength, xReturn;
|
||||
uint32_t ulIPAddress, ulBytesToPing;
|
||||
const uint32_t ulDefaultBytesToPing = 8UL;
|
||||
int8_t 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 = ( int8_t * ) 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( ( const char * ) pcParameter );
|
||||
}
|
||||
|
||||
/* Obtain the IP address string. */
|
||||
pcParameter = ( int8_t * ) 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( ( const uint8_t * ) pcParameter );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Terminate the host name. */
|
||||
pcParameter[ lParameterStringLength ] = 0x00;
|
||||
|
||||
/* Attempt to resolve host. */
|
||||
ulIPAddress = FreeRTOS_gethostbyname( ( uint8_t * ) pcParameter );
|
||||
}
|
||||
|
||||
/* Convert IP address, which may have come from a DNS lookup, to string. */
|
||||
FreeRTOS_inet_ntoa( ulIPAddress, ( char * ) cBuffer );
|
||||
|
||||
if( ulIPAddress != 0 )
|
||||
{
|
||||
xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdFALSE;
|
||||
}
|
||||
|
||||
if( xReturn == pdFALSE )
|
||||
{
|
||||
sprintf( ( char * ) pcWriteBuffer, "%s", "Could not send ping request\r\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) 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 portBASE_TYPE prvDisplayIPDebugStats( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
static portBASE_TYPE xIndex = -1;
|
||||
extern xExampleDebugStatEntry_t xIPTraceValues[];
|
||||
portBASE_TYPE 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( ( char * ) pcWriteBuffer, "%s %d\r\n", ( char * ) 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 portBASE_TYPE prvDisplayIPConfig( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
static portBASE_TYPE xIndex = 0;
|
||||
portBASE_TYPE 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( ( char * ) pcWriteBuffer, "\r\nIP address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 1 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
|
||||
sprintf( ( char * ) pcWriteBuffer, "\r\nNet mask " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 2 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
|
||||
sprintf( ( char * ) pcWriteBuffer, "\r\nGateway address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
|
||||
sprintf( ( char * ) pcWriteBuffer, "\r\nDNS server address " );
|
||||
xReturn = pdTRUE;
|
||||
xIndex++;
|
||||
break;
|
||||
|
||||
default :
|
||||
ulAddress = 0;
|
||||
sprintf( ( char * ) pcWriteBuffer, "\r\n\r\n" );
|
||||
xReturn = pdFALSE;
|
||||
xIndex = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if( ulAddress != 0 )
|
||||
{
|
||||
FreeRTOS_inet_ntoa( ulAddress, ( ( char * ) &( pcWriteBuffer[ strlen( ( char * ) pcWriteBuffer ) ] ) ) );
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
|
||||
|
||||
static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
|
||||
{
|
||||
int8_t *pcParameter;
|
||||
portBASE_TYPE 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 = ( int8_t * ) 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( ( const char * ) pcParameter, "start", strlen( "start" ) ) == 0 )
|
||||
{
|
||||
/* Start or restart the trace. */
|
||||
vTraceStop();
|
||||
vTraceClear();
|
||||
vTraceStart();
|
||||
|
||||
sprintf( ( char * ) pcWriteBuffer, "Trace recording (re)started.\r\n" );
|
||||
}
|
||||
else if( strncmp( ( const char * ) pcParameter, "stop", strlen( "stop" ) ) == 0 )
|
||||
{
|
||||
/* End the trace, if one is running. */
|
||||
vTraceStop();
|
||||
sprintf( ( char * ) pcWriteBuffer, "Stopping trace recording.\r\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( ( char * ) 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,352 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
/* FreeRTOS+UDP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
#define simpTINY_DELAY ( ( portTickType ) 2 )
|
||||
|
||||
/*
|
||||
* Uses a socket to send data without using the zero copy option.
|
||||
* prvSimpleServerTask() will receive the data.
|
||||
*/
|
||||
static void prvSimpleClientTask( void *pvParameters );
|
||||
|
||||
/*
|
||||
* Uses a socket to receive the data sent by the prvSimpleClientTask() task.
|
||||
* Does not use the zero copy option.
|
||||
*/
|
||||
static void prvSimpleServerTask( void *pvParameters );
|
||||
|
||||
/*
|
||||
* Uses a socket to send data using the zero copy option.
|
||||
* prvSimpleZeroCopyServerTask() will receive the data.
|
||||
*/
|
||||
static void prvSimpleZeroCopyUDPClientTask( void *pvParameters );
|
||||
|
||||
/*
|
||||
* Uses a socket to receive the data sent by the prvSimpleZeroCopyUDPClientTask()
|
||||
* task. Uses the zero copy option.
|
||||
*/
|
||||
static void prvSimpleZeroCopyServerTask( void *pvParameters );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulPort, unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
/* Create the client and server tasks that do not use the zero copy
|
||||
interface. */
|
||||
xTaskCreate( prvSimpleClientTask, "SimpCpyClnt", usStackSize, ( void * ) ulPort, uxPriority, NULL );
|
||||
xTaskCreate( prvSimpleServerTask, "SimpCpySrv", usStackSize, ( void * ) ulPort, uxPriority + 1, NULL );
|
||||
|
||||
/* Create the client and server tasks that do use the zero copy interface. */
|
||||
xTaskCreate( prvSimpleZeroCopyUDPClientTask, "SimpZCpyClnt", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority, NULL );
|
||||
xTaskCreate( prvSimpleZeroCopyServerTask, "SimpZCpySrv", usStackSize, ( void * ) ( ulPort + 1 ), uxPriority + 1, NULL );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSimpleClientTask( void *pvParameters )
|
||||
{
|
||||
Socket_t xClientSocket;
|
||||
struct freertos_sockaddr xDestinationAddress;
|
||||
uint8_t cString[ 50 ];
|
||||
portBASE_TYPE lReturned;
|
||||
uint32_t ulCount = 0UL, ulIPAddress;
|
||||
const uint32_t ulLoopsPerSocket = 10UL;
|
||||
const portTickType x150ms = 150UL / portTICK_RATE_MS;
|
||||
|
||||
/* Remove compiler warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* It is assumed that this task is not created until the network is up,
|
||||
so the IP address can be obtained immediately. store the IP address being
|
||||
used in ulIPAddress. This is done so the socket can send to a different
|
||||
port on the same IP address. */
|
||||
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
|
||||
|
||||
/* This test sends to itself, so data sent from here is received by a server
|
||||
socket on the same IP address. Setup the freertos_sockaddr structure with
|
||||
this nodes IP address, and the port number being sent to. The strange
|
||||
casting is to try and remove compiler warnings on 32 bit machines. */
|
||||
xDestinationAddress.sin_addr = ulIPAddress;
|
||||
xDestinationAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
|
||||
xDestinationAddress.sin_port = FreeRTOS_htons( xDestinationAddress.sin_port );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Create the socket. */
|
||||
xClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* The count is used to differentiate between different messages sent to
|
||||
the server, and to break out of the do while loop below. */
|
||||
ulCount = 0UL;
|
||||
|
||||
do
|
||||
{
|
||||
/* Create the string that is sent to the server. */
|
||||
sprintf( ( char * ) cString, "Server received (not zero copy): Message number %lu\r\n", ulCount );
|
||||
|
||||
/* Send the string to the socket. ulFlags is set to 0, so the zero
|
||||
copy option is not selected. That means the data from cString[] is
|
||||
copied into a network buffer inside FreeRTOS_sendto(), and cString[]
|
||||
can be reused as soon as FreeRTOS_sendto() has returned. */
|
||||
lReturned = FreeRTOS_sendto( xClientSocket, ( void * ) cString, strlen( ( const char * ) cString ), 0, &xDestinationAddress, sizeof( xDestinationAddress ) );
|
||||
|
||||
ulCount++;
|
||||
|
||||
} while( ( lReturned != FREERTOS_SOCKET_ERROR ) && ( ulCount < ulLoopsPerSocket ) );
|
||||
|
||||
FreeRTOS_closesocket( xClientSocket );
|
||||
|
||||
/* A short delay to prevent the messages printed by the server task
|
||||
scrolling off the screen too quickly, and to prevent reduce the network
|
||||
loading. */
|
||||
vTaskDelay( x150ms );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSimpleServerTask( void *pvParameters )
|
||||
{
|
||||
long lBytes;
|
||||
uint8_t cReceivedString[ 60 ];
|
||||
struct freertos_sockaddr xClient, xBindAddress;
|
||||
uint32_t xClientLength = sizeof( xClient );
|
||||
Socket_t xListeningSocket;
|
||||
|
||||
/* Just to prevent compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Attempt to open the socket. */
|
||||
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* This test receives data sent from a different port on the same IP
|
||||
address. Configure the freertos_sockaddr structure with the address being
|
||||
bound to. The strange casting is to try and remove compiler warnings on 32
|
||||
bit machines. Note that this task is only created after the network is up,
|
||||
so the IP address is valid here. */
|
||||
xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
|
||||
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
|
||||
|
||||
/* Bind the socket to the port that the client task will send to. */
|
||||
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Zero out the receive array so there is NULL at the end of the string
|
||||
when it is printed out. */
|
||||
memset( cReceivedString, 0x00, sizeof( cReceivedString ) );
|
||||
|
||||
/* Receive data on the socket. ulFlags is zero, so the zero copy option
|
||||
is not set and the received data is copied into the buffer pointed to by
|
||||
cReceivedString. By default the block time is portMAX_DELAY.
|
||||
xClientLength is not actually used by FreeRTOS_recvfrom(), but is set
|
||||
appropriately in case future versions do use it. */
|
||||
lBytes = FreeRTOS_recvfrom( xListeningSocket, cReceivedString, sizeof( cReceivedString ), 0, &xClient, &xClientLength );
|
||||
|
||||
/* Print the received characters. */
|
||||
if( lBytes > 0 )
|
||||
{
|
||||
FreeRTOS_debug_printf( ( ( char * ) cReceivedString ) );
|
||||
}
|
||||
|
||||
/* Error check. */
|
||||
configASSERT( lBytes == ( portBASE_TYPE ) strlen( ( const char * ) cReceivedString ) );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSimpleZeroCopyUDPClientTask( void *pvParameters )
|
||||
{
|
||||
Socket_t xClientSocket;
|
||||
uint8_t *pucUDPPayloadBuffer;
|
||||
struct freertos_sockaddr xDestinationAddress;
|
||||
portBASE_TYPE lReturned;
|
||||
uint32_t ulCount = 0UL, ulIPAddress;
|
||||
const uint32_t ulLoopsPerSocket = 10UL;
|
||||
const uint8_t *pucStringToSend = ( const uint8_t * ) "Server received (using zero copy): Message number ";
|
||||
const portTickType x150ms = 150UL / portTICK_RATE_MS;
|
||||
/* 15 is added to ensure the number, \r\n and terminating zero fit. */
|
||||
const size_t xStringLength = strlen( ( char * ) pucStringToSend ) + 15;
|
||||
|
||||
/* Remove compiler warning about unused parameters. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* It is assumed that this task is not created until the network is up,
|
||||
so the IP address can be obtained immediately. store the IP address being
|
||||
used in ulIPAddress. This is done so the socket can send to a different
|
||||
port on the same IP address. */
|
||||
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
|
||||
|
||||
/* This test sends to itself, so data sent from here is received by a server
|
||||
socket on the same IP address. Setup the freertos_sockaddr structure with
|
||||
this nodes IP address, and the port number being sent to. The strange
|
||||
casting is to try and remove compiler warnings on 32 bit machines. */
|
||||
xDestinationAddress.sin_addr = ulIPAddress;
|
||||
xDestinationAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
|
||||
xDestinationAddress.sin_port = FreeRTOS_htons( xDestinationAddress.sin_port );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* Create the socket. */
|
||||
xClientSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xClientSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* The count is used to differentiate between different messages sent to
|
||||
the server, and to break out of the do while loop below. */
|
||||
ulCount = 0UL;
|
||||
|
||||
do
|
||||
{
|
||||
/* 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 into, rather than copied into, the FreeRTOS_sendto()
|
||||
function.
|
||||
|
||||
First obtain a buffer of adequate length from the IP stack into which
|
||||
the string will be written. Although a max delay is used, the actual
|
||||
delay will be capped to ipconfigMAX_SEND_BLOCK_TIME_TICKS, hence
|
||||
the do while loop is used to ensure a buffer is obtained. */
|
||||
do
|
||||
{
|
||||
} while( ( pucUDPPayloadBuffer = ( uint8_t * ) FreeRTOS_GetUDPPayloadBuffer( xStringLength, portMAX_DELAY ) ) == NULL );
|
||||
|
||||
/* A buffer was successfully obtained. Create the string that is
|
||||
sent to the server. First the string is filled with zeros as this will
|
||||
effectively be the null terminator when the string is received at the other
|
||||
end. Note that the string is being written directly into the buffer
|
||||
obtained from the IP stack above. */
|
||||
memset( ( void * ) pucUDPPayloadBuffer, 0x00, xStringLength );
|
||||
sprintf( ( char * ) pucUDPPayloadBuffer, "%s%lu\r\n", ( char * ) pucStringToSend, ulCount );
|
||||
|
||||
/* 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. */
|
||||
lReturned = FreeRTOS_sendto( xClientSocket, /* The socket being sent to. */
|
||||
( void * ) pucUDPPayloadBuffer, /* A pointer to the the data being sent. */
|
||||
strlen( ( const char * ) pucUDPPayloadBuffer ) + 1, /* The length of the data being sent - including the string's null terminator. */
|
||||
FREERTOS_ZERO_COPY, /* ulFlags with the FREERTOS_ZERO_COPY bit set. */
|
||||
&xDestinationAddress, /* Where the data is being sent. */
|
||||
sizeof( xDestinationAddress ) );
|
||||
|
||||
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 after this call. */
|
||||
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. */
|
||||
}
|
||||
|
||||
ulCount++;
|
||||
|
||||
} while( ( lReturned != FREERTOS_SOCKET_ERROR ) && ( ulCount < ulLoopsPerSocket ) );
|
||||
|
||||
FreeRTOS_closesocket( xClientSocket );
|
||||
|
||||
/* A short delay to prevent the messages scrolling off the screen too
|
||||
quickly. */
|
||||
vTaskDelay( x150ms );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
static void prvSimpleZeroCopyServerTask( void *pvParameters )
|
||||
{
|
||||
int32_t lBytes;
|
||||
uint8_t *pucUDPPayloadBuffer;
|
||||
struct freertos_sockaddr xClient, xBindAddress;
|
||||
uint32_t xClientLength = sizeof( xClient ), ulIPAddress;
|
||||
Socket_t xListeningSocket;
|
||||
|
||||
/* Just to prevent compiler warnings. */
|
||||
( void ) pvParameters;
|
||||
|
||||
/* Attempt to open the socket. */
|
||||
xListeningSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
|
||||
configASSERT( xListeningSocket != FREERTOS_INVALID_SOCKET );
|
||||
|
||||
/* This test receives data sent from a different port on the same IP address.
|
||||
Obtain the nodes IP address. Configure the freertos_sockaddr structure with
|
||||
the address being bound to. The strange casting is to try and remove
|
||||
compiler warnings on 32 bit machines. Note that this task is only created
|
||||
after the network is up, so the IP address is valid here. */
|
||||
FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
|
||||
xBindAddress.sin_addr = ulIPAddress;
|
||||
xBindAddress.sin_port = ( uint16_t ) ( ( uint32_t ) pvParameters ) & 0xffffUL;
|
||||
xBindAddress.sin_port = FreeRTOS_htons( xBindAddress.sin_port );
|
||||
|
||||
/* Bind the socket to the port that the client task will send to. */
|
||||
FreeRTOS_bind( xListeningSocket, &xBindAddress, sizeof( xBindAddress ) );
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
/* 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 block time is portMAX_DELAY. */
|
||||
lBytes = FreeRTOS_recvfrom( xListeningSocket, ( void * ) &pucUDPPayloadBuffer, 0, FREERTOS_ZERO_COPY, &xClient, &xClientLength );
|
||||
|
||||
/* It is expected to receive one more byte than the string length as
|
||||
the NULL terminator is also transmitted. */
|
||||
configASSERT( lBytes == ( ( portBASE_TYPE ) strlen( ( const char * ) pucUDPPayloadBuffer ) + 1 ) );
|
||||
|
||||
/* Print the received characters. */
|
||||
if( lBytes > 0 )
|
||||
{
|
||||
FreeRTOS_debug_printf( ( ( char * ) pucUDPPayloadBuffer ) );
|
||||
}
|
||||
|
||||
if( lBytes >= 0 )
|
||||
{
|
||||
/* The buffer *must* be freed once it is no longer needed. */
|
||||
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,397 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* 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_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* Small delay used between attempts to obtain a zero copy buffer. */
|
||||
#define echoTINY_DELAY ( ( portTickType ) 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. The delay is shorter when the Windows
|
||||
simulator is used because simulated time is slower than real time. */
|
||||
#ifdef _WINDOWS_
|
||||
#define echoLOOP_DELAY ( ( portTickType ) 10 / portTICK_RATE_MS )
|
||||
#else
|
||||
#define echoLOOP_DELAY ( ( portTickType ) 150 / portTICK_RATE_MS )
|
||||
#endif /* _WINDOWS_ */
|
||||
|
||||
#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 ( 8080 )
|
||||
|
||||
/*
|
||||
* 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 portTickType xReceiveTimeOut = 500 / portTICK_RATE_MS;
|
||||
#else
|
||||
const portTickType xReceiveTimeOut = 1000 / portTICK_RATE_MS;
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartEchoClientTasks( uint16_t usTaskStackSize, unsigned portBASE_TYPE uxTaskPriority )
|
||||
{
|
||||
/* Create the echo client task that does not use the zero copy interface. */
|
||||
xTaskCreate( prvEchoClientTask, /* The function that implements the task. */
|
||||
( const signed char * const ) "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. */
|
||||
( const signed char * const ) "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 )
|
||||
{
|
||||
Socket_t xSocket;
|
||||
struct freertos_sockaddr xEchoServerAddress;
|
||||
int8_t 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;
|
||||
int32_t lReturned;
|
||||
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( ( char * ) cTxString, "Message number %u\r\n", 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. */
|
||||
lReturned = FreeRTOS_sendto( xSocket, /* The socket being sent to. */
|
||||
( void * ) cTxString, /* The data being sent. */
|
||||
strlen( ( const char * ) cTxString ) + 1, /* The length of the data being sent. */
|
||||
0, /* ulFlags with the FREERTOS_ZERO_COPY bit clear. */
|
||||
&xEchoServerAddress, /* The destination address. */
|
||||
sizeof( xEchoServerAddress ) );
|
||||
|
||||
if( lReturned == 0 )
|
||||
{
|
||||
/* The send operation failed. */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The send was successful. */
|
||||
FreeRTOS_debug_printf( ( "[Echo Client] Data sent... \r\n" ) );
|
||||
}
|
||||
|
||||
/* 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 ) );
|
||||
lReturned = 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 );
|
||||
|
||||
if( lReturned > 0 )
|
||||
{
|
||||
/* Compare the transmitted string to the received string. */
|
||||
if( strcmp( ( char * ) cRxString, ( char * ) cTxString ) == 0 )
|
||||
{
|
||||
/* The echo reply was received without error. */
|
||||
ulRxCount++;
|
||||
FreeRTOS_debug_printf( ( "[Echo Client] Data was received correctly.\r\n" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeRTOS_debug_printf( ( "[Echo Client] Data received was erreneous.\r\n" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeRTOS_debug_printf( ( "[Echo Client] Data was not received\r\n" ) );
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 )
|
||||
{
|
||||
Socket_t xSocket;
|
||||
struct freertos_sockaddr xEchoServerAddress;
|
||||
static int8_t 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 uint8_t * const pucStringToSend = ( const uint8_t * const ) "Zero copy message number";
|
||||
/* The buffer is large enough to hold the string, a number, and the string terminator. */
|
||||
const size_t xBufferLength = strlen( ( char * ) pucStringToSend ) + 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", ( const char * ) "Zero copy message number", 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( ( char * ) 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( ( const char * ) 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. */
|
||||
FreeRTOS_debug_printf( ( "[Zero Copy] Data sent... \r\n" ) );
|
||||
}
|
||||
|
||||
/* 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, ( char * ) cTxString ) == 0 )
|
||||
{
|
||||
/* The strings matched. */
|
||||
ulRxCount++;
|
||||
FreeRTOS_debug_printf( ( "[Zero Copy] Data was received correctly.\r\n" ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeRTOS_debug_printf( ( "[Zero Copy] Data received was erreneous.\r\n" ) );
|
||||
}
|
||||
|
||||
/* The buffer that contains the data passed out of the stack
|
||||
*must* be returned to the stack. */
|
||||
FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayloadBuffer );
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeRTOS_debug_printf( ( "[Zero Copy] Data was not received\r\n" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 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,207 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/* 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_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 1024
|
||||
|
||||
/* 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 Socket_t prvOpenUDPServerSocket( uint16_t usPort );
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, unsigned portBASE_TYPE uxPriority )
|
||||
{
|
||||
xTaskCreate( vUDPCommandInterpreterTask, ( signed char * ) "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 signed char cInputString[ cmdMAX_INPUT_SIZE ], cOutputString[ cmdMAX_OUTPUT_SIZE ], cLocalBuffer[ cmdSOCKET_INPUT_BUFFER_SIZE ];
|
||||
portBASE_TYPE 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. */
|
||||
Socket_t xSocket;
|
||||
extern const uint8_t ucIPAddress[ 4 ];
|
||||
extern const uint8_t ucMACAddress[ 6 ];
|
||||
|
||||
/* 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( ( const char * ) 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 Socket_t prvOpenUDPServerSocket( uint16_t usPort )
|
||||
{
|
||||
struct freertos_sockaddr xServer;
|
||||
Socket_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,32 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_CLIENT_AND_SERVER_H
|
||||
#define SIMPLE_CLIENT_AND_SERVER_H
|
||||
|
||||
void vStartSimpleUDPClientServerTasks( uint16_t usStackSize, uint32_t ulsPort, unsigned portBASE_TYPE uxPriority );
|
||||
|
||||
#endif /* SIMPLE_CLIENT_AND_SERVER_H */
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
#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, unsigned portBASE_TYPE uxTaskPriority );
|
||||
|
||||
#endif /* TWO_ECHO_CLIENTS_H */
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UDP_COMMAND_INTERPRETER_H
|
||||
#define UDP_COMMAND_INTERPRETER_H
|
||||
|
||||
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, unsigned portBASE_TYPE uxPriority );
|
||||
|
||||
#endif /* UDP_COMMAND_INTERPRETER_H */
|
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
||||
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
||||
* http://www.freertos.org/a00110.html
|
||||
*
|
||||
* The bottom of this file contains some constants specific to running the UDP
|
||||
* stack in this demo. Constants specific to FreeRTOS+TCP itself (rather than
|
||||
* the demo) are contained in FreeRTOSIPConfig.h.
|
||||
*----------------------------------------------------------*/
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 1
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
|
||||
#define configMAX_PRIORITIES ( 7 )
|
||||
#define configTICK_RATE_HZ ( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
|
||||
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the Win32 thread. */
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2048U * 1024U ) )
|
||||
#define configMAX_TASK_NAME_LEN ( 15 )
|
||||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 0
|
||||
#define configUSE_APPLICATION_TASK_TAG 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_ALTERNATIVE_API 0
|
||||
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 3 /* FreeRTOS+FAT requires 2 pointers if a CWD is supported. */
|
||||
|
||||
/* Hook function related definitions. */
|
||||
#define configUSE_TICK_HOOK 0
|
||||
#define configUSE_IDLE_HOOK 1
|
||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 0 /* Not applicable to the Win32 port. */
|
||||
|
||||
/* Software timer related definitions. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#define configTIMER_QUEUE_LENGTH 5
|
||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
|
||||
|
||||
/* Event group related definitions. */
|
||||
#define configUSE_EVENT_GROUPS 1
|
||||
|
||||
/* Run time stats gathering definitions. */
|
||||
#define configGENERATE_RUN_TIME_STATS 0
|
||||
|
||||
/* Co-routine definitions. */
|
||||
#define configUSE_CO_ROUTINES 0
|
||||
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
|
||||
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskCleanUpResources 0
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 1
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTimerGetTimerTaskHandle 0
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 0
|
||||
#define INCLUDE_xQueueGetMutexHolder 1
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
#define INCLUDE_xEventGroupSetBitsFromISR 1
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_pcTaskGetTaskName 1
|
||||
|
||||
/* This demo makes use of one or more example stats formatting functions. These
|
||||
format the raw data provided by the uxTaskGetSystemState() function in to human
|
||||
readable ASCII form. See the notes in the implementation of vTaskList() within
|
||||
FreeRTOS/Source/tasks.c for limitations. configUSE_STATS_FORMATTING_FUNCTIONS
|
||||
is set to 2 so the formatting functions are included without the stdio.h being
|
||||
included in tasks.c. That is because this project defines its own sprintf()
|
||||
functions. */
|
||||
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
|
||||
|
||||
/* Assert call defined for debug builds. */
|
||||
#ifdef _DEBUG
|
||||
extern void vAssertCalled(const char* pcFile, uint32_t ulLine);
|
||||
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
|
||||
#endif /* _DEBUG */
|
||||
|
||||
|
||||
|
||||
/* Application specific definitions follow. **********************************/
|
||||
|
||||
/* If configINCLUDE_DEMO_DEBUG_STATS is set to one, then a few basic IP trace
|
||||
macros are defined to gather some UDP stack statistics that can then be viewed
|
||||
through the CLI interface. */
|
||||
#define configINCLUDE_DEMO_DEBUG_STATS 0
|
||||
|
||||
/* The size of the global output buffer that is available for use when there
|
||||
are multiple command interpreters running at once (for example, one on a UART
|
||||
and one on TCP/IP). This is done to prevent an output buffer being defined by
|
||||
each implementation - which would waste RAM. In this case, there is only one
|
||||
command interpreter running, and it has its own local output buffer, so the
|
||||
global buffer is just set to be one byte long as it is not used and should not
|
||||
take up unnecessary RAM. */
|
||||
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 1
|
||||
|
||||
/* Only used when running in the FreeRTOS Windows simulator. Defines the
|
||||
priority of the task used to simulate Ethernet interrupts. */
|
||||
#define configMAC_ISR_SIMULATOR_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
|
||||
/* This demo creates a virtual network connection by accessing the raw Ethernet
|
||||
or WiFi data to and from a real network connection. Many computers have more
|
||||
than one real network port, and configNETWORK_INTERFACE_TO_USE is used to tell
|
||||
the demo which real port should be used to create the virtual port. The ports
|
||||
available are displayed on the console when the application is executed. For
|
||||
example, on my development laptop setting configNETWORK_INTERFACE_TO_USE to 4
|
||||
results in the wired network being used, while setting
|
||||
configNETWORK_INTERFACE_TO_USE to 2 results in the wireless network being
|
||||
used. */
|
||||
#define configNETWORK_INTERFACE_TO_USE ( 0L )
|
||||
|
||||
/* The address of an echo server that will be used by the two demo echo client
|
||||
tasks.
|
||||
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Echo_Clients.html
|
||||
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/UDP_Echo_Clients.html */
|
||||
#define configECHO_SERVER_ADDR0 192
|
||||
#define configECHO_SERVER_ADDR1 168
|
||||
#define configECHO_SERVER_ADDR2 0
|
||||
#define configECHO_SERVER_ADDR3 17
|
||||
|
||||
/* Default MAC address configuration. The demo creates a virtual network
|
||||
connection that uses this MAC address by accessing the raw Ethernet/WiFi data
|
||||
to and from a real network connection on the host PC. See the
|
||||
configNETWORK_INTERFACE_TO_USE definition above for information on how to
|
||||
configure the real network connection to use. */
|
||||
#define configMAC_ADDR0 0x00
|
||||
#define configMAC_ADDR1 0x11
|
||||
#define configMAC_ADDR2 0x22
|
||||
#define configMAC_ADDR3 0x33
|
||||
#define configMAC_ADDR4 0x44
|
||||
#define configMAC_ADDR5 0x41
|
||||
|
||||
/* Default IP address configuration. Used in ipconfigUSE_DNS is set to 0, or
|
||||
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
|
||||
#define configIP_ADDR0 192
|
||||
#define configIP_ADDR1 168
|
||||
#define configIP_ADDR2 0
|
||||
#define configIP_ADDR3 20
|
||||
|
||||
/* Default gateway IP address configuration. Used in ipconfigUSE_DNS is set to
|
||||
0, or ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
|
||||
#define configGATEWAY_ADDR0 10
|
||||
#define configGATEWAY_ADDR1 10
|
||||
#define configGATEWAY_ADDR2 10
|
||||
#define configGATEWAY_ADDR3 1
|
||||
|
||||
/* Default DNS server configuration. OpenDNS addresses are 208.67.222.222 and
|
||||
208.67.220.220. Used if ipconfigUSE_DNS is set to 0, or ipconfigUSE_DNS is set
|
||||
to 1 but a DNS server cannot be contacted.*/
|
||||
#define configDNS_SERVER_ADDR0 208
|
||||
#define configDNS_SERVER_ADDR1 67
|
||||
#define configDNS_SERVER_ADDR2 222
|
||||
#define configDNS_SERVER_ADDR3 222
|
||||
|
||||
/* Default netmask configuration. Used in ipconfigUSE_DNS is set to 0, or
|
||||
ipconfigUSE_DNS is set to 1 but a DNS server cannot be contacted. */
|
||||
#define configNET_MASK0 255
|
||||
#define configNET_MASK1 0
|
||||
#define configNET_MASK2 0
|
||||
#define configNET_MASK3 0
|
||||
|
||||
/* The UDP port to which print messages are sent. */
|
||||
#define configPRINT_PORT ( 15000 )
|
||||
|
||||
#if( defined( _MSC_VER ) && ( _MSC_VER <= 1600 ) && !defined( snprintf ) )
|
||||
/* Map to Windows names. */
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
||||
/* Visual studio does not have an implementation of strcasecmp(). */
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define strcmpi _strcmpi
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
@ -0,0 +1,306 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* See the following URL for configuration information.
|
||||
* http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_IP_Configuration.html
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef FREERTOS_IP_CONFIG_H
|
||||
#define FREERTOS_IP_CONFIG_H
|
||||
|
||||
/* Prototype for the function used to print out. In this case it prints to the
|
||||
console before the network is connected then a UDP port after the network has
|
||||
connected. */
|
||||
extern void vLoggingPrintf(const char* pcFormatString, ...);
|
||||
|
||||
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
|
||||
1 then FreeRTOS_debug_printf should be defined to the function used to print
|
||||
out the debugging messages. */
|
||||
#define ipconfigHAS_DEBUG_PRINTF 1
|
||||
#if( ipconfigHAS_DEBUG_PRINTF == 1 )
|
||||
#define FreeRTOS_debug_printf(X) vLoggingPrintf X
|
||||
#endif
|
||||
|
||||
/* Set to 1 to print out non debugging messages, for example the output of the
|
||||
FreeRTOS_netstat() command, and ping replies. If ipconfigHAS_PRINTF is set to 1
|
||||
then FreeRTOS_printf should be set to the function used to print out the
|
||||
messages. */
|
||||
#define ipconfigHAS_PRINTF 1
|
||||
#if( ipconfigHAS_PRINTF == 1 )
|
||||
#define FreeRTOS_printf(X) vLoggingPrintf X
|
||||
#endif
|
||||
|
||||
/* Define the byte order of the target MCU (the MCU FreeRTOS+TCP is executing
|
||||
on). Valid options are pdFREERTOS_BIG_ENDIAN and pdFREERTOS_LITTLE_ENDIAN. */
|
||||
#define ipconfigBYTE_ORDER pdFREERTOS_LITTLE_ENDIAN
|
||||
|
||||
/* If the network card/driver includes checksum offloading (IP/TCP/UDP checksums)
|
||||
then set ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM to 1 to prevent the software
|
||||
stack repeating the checksum calculations. */
|
||||
#define ipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM 1
|
||||
|
||||
/* Several API's will block until the result is known, or the action has been
|
||||
performed, for example FreeRTOS_send() and FreeRTOS_recv(). The timeouts can be
|
||||
set per socket, using setsockopt(). If not set, the times below will be
|
||||
used as defaults. */
|
||||
#define ipconfigSOCK_DEFAULT_RECEIVE_BLOCK_TIME ( 5000 )
|
||||
#define ipconfigSOCK_DEFAULT_SEND_BLOCK_TIME ( 5000 )
|
||||
|
||||
/* Include support for LLMNR: Link-local Multicast Name Resolution
|
||||
(non-Microsoft) */
|
||||
#define ipconfigUSE_LLMNR ( 1 )
|
||||
|
||||
/* Include support for NBNS: NetBIOS Name Service (Microsoft) */
|
||||
#define ipconfigUSE_NBNS ( 1 )
|
||||
|
||||
/* Include support for DNS caching. For TCP, having a small DNS cache is very
|
||||
useful. When a cache is present, ipconfigDNS_REQUEST_ATTEMPTS can be kept low
|
||||
and also DNS may use small timeouts. If a DNS reply comes in after the DNS
|
||||
socket has been destroyed, the result will be stored into the cache. The next
|
||||
call to FreeRTOS_gethostbyname() will return immediately, without even creating
|
||||
a socket. */
|
||||
#define ipconfigUSE_DNS_CACHE ( 1 )
|
||||
#define ipconfigDNS_CACHE_NAME_LENGTH ( 16 )
|
||||
#define ipconfigDNS_CACHE_ENTRIES ( 4 )
|
||||
#define ipconfigDNS_REQUEST_ATTEMPTS ( 2 )
|
||||
|
||||
/* The IP stack executes it its own task (although any application task can make
|
||||
use of its services through the published sockets API). ipconfigUDP_TASK_PRIORITY
|
||||
sets the priority of the task that executes the IP stack. The priority is a
|
||||
standard FreeRTOS task priority so can take any value from 0 (the lowest
|
||||
priority) to (configMAX_PRIORITIES - 1) (the highest priority).
|
||||
configMAX_PRIORITIES is a standard FreeRTOS configuration parameter defined in
|
||||
FreeRTOSConfig.h, not FreeRTOSIPConfig.h. Consideration needs to be given as to
|
||||
the priority assigned to the task executing the IP stack relative to the
|
||||
priority assigned to tasks that use the IP stack. */
|
||||
#define ipconfigIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
|
||||
|
||||
/* The size, in words (not bytes), of the stack allocated to the FreeRTOS+TCP
|
||||
task. This setting is less important when the FreeRTOS Win32 simulator is used
|
||||
as the Win32 simulator only stores a fixed amount of information on the task
|
||||
stack. FreeRTOS includes optional stack overflow detection, see:
|
||||
http://www.freertos.org/Stacks-and-stack-overflow-checking.html */
|
||||
#define ipconfigIP_TASK_STACK_SIZE_WORDS ( configMINIMAL_STACK_SIZE * 5 )
|
||||
|
||||
/* ipconfigRAND32() is called by the IP stack to generate random numbers for
|
||||
things such as a DHCP transaction number or initial sequence number. Random
|
||||
number generation is performed via this macro to allow applications to use their
|
||||
own random number generation method. For example, it might be possible to
|
||||
generate a random number by sampling noise on an analogue input. */
|
||||
extern UBaseType_t uxRand();
|
||||
#define ipconfigRAND32() uxRand()
|
||||
|
||||
/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
|
||||
network event hook at the appropriate times. If ipconfigUSE_NETWORK_EVENT_HOOK
|
||||
is not set to 1 then the network event hook will never be called. See
|
||||
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/API/vApplicationIPNetworkEventHook.shtml
|
||||
*/
|
||||
#define ipconfigUSE_NETWORK_EVENT_HOOK 1
|
||||
|
||||
/* Sockets have a send block time attribute. If FreeRTOS_sendto() is called but
|
||||
a network buffer cannot be obtained then the calling task is held in the Blocked
|
||||
state (so other tasks can continue to executed) until either a network buffer
|
||||
becomes available or the send block time expires. If the send block time expires
|
||||
then the send operation is aborted. The maximum allowable send block time is
|
||||
capped to the value set by ipconfigMAX_SEND_BLOCK_TIME_TICKS. Capping the
|
||||
maximum allowable send block time prevents prevents a deadlock occurring when
|
||||
all the network buffers are in use and the tasks that process (and subsequently
|
||||
free) the network buffers are themselves blocked waiting for a network buffer.
|
||||
ipconfigMAX_SEND_BLOCK_TIME_TICKS is specified in RTOS ticks. A time in
|
||||
milliseconds can be converted to a time in ticks by dividing the time in
|
||||
milliseconds by portTICK_PERIOD_MS. */
|
||||
#define ipconfigUDP_MAX_SEND_BLOCK_TIME_TICKS ( 5000U / portTICK_PERIOD_MS )
|
||||
|
||||
/* If ipconfigUSE_DHCP is 1 then FreeRTOS+TCP will attempt to retrieve an IP
|
||||
address, netmask, DNS server address and gateway address from a DHCP server. If
|
||||
ipconfigUSE_DHCP is 0 then FreeRTOS+TCP will use a static IP address. The
|
||||
stack will revert to using the static IP address even when ipconfigUSE_DHCP is
|
||||
set to 1 if a valid configuration cannot be obtained from a DHCP server for any
|
||||
reason. The static configuration used is that passed into the stack by the
|
||||
FreeRTOS_IPInit() function call. */
|
||||
#define ipconfigUSE_DHCP 1
|
||||
|
||||
/* When ipconfigUSE_DHCP is set to 1, DHCP requests will be sent out at
|
||||
increasing time intervals until either a reply is received from a DHCP server
|
||||
and accepted, or the interval between transmissions reaches
|
||||
ipconfigMAXIMUM_DISCOVER_TX_PERIOD. The IP stack will revert to using the
|
||||
static IP address passed as a parameter to FreeRTOS_IPInit() if the
|
||||
re-transmission time interval reaches ipconfigMAXIMUM_DISCOVER_TX_PERIOD without
|
||||
a DHCP reply being received. */
|
||||
#define ipconfigMAXIMUM_DISCOVER_TX_PERIOD ( 120000U / portTICK_PERIOD_MS )
|
||||
|
||||
/* The ARP cache is a table that maps IP addresses to MAC addresses. The IP
|
||||
stack can only send a UDP message to a remove IP address if it knowns the MAC
|
||||
address associated with the IP address, or the MAC address of the router used to
|
||||
contact the remote IP address. When a UDP message is received from a remote IP
|
||||
address the MAC address and IP address are added to the ARP cache. When a UDP
|
||||
message is sent to a remote IP address that does not already appear in the ARP
|
||||
cache then the UDP message is replaced by a ARP message that solicits the
|
||||
required MAC address information. ipconfigARP_CACHE_ENTRIES defines the maximum
|
||||
number of entries that can exist in the ARP table at any one time. */
|
||||
#define ipconfigARP_CACHE_ENTRIES 6
|
||||
|
||||
/* ARP requests that do not result in an ARP response will be re-transmitted a
|
||||
maximum of ipconfigMAX_ARP_RETRANSMISSIONS times before the ARP request is
|
||||
aborted. */
|
||||
#define ipconfigMAX_ARP_RETRANSMISSIONS ( 5 )
|
||||
|
||||
/* ipconfigMAX_ARP_AGE defines the maximum time between an entry in the ARP
|
||||
table being created or refreshed and the entry being removed because it is stale.
|
||||
New ARP requests are sent for ARP cache entries that are nearing their maximum
|
||||
age. ipconfigMAX_ARP_AGE is specified in tens of seconds, so a value of 150 is
|
||||
equal to 1500 seconds (or 25 minutes). */
|
||||
#define ipconfigMAX_ARP_AGE 150
|
||||
|
||||
/* Implementing FreeRTOS_inet_addr() necessitates the use of string handling
|
||||
routines, which are relatively large. To save code space the full
|
||||
FreeRTOS_inet_addr() implementation is made optional, and a smaller and faster
|
||||
alternative called FreeRTOS_inet_addr_quick() is provided. FreeRTOS_inet_addr()
|
||||
takes an IP in decimal dot format (for example, "192.168.0.1") as its parameter.
|
||||
FreeRTOS_inet_addr_quick() takes an IP address as four separate numerical octets
|
||||
(for example, 192, 168, 0, 1) as its parameters. If
|
||||
ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
|
||||
FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
|
||||
not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
|
||||
#define ipconfigINCLUDE_FULL_INET_ADDR 1
|
||||
|
||||
/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
|
||||
are available to the IP stack. The total number of network buffers is limited
|
||||
to ensure the total amount of RAM that can be consumed by the IP stack is capped
|
||||
to a pre-determinable value. */
|
||||
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 60
|
||||
|
||||
/* A FreeRTOS queue is used to send events from application tasks to the IP
|
||||
stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
|
||||
be queued for processing at any one time. The event queue must be a minimum of
|
||||
5 greater than the total number of network buffers. */
|
||||
#define ipconfigEVENT_QUEUE_LENGTH ( ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS + 5 )
|
||||
|
||||
/* The address of a socket is the combination of its IP address and its port
|
||||
number. FreeRTOS_bind() is used to manually allocate a port number to a socket
|
||||
(to 'bind' the socket to a port), but manual binding is not normally necessary
|
||||
for client sockets (those sockets that initiate outgoing connections rather than
|
||||
wait for incoming connections on a known port number). If
|
||||
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 1 then calling
|
||||
FreeRTOS_sendto() on a socket that has not yet been bound will result in the IP
|
||||
stack automatically binding the socket to a port number from the range
|
||||
socketAUTO_PORT_ALLOCATION_START_NUMBER to 0xffff. If
|
||||
ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND is set to 0 then calling FreeRTOS_sendto()
|
||||
on a socket that has not yet been bound will result in the send operation being
|
||||
aborted. */
|
||||
#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1
|
||||
|
||||
/* Defines the Time To Live (TTL) values used in outgoing UDP packets. */
|
||||
#define ipconfigUDP_TIME_TO_LIVE 128
|
||||
#define ipconfigTCP_TIME_TO_LIVE 128 /* also defined in FreeRTOSIPConfigDefaults.h */
|
||||
|
||||
/* USE_TCP: Use TCP and all its features */
|
||||
#define ipconfigUSE_TCP ( 0 )
|
||||
|
||||
/* USE_WIN: Let TCP use windowing mechanism. */
|
||||
#define ipconfigUSE_TCP_WIN ( 0 )
|
||||
|
||||
/* The MTU is the maximum number of bytes the payload of a network frame can
|
||||
contain. For normal Ethernet V2 frames the maximum MTU is 1500. Setting a
|
||||
lower value can save RAM, depending on the buffer management scheme used. If
|
||||
ipconfigCAN_FRAGMENT_OUTGOING_PACKETS is 1 then (ipconfigNETWORK_MTU - 28) must
|
||||
be divisible by 8. */
|
||||
#define ipconfigNETWORK_MTU 1200U
|
||||
|
||||
/* Set ipconfigUSE_DNS to 1 to include a basic DNS client/resolver. DNS is used
|
||||
through the FreeRTOS_gethostbyname() API function. */
|
||||
#define ipconfigUSE_DNS 1
|
||||
|
||||
/* If ipconfigREPLY_TO_INCOMING_PINGS is set to 1 then the IP stack will
|
||||
generate replies to incoming ICMP echo (ping) requests. */
|
||||
#define ipconfigREPLY_TO_INCOMING_PINGS 1
|
||||
|
||||
/* If ipconfigSUPPORT_OUTGOING_PINGS is set to 1 then the
|
||||
FreeRTOS_SendPingRequest() API function is available. */
|
||||
#define ipconfigSUPPORT_OUTGOING_PINGS 0
|
||||
|
||||
/* If ipconfigSUPPORT_SELECT_FUNCTION is set to 1 then the FreeRTOS_select()
|
||||
(and associated) API function is available. */
|
||||
#define ipconfigSUPPORT_SELECT_FUNCTION 1
|
||||
|
||||
/* If ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES is set to 1 then Ethernet frames
|
||||
that are not in Ethernet II format will be dropped. This option is included for
|
||||
potential future IP stack developments. */
|
||||
#define ipconfigFILTER_OUT_NON_ETHERNET_II_FRAMES 1
|
||||
|
||||
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1 then it is the
|
||||
responsibility of the Ethernet interface to filter out packets that are of no
|
||||
interest. If the Ethernet interface does not implement this functionality, then
|
||||
set ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES to 0 to have the IP stack
|
||||
perform the filtering instead (it is much less efficient for the stack to do it
|
||||
because the packet will already have been passed into the stack). If the
|
||||
Ethernet driver does all the necessary filtering in hardware then software
|
||||
filtering can be removed by using a value other than 1 or 0. */
|
||||
#define ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES 1
|
||||
|
||||
/* The windows simulator cannot really simulate MAC interrupts, and needs to
|
||||
block occasionally to allow other tasks to run. */
|
||||
#define configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY ( 20 / portTICK_PERIOD_MS )
|
||||
|
||||
/* Advanced only: in order to access 32-bit fields in the IP packets with
|
||||
32-bit memory instructions, all packets will be stored 32-bit-aligned, plus 16-bits.
|
||||
This has to do with the contents of the IP-packets: all 32-bit fields are
|
||||
32-bit-aligned, plus 16-bit(!) */
|
||||
#define ipconfigPACKET_FILLER_SIZE 2U
|
||||
|
||||
/* Define the size of the pool of TCP window descriptors. On the average, each
|
||||
TCP socket will use up to 2 x 6 descriptors, meaning that it can have 2 x 6
|
||||
outstanding packets (for Rx and Tx). When using up to 10 TP sockets
|
||||
simultaneously, one could define TCP_WIN_SEG_COUNT as 120. */
|
||||
#define ipconfigTCP_WIN_SEG_COUNT 240
|
||||
|
||||
/* Each TCP socket has a circular buffers for Rx and Tx, which have a fixed
|
||||
maximum size. Define the size of Rx buffer for TCP sockets. */
|
||||
#define ipconfigTCP_RX_BUFFER_LENGTH ( 1000 )
|
||||
|
||||
/* Define the size of Tx buffer for TCP sockets. */
|
||||
#define ipconfigTCP_TX_BUFFER_LENGTH ( 1000 )
|
||||
|
||||
/* When using call-back handlers, the driver may check if the handler points to
|
||||
real program memory (RAM or flash) or just has a random non-zero value. */
|
||||
#define ipconfigIS_VALID_PROG_ADDRESS(x) ( (x) != NULL )
|
||||
|
||||
/* Include support for TCP hang protection. All sockets in a connecting or
|
||||
disconnecting stage will timeout after a period of non-activity. */
|
||||
#define ipconfigTCP_HANG_PROTECTION ( 1 )
|
||||
#define ipconfigTCP_HANG_PROTECTION_TIME ( 30 )
|
||||
|
||||
/* Include support for TCP keep-alive messages. */
|
||||
#define ipconfigTCP_KEEP_ALIVE ( 1 )
|
||||
#define ipconfigTCP_KEEP_ALIVE_INTERVAL ( 20 ) /* in seconds */
|
||||
|
||||
#define portINLINE __inline
|
||||
|
||||
#endif /* FREERTOS_IP_CONFIG_H */
|
Binary file not shown.
@ -0,0 +1,11 @@
|
||||
This demo is documented on the following web page:
|
||||
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/RTOS_UDP_CLI_Windows_Simulator.shtml
|
||||
|
||||
The FreeRTOS+UDP API is documented on the following web page:
|
||||
http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/FreeRTOS_UDP_API_Functions.shtml
|
||||
|
||||
Other information, including a FreeRTOS+UDP primer, a description of the
|
||||
directory structure, and a glossary of networking terminology, can be found in
|
||||
the FreeRTOS+UDP portal:
|
||||
http://www.FreeRTOS.org/udp
|
||||
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Utility functions required to gather run time statistics. See:
|
||||
* http://www.freertos.org/rtos-run-time-stats.html
|
||||
*
|
||||
* Note that this is a simulated port, where simulated time is a lot slower than
|
||||
* real time, therefore the run time counter values have no real meaningful
|
||||
* units.
|
||||
*
|
||||
* Also note that it is assumed this demo is going to be used for short periods
|
||||
* of time only, and therefore timer overflows are not handled.
|
||||
*/
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
/* Variables used in the creation of the run time stats time base. Run time
|
||||
stats record how much time each task spends in the Running state. */
|
||||
static long long llInitialRunTimeCounterValue = 0LL, llTicksPerHundedthMillisecond = 0LL;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vConfigureTimerForRunTimeStats( void )
|
||||
{
|
||||
LARGE_INTEGER liPerformanceCounterFrequency, liInitialRunTimeValue;
|
||||
|
||||
/* Initialise the variables used to create the run time stats time base.
|
||||
Run time stats record how much time each task spends in the Running
|
||||
state. */
|
||||
|
||||
if( QueryPerformanceFrequency( &liPerformanceCounterFrequency ) == 0 )
|
||||
{
|
||||
llTicksPerHundedthMillisecond = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* How many times does the performance counter increment in 1/100th
|
||||
millisecond. */
|
||||
llTicksPerHundedthMillisecond = liPerformanceCounterFrequency.QuadPart / 100000LL;
|
||||
|
||||
/* What is the performance counter value now, this will be subtracted
|
||||
from readings taken at run time. */
|
||||
QueryPerformanceCounter( &liInitialRunTimeValue );
|
||||
llInitialRunTimeCounterValue = liInitialRunTimeValue.QuadPart;
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
unsigned long ulGetRunTimeCounterValue( void )
|
||||
{
|
||||
LARGE_INTEGER liCurrentCount;
|
||||
unsigned long ulReturn;
|
||||
|
||||
/* What is the performance counter value now? */
|
||||
QueryPerformanceCounter( &liCurrentCount );
|
||||
|
||||
/* Subtract the performance counter value reading taken when the
|
||||
application started to get a count from that reference point, then
|
||||
scale to (simulated) 1/100ths of a millisecond. */
|
||||
ulReturn = ( unsigned long ) ( ( liCurrentCount.QuadPart - llInitialRunTimeCounterValue ) / llTicksPerHundedthMillisecond );
|
||||
|
||||
return ulReturn;
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
@ -0,0 +1,212 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Demo App Source">
|
||||
<UniqueIdentifier>{34567deb-d5ab-4a56-8640-0aaec609521a}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS">
|
||||
<UniqueIdentifier>{af3445a1-4908-4170-89ed-39345d90d30c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+">
|
||||
<UniqueIdentifier>{e5ad4ec7-23dc-4295-8add-2acaee488f5a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+CLI">
|
||||
<UniqueIdentifier>{fd43c0ed-fdbc-437f-a5a3-c50399690bd7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Demo App Source\DemoTasks">
|
||||
<UniqueIdentifier>{b71e974a-9f28-4815-972b-d930ba8a34d0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Demo App Source\Configuration Files">
|
||||
<UniqueIdentifier>{19ff1a34-36de-4c48-9d10-3fb1fa0d1fa4}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP">
|
||||
<UniqueIdentifier>{8672fa26-b119-481f-8b8d-086419c01a3e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP\include">
|
||||
<UniqueIdentifier>{5d93ed51-023a-41ad-9243-8d230165d34b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS\include">
|
||||
<UniqueIdentifier>{efdc091e-3412-4dbe-a7c3-f660d1cf75e8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS\portable">
|
||||
<UniqueIdentifier>{822b2cba-7de8-4a4b-9b44-c819647cdeb7}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP\portable">
|
||||
<UniqueIdentifier>{cb5941d0-6158-48ca-b76e-a922c037fe93}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP\portable\NetworkInterface">
|
||||
<UniqueIdentifier>{60d4e26e-d730-4d65-b64c-347fee222b9a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP\portable\BufferManagement">
|
||||
<UniqueIdentifier>{c86a0d3c-216d-4259-b770-21678dd82ea2}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="FreeRTOS+\FreeRTOS+TCP\portable\Compiler">
|
||||
<UniqueIdentifier>{e2273fad-c964-49fb-ba24-046e2095064c}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.c">
|
||||
<Filter>Demo App Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Run-time-stats-utils.c">
|
||||
<Filter>Demo App Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DemoTasks\SimpleClientAndServer.c">
|
||||
<Filter>Demo App Source\DemoTasks</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DemoTasks\UDPCommandServer.c">
|
||||
<Filter>Demo App Source\DemoTasks</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-CLI\FreeRTOS_CLI.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+CLI</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_ARP.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_DHCP.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_DNS.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_IP.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_Sockets.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_Stream_Buffer.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_TCP_IP.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_TCP_WIN.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\croutine.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\event_groups.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\list.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\queue.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\stream_buffer.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\tasks.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\timers.c">
|
||||
<Filter>FreeRTOS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\portable\MemMang\heap_4.c">
|
||||
<Filter>FreeRTOS\portable</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\FreeRTOS\Source\portable\MSVC-MingW\port.c">
|
||||
<Filter>FreeRTOS\portable</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\portable\NetworkInterface</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\portable\BufferManagement</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DemoTasks\TwoEchoClients.c">
|
||||
<Filter>Demo App Source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="DemoTasks\CLI-commands.c">
|
||||
<Filter>Demo App Source\DemoTasks</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Common\Logging\windows\Logging_WinSim.c">
|
||||
<Filter>Demo App Source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="FreeRTOSConfig.h">
|
||||
<Filter>Demo App Source\Configuration Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="FreeRTOSIPConfig.h">
|
||||
<Filter>Demo App Source\Configuration Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_ARP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_DHCP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_DNS.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_errno_TCP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_IP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_IP_Private.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_Sockets.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_Stream_Buffer.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_TCP_IP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_TCP_WIN.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOS_UDP_IP.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\FreeRTOSIPConfigDefaults.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\IPTraceMacroDefaults.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\NetworkBufferManagement.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\include\event_groups.h">
|
||||
<Filter>FreeRTOS\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\include\FreeRTOS.h">
|
||||
<Filter>FreeRTOS\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\include\list.h">
|
||||
<Filter>FreeRTOS\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\include\queue.h">
|
||||
<Filter>FreeRTOS\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\include\semphr.h">
|
||||
<Filter>FreeRTOS\include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\FreeRTOS\Source\portable\MSVC-MingW\portmacro.h">
|
||||
<Filter>FreeRTOS\portable</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC\pack_struct_end.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\portable\Compiler</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC\pack_struct_start.h">
|
||||
<Filter>FreeRTOS+\FreeRTOS+TCP\portable\Compiler</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
@ -0,0 +1,365 @@
|
||||
/*
|
||||
* FreeRTOS V202011.00
|
||||
* Copyright (C) 2020 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.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include <FreeRTOS.h>
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
#include "semphr.h"
|
||||
|
||||
/* Demo application includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
#include "SimpleClientAndServer.h"
|
||||
#include "TwoEchoClients.h"
|
||||
#include "UDPCommandInterpreter.h"
|
||||
#include "logging.h"
|
||||
|
||||
/* UDP command server task parameters. */
|
||||
#define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
||||
#define mainUDP_CLI_PORT_NUMBER ( 5001UL )
|
||||
#define mainUDP_CLI_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
|
||||
|
||||
/* Simple UDP client and server task parameters. */
|
||||
#define mainSIMPLE_CLIENT_SERVER_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
||||
#define mainSIMPLE_CLIENT_SERVER_PORT ( 5005UL )
|
||||
#define mainSIMPLE_CLIENT_SERVER_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE )
|
||||
|
||||
/* Echo client task parameters. */
|
||||
#define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
|
||||
#define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
|
||||
|
||||
/* Set the following constants to 1 or 0 to define which tasks to include and
|
||||
exclude. */
|
||||
#define mainCREATE_UDP_CLI_TASKS 1
|
||||
#define mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS 0
|
||||
#define mainCREATE_UDP_ECHO_TASKS 1
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/*
|
||||
* Register commands that can be used with FreeRTOS+CLI through the UDP socket.
|
||||
* The commands are defined in CLI-commands.c.
|
||||
*/
|
||||
extern void vRegisterCLICommands( void );
|
||||
|
||||
/* The default IP and MAC address used by the demo. The address configuration
|
||||
defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
|
||||
1 but a DHCP server could not be contacted. See the online documentation for
|
||||
more information. */
|
||||
static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
|
||||
static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
|
||||
static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
|
||||
static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
|
||||
|
||||
/* Default MAC address configuration. The demo creates a virtual network
|
||||
connection that uses this MAC address by accessing the raw Ethernet data
|
||||
to and from a real network connection on the host PC. See the
|
||||
configNETWORK_INTERFACE_TO_USE definition for information on how to configure
|
||||
the real network connection to use. */
|
||||
const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
|
||||
|
||||
/* Used to guard prints to the console. */
|
||||
static xSemaphoreHandle xConsoleMutex = NULL;
|
||||
|
||||
/* Set the following constant to pdTRUE to log using the method indicated by the
|
||||
* name of the constant, or pdFALSE to not log using the method indicated by the
|
||||
* name of the constant. Options include to standard out (xLogToStdout), to a disk
|
||||
* file (xLogToFile), and to a UDP port (xLogToUDP). If xLogToUDP is set to pdTRUE
|
||||
* then UDP messages are sent to the IP address configured as the echo server
|
||||
* address (see the configECHO_SERVER_ADDR0 definitions in FreeRTOSConfig.h) and
|
||||
* the port number set by configPRINT_PORT in FreeRTOSConfig.h. */
|
||||
const BaseType_t xLogToStdout = pdTRUE, xLogToFile = pdFALSE, xLogToUDP = pdFALSE;
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Define a name that will be used for LLMNR and NBNS searches. */
|
||||
#define mainHOST_NAME "RTOSDemo"
|
||||
#define mainDEVICE_NICK_NAME "windows_demo"
|
||||
|
||||
/* Used by the pseudo random number generator. */
|
||||
static UBaseType_t ulNextRand;
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* See the following web page for information on using this demo.
|
||||
* http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/RTOS_UDP_CLI_Windows_Simulator.shtml
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
int main( void )
|
||||
{
|
||||
const uint32_t ulLongTime_ms = 250UL;
|
||||
|
||||
/* Create a mutex that is used to guard against the console being accessed
|
||||
by more than one task simultaniously. */
|
||||
xConsoleMutex = xSemaphoreCreateMutex();
|
||||
|
||||
/* Initialise the network interface. Tasks that use the network are
|
||||
created in the network event hook when the network is connected and ready
|
||||
for use. The address values passed in here are used if ipconfigUSE_DHCP is
|
||||
set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
|
||||
contacted. */
|
||||
FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
|
||||
|
||||
/* Initialise the logging. */
|
||||
uint32_t ulLoggingIPAddress;
|
||||
|
||||
ulLoggingIPAddress = FreeRTOS_inet_addr_quick( configECHO_SERVER_ADDR0,
|
||||
configECHO_SERVER_ADDR1,
|
||||
configECHO_SERVER_ADDR2,
|
||||
configECHO_SERVER_ADDR3 );
|
||||
vLoggingInit( xLogToStdout, xLogToFile, xLogToUDP, ulLoggingIPAddress, configPRINT_PORT );
|
||||
|
||||
|
||||
/* Register commands with the FreeRTOS+CLI command interpreter. */
|
||||
vRegisterCLICommands();
|
||||
|
||||
/* Start the RTOS scheduler. */
|
||||
vTaskStartScheduler();
|
||||
|
||||
/* If all is well, the scheduler will now be running, and the following
|
||||
line will never be reached. If the following line does execute, then
|
||||
there was insufficient FreeRTOS heap memory available for the idle and/or
|
||||
timer tasks to be created. See the memory management section on the
|
||||
FreeRTOS web site for more details (this is standard text that is not not
|
||||
really applicable to the Win32 simulator port). */
|
||||
for( ;; )
|
||||
{
|
||||
Sleep( ulLongTime_ms );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vApplicationIdleHook( void )
|
||||
{
|
||||
const unsigned long ulMSToSleep = 5;
|
||||
|
||||
/* This function is called on each cycle of the idle task if
|
||||
configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. Sleep to reduce CPU
|
||||
load. */
|
||||
Sleep( ulMSToSleep );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vAssertCalled( void )
|
||||
{
|
||||
const unsigned long ulLongSleep = 1000UL;
|
||||
volatile uint32_t ulBlockVariable = 0UL;
|
||||
|
||||
/* Setting ulBlockVariable to a non-zero value in the debugger will allow
|
||||
this function to be exited. */
|
||||
taskDISABLE_INTERRUPTS();
|
||||
{
|
||||
while( ulBlockVariable == 0UL )
|
||||
{
|
||||
Sleep( ulLongSleep );
|
||||
}
|
||||
}
|
||||
taskENABLE_INTERRUPTS();
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Called by FreeRTOS+TCP when the network connects. */
|
||||
void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
|
||||
{
|
||||
uint32_t ulIPAddress, ulNetMask, ulGatewayAddress, ulDNSServerAddress;
|
||||
int8_t cBuffer[ 16 ];
|
||||
static BaseType_t xTasksAlreadyCreated = pdFALSE;
|
||||
|
||||
if( eNetworkEvent == eNetworkUp )
|
||||
{
|
||||
/* Create the tasks that use the IP stack if they have not already been
|
||||
created. */
|
||||
if( xTasksAlreadyCreated == pdFALSE )
|
||||
{
|
||||
#if( mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS == 1 )
|
||||
{
|
||||
/* Create tasks that demonstrate sending and receiving in both
|
||||
standard and zero copy mode. */
|
||||
vStartSimpleUDPClientServerTasks( mainSIMPLE_CLIENT_SERVER_TASK_STACK_SIZE, mainSIMPLE_CLIENT_SERVER_PORT, mainSIMPLE_CLIENT_SERVER_TASK_PRIORITY );
|
||||
}
|
||||
#endif /* mainCREATE_SIMPLE_UDP_CLIENT_SERVER_TASKS */
|
||||
|
||||
#if( mainCREATE_UDP_ECHO_TASKS == 1 )
|
||||
{
|
||||
/* Create the tasks that transmit to and receive from a standard
|
||||
echo server (see the web documentation for this port) in both
|
||||
standard and zero copy mode. */
|
||||
vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
|
||||
}
|
||||
#endif /* mainCREATE_UDP_ECHO_TASKS */
|
||||
|
||||
#if( mainCREATE_UDP_CLI_TASKS == 1 )
|
||||
{
|
||||
/* Create the task that handles the CLI on a UDP port. The port number
|
||||
is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
|
||||
vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY );
|
||||
}
|
||||
#endif /* mainCREATE_UDP_CLI_TASKS */
|
||||
|
||||
xTasksAlreadyCreated = pdTRUE;
|
||||
}
|
||||
|
||||
/* Print out the network configuration, which may have come from a DHCP
|
||||
server. */
|
||||
FreeRTOS_GetAddressConfiguration( &ulIPAddress, &ulNetMask, &ulGatewayAddress, &ulDNSServerAddress );
|
||||
FreeRTOS_debug_printf( ( "IP Address: " ) );
|
||||
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
|
||||
FreeRTOS_debug_printf( ( ( char * ) cBuffer ) );
|
||||
FreeRTOS_debug_printf( ( "\r\nSubnet Mask: " ) );
|
||||
FreeRTOS_inet_ntoa( ulNetMask, cBuffer );
|
||||
FreeRTOS_debug_printf( ( ( char * ) cBuffer ) );
|
||||
FreeRTOS_debug_printf( ( "\r\nGateway Address: " ) );
|
||||
FreeRTOS_inet_ntoa( ulGatewayAddress, cBuffer );
|
||||
FreeRTOS_debug_printf( ( ( char * ) cBuffer ) );
|
||||
FreeRTOS_debug_printf( ( "\r\nDNS Server Address: " ) );
|
||||
FreeRTOS_inet_ntoa( ulDNSServerAddress, cBuffer );
|
||||
FreeRTOS_debug_printf( ( ( char * ) cBuffer ) );
|
||||
FreeRTOS_debug_printf( ( "\r\n\r\n" ) );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/* Called automatically when a reply to an outgoing ping is received. */
|
||||
void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
|
||||
{
|
||||
static const uint8_t *pcSuccess = ( uint8_t * ) "Ping reply received - ";
|
||||
static const uint8_t *pcInvalidChecksum = ( uint8_t * ) "Ping reply received with invalid checksum - ";
|
||||
static const uint8_t *pcInvalidData = ( uint8_t * ) "Ping reply received with invalid data - ";
|
||||
static uint8_t cMessage[ 50 ];
|
||||
|
||||
|
||||
switch( eStatus )
|
||||
{
|
||||
case eSuccess :
|
||||
FreeRTOS_debug_printf( ( ( char * ) pcSuccess ) );
|
||||
break;
|
||||
|
||||
case eInvalidChecksum :
|
||||
FreeRTOS_debug_printf( ( ( char * ) pcInvalidChecksum ) );
|
||||
break;
|
||||
|
||||
case eInvalidData :
|
||||
FreeRTOS_debug_printf( ( ( char * ) pcInvalidData ) );
|
||||
break;
|
||||
|
||||
default :
|
||||
/* It is not possible to get here as all enums have their own
|
||||
case. */
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf( ( char * ) cMessage, "identifier %d\r\n", ( int ) usIdentifier );
|
||||
FreeRTOS_debug_printf( ( ( char * ) cMessage ) );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vApplicationMallocFailedHook( void )
|
||||
{
|
||||
/* vApplicationMallocFailedHook() will only be called if
|
||||
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
|
||||
function that will get called if a call to pvPortMalloc() fails.
|
||||
pvPortMalloc() is called internally by the kernel whenever a task, queue,
|
||||
timer or semaphore is created. It is also called by various parts of the
|
||||
demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
|
||||
size of the heap available to pvPortMalloc() is defined by
|
||||
configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
|
||||
API function can be used to query the size of free heap space that remains
|
||||
(although it does not provide information on how the remaining heap might
|
||||
be fragmented). */
|
||||
taskDISABLE_INTERRUPTS();
|
||||
for( ;; );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) || ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
|
||||
|
||||
const char * pcApplicationHostnameHook( void )
|
||||
{
|
||||
/* Assign the name "FreeRTOS" to this network node. This function will
|
||||
* be called during the DHCP: the machine will be registered with an IP
|
||||
* address plus this name. */
|
||||
return mainHOST_NAME;
|
||||
}
|
||||
|
||||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 )
|
||||
|
||||
BaseType_t xApplicationDNSQueryHook( const char * pcName )
|
||||
{
|
||||
BaseType_t xReturn;
|
||||
|
||||
/* Determine if a name lookup is for this node. Two names are given
|
||||
* to this node: that returned by pcApplicationHostnameHook() and that set
|
||||
* by mainDEVICE_NICK_NAME. */
|
||||
if( _stricmp( pcName, pcApplicationHostnameHook() ) == 0 )
|
||||
{
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else if( _stricmp( pcName, mainDEVICE_NICK_NAME ) == 0 )
|
||||
{
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
else
|
||||
{
|
||||
xReturn = pdFAIL;
|
||||
}
|
||||
|
||||
return xReturn;
|
||||
}
|
||||
|
||||
#endif /* if ( ipconfigUSE_LLMNR != 0 ) || ( ipconfigUSE_NBNS != 0 ) */
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
UBaseType_t uxRand( void )
|
||||
{
|
||||
const uint32_t ulMultiplier = 0x015a4e35UL, ulIncrement = 1UL;
|
||||
|
||||
/* Utility function to generate a pseudo random number. */
|
||||
|
||||
ulNextRand = ( ulMultiplier * ulNextRand ) + ulIncrement;
|
||||
return( ( int ) ( ulNextRand >> 16UL ) & 0x7fffUL );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Supply a random number to FreeRTOS+TCP stack.
|
||||
* THIS IS ONLY A DUMMY IMPLEMENTATION THAT RETURNS A PSEUDO RANDOM NUMBER
|
||||
* SO IS NOT INTENDED FOR USE IN PRODUCTION SYSTEMS.
|
||||
*/
|
||||
BaseType_t xApplicationGetRandomNumber( uint32_t * pulNumber )
|
||||
{
|
||||
*( pulNumber ) = uxRand();
|
||||
return pdTRUE;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
FreeRTOS+UDP was removed in FreeRTOS V10.1.0 as it was replaced by FreeRTOS+TCP,
|
||||
which was brought into the main download in FreeRTOS V10.0.0. FreeRTOS+TCP can
|
||||
be configured as a UDP only stack, and FreeRTOS+UDP does not contain the patches
|
||||
applied to FreeRTOS+TCP.
|
@ -1,5 +0,0 @@
|
||||
[{000214A0-0000-0000-C000-000000000046}]
|
||||
Prop3=19,2
|
||||
[InternetShortcut]
|
||||
URL=http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
|
||||
IDList=
|
Loading…
Reference in New Issue