Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 75 additions & 39 deletions FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.c
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*
*/

Expand All @@ -37,19 +37,23 @@

/* 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 ];
*/
#ifndef configAPPLICATION_PROVIDES_cOutputBuffer
#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
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -347,4 +383,4 @@ BaseType_t xLastCharacterWasSpace = pdFALSE;
as the first word should be the command itself. */
return cParameters;
}

/*-----------------------------------------------------------*/
38 changes: 22 additions & 16 deletions FreeRTOS-Plus/Source/FreeRTOS-Plus-CLI/FreeRTOS_CLI.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
*
*/

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -102,15 +120,3 @@ const char *FreeRTOS_CLIGetParameter( const char *pcCommandString, UBaseType_t u

#endif /* COMMAND_INTERPRETER_H */













1 change: 1 addition & 0 deletions lexicon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,7 @@ pxcertificatebufferlength
pxcertificatecontext
pxcertificateidbufferlength
pxclass
pxclidefinitionlistitembuffer
pxclient
pxcommand
pxcommandcontext
Expand Down