Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save friesendrywall/42f007854daa00c6736e5b57979ad8ba to your computer and use it in GitHub Desktop.
Save friesendrywall/42f007854daa00c6736e5b57979ad8ba to your computer and use it in GitHub Desktop.
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister )
#else
BaseType_t FreeRTOS_CLIRegisterCommand( const CLI_Command_Definition_t * const pxCommandToRegister, CLI_Definition_List_Item_t *pxNewListItem )
#endif
{
static CLI_Definition_List_Item_t *pxLastCommandInList = &xRegisteredCommands;
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
CLI_Definition_List_Item_t *pxNewListItem;
#endif
BaseType_t xReturn = pdFAIL;
/* Check the parameter is not NULL. */
configASSERT( pxCommandToRegister );
#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
/* 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 );
#endif
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();
xReturn = pdPASS;
}
return xReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment