summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortabarnakos <46621477+tabarnakos@users.noreply.github.com>2023-04-13 10:32:41 -0400
committerGitHub <noreply@github.com>2023-04-13 07:32:41 -0700
commit4727d6b3cc369310306ff24f61cafc1017853f82 (patch)
tree3d32bcda5cf73ba4f15f46283aed770a06bb96bf
parent1309654d6f5d1342b4a9d3d7ae0824e8fcaefaf2 (diff)
downloadfreertos-git-4727d6b3cc369310306ff24f61cafc1017853f82.tar.gz
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>
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c114
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h38
-rw-r--r--lexicon.txt1
3 files changed, 98 insertions, 55 deletions
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
index 52dbe0d4a..b8825f500 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
@@ -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
*
*/
@@ -37,7 +37,7 @@
/* 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
-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:
char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
*/
@@ -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). */
/*-----------------------------------------------------------*/
-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;
+#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
+
+ BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
+ {
+ BaseType_t xReturn = pdFAIL;
+ CLI_Definition_List_Item_t *pxNewListItem;
- /* Check the parameter is not NULL. */
- configASSERT( pxCommandToRegister );
+ /* 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 );
+ /* 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 )
- {
- taskENTER_CRITICAL();
+ if( pxNewListItem != NULL )
{
- /* Reference the command being registered from the newly created
- list item. */
- pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;
+ prvRegisterCommand( pxCommandToRegister, pxNewListItem );
+ xReturn = pdPASS;
+ }
- /* The new list item will get added to the end of the list, so
- pxNext has nowhere to point. */
- pxNewListItem->pxNext = NULL;
+ return xReturn;
+ }
- /* Add the newly created list item to the end of the already existing
- list. */
- pxLastCommandInList->pxNext = pxNewListItem;
+#endif /* #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
+/*-----------------------------------------------------------*/
- /* Set the end of list marker to the new list item. */
- pxLastCommandInList = pxNewListItem;
- }
- taskEXIT_CRITICAL();
+#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- xReturn = pdPASS;
+ 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;
}
- return xReturn;
-}
+#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;
}
-
+/*-----------------------------------------------------------*/
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
index 0f670ca83..810724f98 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
@@ -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.
*/
-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
@@ -102,15 +120,3 @@ const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t u
#endif /* COMMAND_INTERPRETER_H */
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/lexicon.txt b/lexicon.txt
index fe87f51d0..90040ec07 100644
--- a/lexicon.txt
+++ b/lexicon.txt
@@ -2171,6 +2171,7 @@ pxcertificatebufferlength
pxcertificatecontext
pxcertificateidbufferlength
pxclass
+pxclidefinitionlistitembuffer
pxclient
pxcommand
pxcommandcontext