From: richardbarry Date: Mon, 26 Sep 2011 14:27:03 +0000 (+0000) Subject: Add an optional global buffer to the command interpreter that can be used for command... X-Git-Tag: V7.1.0~48 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b8ad8fe4d585eb7132eab05856b48238e15d4a9b;p=freertos 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. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1612 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/Demo/Common/Utils/CommandInterpreter.c b/Demo/Common/Utils/CommandInterpreter.c index 59eb5eb44..94a8020ea 100644 --- a/Demo/Common/Utils/CommandInterpreter.c +++ b/Demo/Common/Utils/CommandInterpreter.c @@ -90,6 +90,16 @@ static xCommandLineInputListItem xRegisteredCommands = 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 ) @@ -124,6 +134,7 @@ portBASE_TYPE xReturn = pdFAIL; /* Set the end of list marker to the new list item. */ pxLastCommandInList = pxNewListItem; } + taskEXIT_CRITICAL(); 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 const xCommandLineInputListItem * pxCommand = NULL; @@ -206,3 +229,4 @@ signed portBASE_TYPE xReturn; return xReturn; } + diff --git a/Demo/Common/Utils/CommandInterpreter.h b/Demo/Common/Utils/CommandInterpreter.h index c19c1c83a..6501451d8 100644 --- a/Demo/Common/Utils/CommandInterpreter.h +++ b/Demo/Common/Utils/CommandInterpreter.h @@ -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 ); +/*-----------------------------------------------------------*/ + +/* + * 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 */