Add an optional global buffer to the command interpreter that can be used for command interpreter output. This removes the need for multiple output buffers to be allocated when more than one command interpreter is implemented.

pull/4/head
Richard Barry 14 years ago
parent cc61126025
commit 42fa20daec

@ -90,6 +90,16 @@ static xCommandLineInputListItem xRegisteredCommands =
NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */ NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */
}; };
/* A buffer into which command outputs can be written is declared here, rather
than in the command console implementation, to allow multiple command consoles
to share the same buffer. For example, an application may allow access to the
command interpreter by UART and by Ethernet. Sharing a buffer is done purely
to save RAM. Note, however, that the command console itself is not re-entrant,
so only one command interpreter interface can be used at any one time. For that
reason, no attempt at providing mutual exclusion to the cOutputBuffer array is
attempted. */
static signed char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister ) portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister )
@ -124,6 +134,7 @@ portBASE_TYPE xReturn = pdFAIL;
/* Set the end of list marker to the new list item. */ /* Set the end of list marker to the new list item. */
pxLastCommandInList = pxNewListItem; pxLastCommandInList = pxNewListItem;
} }
taskEXIT_CRITICAL();
xReturn = pdPASS; xReturn = pdPASS;
} }
@ -177,6 +188,18 @@ portBASE_TYPE xReturn;
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
signed char *pcCmdIntGetOutputBuffer( void )
{
return cOutputBuffer;
}
/*-----------------------------------------------------------*/
unsigned portBASE_TYPE uxCmdIntGetOutputBufferSizeBytes( void )
{
return configCOMMAND_INT_MAX_OUTPUT_SIZE;
}
/*-----------------------------------------------------------*/
static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen ) static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen )
{ {
static const xCommandLineInputListItem * pxCommand = NULL; static const xCommandLineInputListItem * pxCommand = NULL;
@ -206,3 +229,4 @@ signed portBASE_TYPE xReturn;
return xReturn; return xReturn;
} }

@ -91,6 +91,25 @@ portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandT
*/ */
portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen ); portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen );
/*-----------------------------------------------------------*/
/*
* A buffer into which command outputs can be written is declared in the
* main command interpreter, rather than in the command console implementation,
* to allow application that provide access to the command console via multiple
* interfaces to share a buffer, and therefore save RAM. Note, however, that
* the command interpreter itself is not re-entrant, so only one command
* console interface can be used at any one time. For that reason, no attempt
* is made to provide any mutual exclusion mechanism on the output buffer.
*
* pcCmdIntGetOutputBuffer() returns the address of the output buffer.
*
* uxCmdIntGetOutputBufferSizeBytes() returns the size, in bytes, of the output
* buffer returned by pcCmdIntGetOutputBuffer();
*/
signed char *pcCmdIntGetOutputBuffer( void );
unsigned portBASE_TYPE uxCmdIntGetOutputBufferSizeBytes( void );
#endif /* COMMAND_INTERPRETER_H */ #endif /* COMMAND_INTERPRETER_H */

Loading…
Cancel
Save