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
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* FreeRTOS V202212.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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://aws.amazon.com/freertos
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
|
|
@ -45,11 +45,15 @@ one of the application files:
|
|||
#define configAPPLICATION_PROVIDES_cOutputBuffer 0
|
||||
#endif
|
||||
|
||||
typedef struct xCOMMAND_INPUT_LIST
|
||||
{
|
||||
const CLI_Command_Definition_t *pxCommandLineDefinition;
|
||||
struct xCOMMAND_INPUT_LIST *pxNext;
|
||||
} CLI_Definition_List_Item_t;
|
||||
/*
|
||||
* Register the command passed in using the pxCommandToRegister parameter
|
||||
* and using pxCliDefinitionListItemBuffer as the memory for command line
|
||||
* list items. Registering a command adds the command to the list of
|
||||
* 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
|
||||
|
|
@ -101,45 +105,47 @@ buffer needs to be placed at a fixed address (rather than by the linker). */
|
|||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
|
||||
|
||||
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
|
||||
{
|
||||
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
|
||||
CLI_Definition_List_Item_t *pxNewListItem;
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
CLI_Definition_List_Item_t *pxNewListItem;
|
||||
|
||||
/* Check the parameter is not NULL. */
|
||||
configASSERT( pxCommandToRegister );
|
||||
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 );
|
||||
configASSERT( pxNewListItem != NULL );
|
||||
|
||||
if( pxNewListItem != NULL )
|
||||
{
|
||||
taskENTER_CRITICAL();
|
||||
{
|
||||
/* Reference the command being registered from the newly created
|
||||
list item. */
|
||||
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();
|
||||
|
||||
prvRegisterCommand( pxCommandToRegister, pxNewListItem );
|
||||
xReturn = pdPASS;
|
||||
}
|
||||
|
||||
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 )
|
||||
|
|
@ -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 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. */
|
||||
return cParameters;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* FreeRTOS+CLI V1.0.4
|
||||
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
* FreeRTOS V202212.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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* 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. */
|
||||
} 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. */
|
||||
#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
|
||||
* can be executed from the command line.
|
||||
*/
|
||||
#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
|
||||
|
|
@ -102,15 +120,3 @@ const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t u
|
|||
|
||||
#endif /* COMMAND_INTERPRETER_H */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2171,6 +2171,7 @@ pxcertificatebufferlength
|
|||
pxcertificatecontext
|
||||
pxcertificateidbufferlength
|
||||
pxclass
|
||||
pxclidefinitionlistitembuffer
|
||||
pxclient
|
||||
pxcommand
|
||||
pxcommandcontext
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue