mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-11 06:05:18 -05:00
Added support for static memory allocation in FreeRTOS-Plus-CLI (#983)
* Added support for static memory allocation in FreeRTOS-Plus-CLI * Removed relative include path * removed whitespace changes * Removed whitespace changes * Code review suggestions Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> * Fix spell check Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> --------- Signed-off-by: Gaurav Aggarwal <aggarg@amazon.com> Co-authored-by: Marc-André Harvey <marc-andre.harvey@d-ta.com> Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Co-authored-by: Gaurav Aggarwal <aggarg@amazon.com>
This commit is contained in:
parent
1309654d6f
commit
4727d6b3cc
3 changed files with 101 additions and 58 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS+CLI V1.0.4
|
* FreeRTOS V202212.00
|
||||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* 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
|
* 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
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* https://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* https://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
/* If the application writer needs to place the buffer used by the CLI at a
|
/* If the application writer needs to place the buffer used by the CLI at a
|
||||||
fixed address then set configAPPLICATION_PROVIDES_cOutputBuffer to 1 in
|
fixed address then set configAPPLICATION_PROVIDES_cOutputBuffer to 1 in
|
||||||
FreeRTOSConfig.h, then declare an array with the following name and size in
|
FreeRTOSConfig.h, then declare an array with the following name and size in
|
||||||
one of the application files:
|
one of the application files:
|
||||||
char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
|
char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
|
||||||
*/
|
*/
|
||||||
|
|
@ -45,11 +45,15 @@ one of the application files:
|
||||||
#define configAPPLICATION_PROVIDES_cOutputBuffer 0
|
#define configAPPLICATION_PROVIDES_cOutputBuffer 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct xCOMMAND_INPUT_LIST
|
/*
|
||||||
{
|
* Register the command passed in using the pxCommandToRegister parameter
|
||||||
const CLI_Command_Definition_t *pxCommandLineDefinition;
|
* and using pxCliDefinitionListItemBuffer as the memory for command line
|
||||||
struct xCOMMAND_INPUT_LIST *pxNext;
|
* list items. Registering a command adds the command to the list of
|
||||||
} CLI_Definition_List_Item_t;
|
* commands that are handled by the command interpreter. Once a command
|
||||||
|
* has been registered it can be executed from the command line.
|
||||||
|
*/
|
||||||
|
static void prvRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister,
|
||||||
|
CLI_Definition_List_Item_t * pxCliDefinitionListItemBuffer );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The callback function that is executed when "help" is entered. This is the
|
* The callback function that is executed when "help" is entered. This is the
|
||||||
|
|
@ -101,45 +105,47 @@ buffer needs to be placed at a fixed address (rather than by the linker). */
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
|
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
||||||
{
|
|
||||||
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
|
|
||||||
CLI_Definition_List_Item_t *pxNewListItem;
|
|
||||||
BaseType_t xReturn = pdFAIL;
|
|
||||||
|
|
||||||
/* Check the parameter is not NULL. */
|
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
|
||||||
configASSERT( pxCommandToRegister );
|
|
||||||
|
|
||||||
/* Create a new list item that will reference the command being registered. */
|
|
||||||
pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
|
|
||||||
configASSERT( pxNewListItem );
|
|
||||||
|
|
||||||
if( pxNewListItem != NULL )
|
|
||||||
{
|
{
|
||||||
taskENTER_CRITICAL();
|
BaseType_t xReturn = pdFAIL;
|
||||||
|
CLI_Definition_List_Item_t *pxNewListItem;
|
||||||
|
|
||||||
|
/* Check the parameter is not NULL. */
|
||||||
|
configASSERT( pxCommandToRegister != NULL );
|
||||||
|
|
||||||
|
/* Create a new list item that will reference the command being registered. */
|
||||||
|
pxNewListItem = ( CLI_Definition_List_Item_t * ) pvPortMalloc( sizeof( CLI_Definition_List_Item_t ) );
|
||||||
|
configASSERT( pxNewListItem != NULL );
|
||||||
|
|
||||||
|
if( pxNewListItem != NULL )
|
||||||
{
|
{
|
||||||
/* Reference the command being registered from the newly created
|
prvRegisterCommand( pxCommandToRegister, pxNewListItem );
|
||||||
list item. */
|
xReturn = pdPASS;
|
||||||
pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
|
|
||||||
|
|
||||||
/* The new list item will get added to the end of the list, so
|
|
||||||
pxNext has nowhere to point. */
|
|
||||||
pxNewListItem->pxNext = NULL;
|
|
||||||
|
|
||||||
/* Add the newly created list item to the end of the already existing
|
|
||||||
list. */
|
|
||||||
pxLastCommandInList->pxNext = pxNewListItem;
|
|
||||||
|
|
||||||
/* Set the end of list marker to the new list item. */
|
|
||||||
pxLastCommandInList = pxNewListItem;
|
|
||||||
}
|
}
|
||||||
taskEXIT_CRITICAL();
|
|
||||||
|
|
||||||
xReturn = pdPASS;
|
return xReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return xReturn;
|
#endif /* #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
|
||||||
}
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||||
|
|
||||||
|
BaseType_t FreeRTOS_CLIRegisterCommandStatic( const CLI_Command_Definition_t * const pxCommandToRegister,
|
||||||
|
CLI_Definition_List_Item_t * pxCliDefinitionListItemBuffer )
|
||||||
|
{
|
||||||
|
/* Check the parameters are not NULL. */
|
||||||
|
configASSERT( pxCommandToRegister != NULL );
|
||||||
|
configASSERT( pxCliDefinitionListItemBuffer != NULL );
|
||||||
|
|
||||||
|
prvRegisterCommand( pxCommandToRegister, pxCliDefinitionListItemBuffer );
|
||||||
|
|
||||||
|
return pdPASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* #if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen )
|
BaseType_t FreeRTOS_CLIProcessCommand( const char * const pcCommandInput, char * pcWriteBuffer, size_t xWriteBufferLen )
|
||||||
|
|
@ -279,6 +285,36 @@ const char *pcReturn = NULL;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
static void prvRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister,
|
||||||
|
CLI_Definition_List_Item_t * pxCliDefinitionListItemBuffer )
|
||||||
|
{
|
||||||
|
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
|
||||||
|
|
||||||
|
/* Check the parameters are not NULL. */
|
||||||
|
configASSERT( pxCommandToRegister != NULL );
|
||||||
|
configASSERT( pxCliDefinitionListItemBuffer != NULL );
|
||||||
|
|
||||||
|
taskENTER_CRITICAL();
|
||||||
|
{
|
||||||
|
/* Reference the command being registered from the newly created
|
||||||
|
list item. */
|
||||||
|
pxCliDefinitionListItemBuffer->pxCommandLineDefinition = pxCommandToRegister;
|
||||||
|
|
||||||
|
/* The new list item will get added to the end of the list, so
|
||||||
|
pxNext has nowhere to point. */
|
||||||
|
pxCliDefinitionListItemBuffer->pxNext = NULL;
|
||||||
|
|
||||||
|
/* Add the newly created list item to the end of the already existing
|
||||||
|
list. */
|
||||||
|
pxLastCommandInList->pxNext = pxCliDefinitionListItemBuffer;
|
||||||
|
|
||||||
|
/* Set the end of list marker to the new list item. */
|
||||||
|
pxLastCommandInList = pxCliDefinitionListItemBuffer;
|
||||||
|
}
|
||||||
|
taskEXIT_CRITICAL();
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
static BaseType_t prvHelpCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
|
||||||
{
|
{
|
||||||
static const CLI_Definition_List_Item_t * pxCommand = NULL;
|
static const CLI_Definition_List_Item_t * pxCommand = NULL;
|
||||||
|
|
@ -347,4 +383,4 @@ BaseType_t xLastCharacterWasSpace = pdFALSE;
|
||||||
as the first word should be the command itself. */
|
as the first word should be the command itself. */
|
||||||
return cParameters;
|
return cParameters;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* FreeRTOS+CLI V1.0.4
|
* FreeRTOS V202212.00
|
||||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* 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
|
* 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
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* https://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* https://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -50,6 +50,13 @@ typedef struct xCOMMAND_LINE_INPUT
|
||||||
int8_t cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */
|
int8_t cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */
|
||||||
} CLI_Command_Definition_t;
|
} CLI_Command_Definition_t;
|
||||||
|
|
||||||
|
/* The structure that defines a command line list entry. */
|
||||||
|
typedef struct xCOMMAND_INPUT_LIST
|
||||||
|
{
|
||||||
|
const CLI_Command_Definition_t *pxCommandLineDefinition;
|
||||||
|
struct xCOMMAND_INPUT_LIST *pxNext;
|
||||||
|
} CLI_Definition_List_Item_t;
|
||||||
|
|
||||||
/* For backward compatibility. */
|
/* For backward compatibility. */
|
||||||
#define xCommandLineInput CLI_Command_Definition_t
|
#define xCommandLineInput CLI_Command_Definition_t
|
||||||
|
|
||||||
|
|
@ -59,7 +66,18 @@ typedef struct xCOMMAND_LINE_INPUT
|
||||||
* handled by the command interpreter. Once a command has been registered it
|
* handled by the command interpreter. Once a command has been registered it
|
||||||
* can be executed from the command line.
|
* can be executed from the command line.
|
||||||
*/
|
*/
|
||||||
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister );
|
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
||||||
|
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Static version of the above function which allows the application writer
|
||||||
|
* to supply the memory used for a command line list entry.
|
||||||
|
*/
|
||||||
|
#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
|
||||||
|
BaseType_t FreeRTOS_CLIRegisterCommandStatic( const CLI_Command_Definition_t * const pxCommandToRegister,
|
||||||
|
CLI_Definition_List_Item_t * pxCliDefinitionListItemBuffer );
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Runs the command interpreter for the command string "pcCommandInput". Any
|
* Runs the command interpreter for the command string "pcCommandInput". Any
|
||||||
|
|
@ -102,15 +120,3 @@ const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t u
|
||||||
|
|
||||||
#endif /* COMMAND_INTERPRETER_H */
|
#endif /* COMMAND_INTERPRETER_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2171,6 +2171,7 @@ pxcertificatebufferlength
|
||||||
pxcertificatecontext
|
pxcertificatecontext
|
||||||
pxcertificateidbufferlength
|
pxcertificateidbufferlength
|
||||||
pxclass
|
pxclass
|
||||||
|
pxclidefinitionlistitembuffer
|
||||||
pxclient
|
pxclient
|
||||||
pxcommand
|
pxcommand
|
||||||
pxcommandcontext
|
pxcommandcontext
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue