+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
- \r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-/* Standard includes. */\r
-#include <string.h>\r
-\r
-/* FreeRTOS includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-\r
-/* Utils includes. */\r
-#include "CommandInterpreter.h"\r
-\r
-typedef struct xCOMMAND_INPUT_LIST\r
-{\r
- const xCommandLineInput *pxCommandLineDefinition;\r
- struct xCOMMAND_INPUT_LIST *pxNext;\r
-} xCommandLineInputListItem;\r
-\r
-/*\r
- * The callback function that is executed when "help" is entered. This is the\r
- * only default command that is always present.\r
- */\r
-static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen, const signed char *pcCommandString );\r
-\r
-/*\r
- * Return the number of parameters that follow the command name.\r
- */\r
-static signed char prvGetNumberOfParameters( const signed char * pcCommandString );\r
-\r
-/* The definition of the "help" command. This command is always at the front\r
-of the list of registered commands. */\r
-static const xCommandLineInput xHelpCommand = \r
-{\r
- ( const signed char * const ) "help",\r
- ( const signed char * const ) "help: Lists all the registered commands\r\n",\r
- prvHelpCommand,\r
- 0\r
-};\r
-\r
-/* The definition of the list of commands. Commands that are registered are\r
-added to this list. */\r
-static xCommandLineInputListItem xRegisteredCommands =\r
-{ \r
- &xHelpCommand, /* The first command in the list is always the help command, defined in this file. */\r
- NULL /* The next pointer is initialised to NULL, as there are no other registered commands yet. */\r
-};\r
-\r
-/* A buffer into which command outputs can be written is declared here, rather\r
-than in the command console implementation, to allow multiple command consoles\r
-to share the same buffer. For example, an application may allow access to the\r
-command interpreter by UART and by Ethernet. Sharing a buffer is done purely\r
-to save RAM. Note, however, that the command console itself is not re-entrant,\r
-so only one command interpreter interface can be used at any one time. For that\r
-reason, no attempt at providing mutual exclusion to the cOutputBuffer array is\r
-attempted. */\r
-static signed char cOutputBuffer[ configCOMMAND_INT_MAX_OUTPUT_SIZE ];\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister )\r
-{\r
-static xCommandLineInputListItem *pxLastCommandInList = &xRegisteredCommands;\r
-xCommandLineInputListItem *pxNewListItem;\r
-portBASE_TYPE xReturn = pdFAIL;\r
-\r
- /* Check the parameter is not NULL. */\r
- configASSERT( pxCommandToRegister );\r
-\r
- /* Create a new list item that will reference the command being registered. */\r
- pxNewListItem = ( xCommandLineInputListItem * ) pvPortMalloc( sizeof( xCommandLineInputListItem ) );\r
- configASSERT( pxNewListItem );\r
-\r
- if( pxNewListItem != NULL )\r
- {\r
- taskENTER_CRITICAL();\r
- {\r
- /* Reference the command being registered from the newly created \r
- list item. */\r
- pxNewListItem->pxCommandLineDefinition = pxCommandToRegister;\r
-\r
- /* The new list item will get added to the end of the list, so \r
- pxNext has nowhere to point. */\r
- pxNewListItem->pxNext = NULL;\r
-\r
- /* Add the newly created list item to the end of the already existing\r
- list. */\r
- pxLastCommandInList->pxNext = pxNewListItem;\r
-\r
- /* Set the end of list marker to the new list item. */\r
- pxLastCommandInList = pxNewListItem;\r
- }\r
- taskEXIT_CRITICAL();\r
- \r
- xReturn = pdPASS;\r
- }\r
-\r
- return xReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen )\r
-{\r
-static const xCommandLineInputListItem *pxCommand = NULL;\r
-portBASE_TYPE xReturn = pdTRUE;\r
-const signed char *pcRegisteredCommandString;\r
-\r
- /* Note: This function is not re-entrant. It must not be called from more\r
- thank one task. */\r
-\r
- if( pxCommand == NULL )\r
- {\r
- /* Search for the command string in the list of registered commands. */\r
- for( pxCommand = &xRegisteredCommands; pxCommand != NULL; pxCommand = pxCommand->pxNext )\r
- {\r
- pcRegisteredCommandString = pxCommand->pxCommandLineDefinition->pcCommand;\r
- if( strncmp( ( const char * ) pcCommandInput, ( const char * ) pcRegisteredCommandString, strlen( ( const char * ) pcRegisteredCommandString ) ) == 0 )\r
- {\r
- /* The command has been found. Check it has the expected\r
- number of parameters. If cExpectedNumberOfParameters is -1,\r
- then there could be a variable number of parameters and no\r
- check is made. */\r
- if( pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters >= 0 )\r
- {\r
- if( prvGetNumberOfParameters( pcCommandInput ) != pxCommand->pxCommandLineDefinition->cExpectedNumberOfParameters )\r
- {\r
- xReturn = pdFALSE;\r
- }\r
- }\r
-\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if( ( pxCommand != NULL ) && ( xReturn == pdFALSE ) )\r
- {\r
- /* The command was found, but the number of parameters with the command\r
- was incorrect. */\r
- strncpy( ( char * ) pcWriteBuffer, "Incorrect command parameter(s). Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );\r
- pxCommand = NULL;\r
- }\r
- else if( pxCommand != NULL )\r
- {\r
- /* Call the callback function that is registered to this command. */\r
- xReturn = pxCommand->pxCommandLineDefinition->pxCommandInterpreter( pcWriteBuffer, xWriteBufferLen, pcCommandInput );\r
-\r
- /* If xReturn is pdFALSE, then no further strings will be returned\r
- after this one, and pxCommand can be reset to NULL ready to search \r
- for the next entered command. */\r
- if( xReturn == pdFALSE )\r
- {\r
- pxCommand = NULL;\r
- }\r
- }\r
- else\r
- {\r
- /* pxCommand was NULL, the command was not found. */\r
- strncpy( ( char * ) pcWriteBuffer, ( const char * const ) "Command not recognised. Enter \"help\" to view a list of available commands.\r\n\r\n", xWriteBufferLen );\r
- xReturn = pdFALSE;\r
- }\r
-\r
- return xReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-signed char *pcCmdIntGetOutputBuffer( void )\r
-{\r
- return cOutputBuffer;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-unsigned portBASE_TYPE uxCmdIntGetOutputBufferSizeBytes( void )\r
-{\r
- return configCOMMAND_INT_MAX_OUTPUT_SIZE;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-const signed char *pcCmdIntGetParameter( const signed char *pcCommandString, unsigned portBASE_TYPE uxWantedParameter, portBASE_TYPE *pxParameterStringLength )\r
-{\r
-unsigned portBASE_TYPE uxParametersFound = 0;\r
-const signed char *pcReturn = NULL;\r
-\r
- *pxParameterStringLength = 0;\r
-\r
- while( uxParametersFound < uxWantedParameter )\r
- {\r
- /* Index the character pointer past the current word. If this is the start\r
- of the command string then the first word is the command itself. */\r
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )\r
- {\r
- pcCommandString++;\r
- }\r
-\r
- /* Find the start of the next string. */\r
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) == ' ' ) )\r
- {\r
- pcCommandString++;\r
- }\r
-\r
- /* Was a string found? */\r
- if( *pcCommandString != 0x00 )\r
- {\r
- /* Is this the start of the required parameter? */\r
- uxParametersFound++;\r
-\r
- if( uxParametersFound == uxWantedParameter )\r
- {\r
- /* How long is the parameter? */\r
- pcReturn = pcCommandString;\r
- while( ( ( *pcCommandString ) != 0x00 ) && ( ( *pcCommandString ) != ' ' ) )\r
- {\r
- ( *pxParameterStringLength )++;\r
- pcCommandString++;\r
- }\r
-\r
- break;\r
- }\r
- }\r
- else\r
- {\r
- break;\r
- }\r
- }\r
-\r
- return pcReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static portBASE_TYPE prvHelpCommand( signed char *pcWriteBuffer, size_t xWriteBufferLen, const signed char *pcCommandString )\r
-{\r
-static const xCommandLineInputListItem * pxCommand = NULL;\r
-signed portBASE_TYPE xReturn;\r
-\r
- ( void ) pcCommandString;\r
-\r
- if( pxCommand == NULL )\r
- {\r
- /* Reset the pxCommand pointer back to the start of the list. */\r
- pxCommand = &xRegisteredCommands;\r
- }\r
-\r
- /* Return the next command help string, before moving the pointer on to\r
- the next command in the list. */\r
- strncpy( ( char * ) pcWriteBuffer, ( const char * ) pxCommand->pxCommandLineDefinition->pcHelpString, xWriteBufferLen );\r
- pxCommand = pxCommand->pxNext;\r
-\r
- if( pxCommand == NULL )\r
- {\r
- /* There are no more commands in the list, so there will be no more\r
- strings to return after this one and pdFALSE should be returned. */\r
- xReturn = pdFALSE;\r
- }\r
- else\r
- {\r
- xReturn = pdTRUE;\r
- }\r
-\r
- return xReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static signed char prvGetNumberOfParameters( const signed char * pcCommandString )\r
-{\r
-signed char cParameters = 0;\r
-portBASE_TYPE xLastCharacterWasSpace = pdFALSE;\r
-\r
- /* Count the number of space delimited words in pcCommandString. */\r
- while( *pcCommandString != 0x00 )\r
- {\r
- if( ( *pcCommandString ) == ' ' )\r
- {\r
- if( xLastCharacterWasSpace != pdTRUE )\r
- {\r
- cParameters++;\r
- xLastCharacterWasSpace = pdTRUE;\r
- }\r
- }\r
- else\r
- {\r
- xLastCharacterWasSpace = pdFALSE;\r
- }\r
-\r
- pcCommandString++;\r
- }\r
-\r
- /* The value returned is one less than the number of space delimited words,\r
- as the first word should be the command itself. */\r
- return cParameters;\r
-}\r
-\r
+++ /dev/null
-/*\r
- FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
-\r
-\r
- ***************************************************************************\r
- * *\r
- * FreeRTOS tutorial books are available in pdf and paperback. *\r
- * Complete, revised, and edited pdf reference manuals are also *\r
- * available. *\r
- * *\r
- * Purchasing FreeRTOS documentation will not only help you, by *\r
- * ensuring you get running as quickly as possible and with an *\r
- * in-depth knowledge of how to use FreeRTOS, it will also help *\r
- * the FreeRTOS project to continue with its mission of providing *\r
- * professional grade, cross platform, de facto standard solutions *\r
- * for microcontrollers - completely free of charge! *\r
- * *\r
- * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
- * *\r
- * Thank you for using FreeRTOS, and thank you for your support! *\r
- * *\r
- ***************************************************************************\r
-\r
-\r
- This file is part of the FreeRTOS distribution.\r
-\r
- FreeRTOS is free software; you can redistribute it and/or modify it under\r
- the terms of the GNU General Public License (version 2) as published by the\r
- Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
- >>>NOTE<<< The modification to the GPL is included to allow you to\r
- distribute a combined work that includes FreeRTOS without being obliged to\r
- provide the source code for proprietary components outside of the FreeRTOS\r
- kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- more details. You should have received a copy of the GNU General Public\r
- License and the FreeRTOS license exception along with FreeRTOS; if not it\r
- can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
- by writing to Richard Barry, contact details for whom are available on the\r
- FreeRTOS WEB site.\r
-\r
- 1 tab == 4 spaces!\r
-\r
- http://www.FreeRTOS.org - Documentation, latest information, license and\r
- contact details.\r
-\r
- http://www.SafeRTOS.com - A version that is certified for use in safety\r
- critical systems.\r
-\r
- http://www.OpenRTOS.com - Commercial support, development, porting,\r
- licensing and training services.\r
-*/\r
-\r
-#ifndef COMMAND_INTERPRETER_H\r
-#define COMMAND_INTERPRETER_H\r
-\r
-/* The prototype to which callback functions used to process command line\r
-commands must comply. pcWriteBuffer is a buffer into which the output from \r
-executing the command can be written, xWriteBufferLen is the length, in bytes of \r
-the pcWriteBuffer buffer, and pcCommandString is the entire string as input by\r
-the user (from which parameters can be extracted.*/\r
-typedef portBASE_TYPE (*pdCOMMAND_LINE_CALLBACK)( signed char *pcWriteBuffer, size_t xWriteBufferLen, const signed char * pcCommandString );\r
-\r
-/* The structure that defines command line commands. A command line command\r
-should be defined by declaring a const structure of this type. */\r
-typedef struct xCOMMAND_LINE_INPUT\r
-{\r
- const signed char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */\r
- const signed char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For example "help: Returns a list of all the commands\r\n". */\r
- const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */\r
- signed char cExpectedNumberOfParameters; /* Commands expect a fixed number of parameters, which may be zero. */\r
-} xCommandLineInput;\r
-\r
-/*\r
- * Register the command passed in using the pxCommandToRegister parameter.\r
- * Registering a command adds the command to the list of commands that are\r
- * handled by the command interpreter. Once a command has been registered it\r
- * can be executed from the command line.\r
- */\r
-portBASE_TYPE xCmdIntRegisterCommand( const xCommandLineInput * const pxCommandToRegister );\r
-\r
-/*\r
- * Runs the command interpreter for the command string "pcCommandInput". Any\r
- * output generated by running the command will be placed into pcWriteBuffer.\r
- * xWriteBufferLen must indicate the size, in bytes, of the buffer pointed to\r
- * by pcWriteBuffer.\r
- *\r
- * xCmdIntProcessCommand should be called repeatedly until it returns pdFALSE.\r
- *\r
- * pcCmdIntProcessCommand is not reentrant. It must not be called from more\r
- * than one task - or at least - by more than one task at a time.\r
- */\r
-portBASE_TYPE xCmdIntProcessCommand( const signed char * const pcCommandInput, signed char * pcWriteBuffer, size_t xWriteBufferLen );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * A buffer into which command outputs can be written is declared in the\r
- * main command interpreter, rather than in the command console implementation,\r
- * to allow application that provide access to the command console via multiple\r
- * interfaces to share a buffer, and therefore save RAM. Note, however, that\r
- * the command interpreter itself is not re-entrant, so only one command\r
- * console interface can be used at any one time. For that reason, no attempt\r
- * is made to provide any mutual exclusion mechanism on the output buffer.\r
- *\r
- * pcCmdIntGetOutputBuffer() returns the address of the output buffer.\r
- *\r
- * uxCmdIntGetOutputBufferSizeBytes() returns the size, in bytes, of the output\r
- * buffer returned by pcCmdIntGetOutputBuffer();\r
- */\r
-signed char *pcCmdIntGetOutputBuffer( void );\r
-unsigned portBASE_TYPE uxCmdIntGetOutputBufferSizeBytes( void );\r
-\r
-/*\r
- * Return a pointer to the xParameterNumber'th word in pcCommandString.\r
- */\r
-const signed char *pcCmdIntGetParameter( const signed char *pcCommandString, unsigned portBASE_TYPE uxWantedParameter, portBASE_TYPE *pxParameterStringLength );\r
-\r
-#endif /* COMMAND_INTERPRETER_H */\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r