FreeRTOS+CLI (二)

FreeRTOS_CLIRegisterCommand()

FreeRTOS_CLI.h

BaseType_t FreeRTOS_CLIRegisterCommand( CLI_Command_Definition_t *pxCommandToRegister )
		

FreeRTOS+CLI is an extensible framework that allows the application writer to define and register their own command line input commands. Functions that implement the behaviour of a user defined command have to use a particular interface, which is described on a separate page.

This page describes FreeRTOS_CLIRegisterCommand(), which is the API function used to register commands with FreeRTOS+CLI. A command is registered by associating (关联)the function that implements the command behaviour with a text string, and telling FreeRTOS+CLI about the association. FreeRTOS+CLI will then automatically run the function each time the command text string is entered. This will become clear after reading this page.

Note: The FreeRTOS_CLIRegisterCommand() prototype that appears in the code take a const pointer to a const structure of type CLI_Command_Definition_t. The const qualifiers(限定符) have been removed here to make the prototype easier to read.


Parameters:

pxCommandToRegister  The command being registered, which is defined by a structure of type CLI_Command_Definition_t. The structure is described below this table.

Returns:

pdPASS is returned if the command was successfully registered.

pdFAIL is returned if the command could not be registered because there was insufficient FreeRTOS heap available for a new list item to be created.

 

CLI_Command_Definition_t

Commands are defined by a structure of type CLI_Command_Definition_t. The structure is shown below. The comments in the code describe the structure members.

 

typedef struct xCLI_COMMAND_DEFINITION
{
    /* The command line input string.  This is the string that the user enters
    to run the command.  For example, the FreeRTOS+CLI help function uses the
    string "help".  If a user types "help" the help command executes. */
    const int8_t * const pcCommand;                
    
    /* A string that describes the command, and its expected parameters.  This
    is the string that is output when the help command is executed.  The string
    must start with the command itself, and end with "\r\n".  For example, the
    help string for the help command itself is:
    "help: Returns a list of all the commands\r\n" */
    const int8_t * const pcHelpString;
    
    /* A pointer to the function that implements the command behaviour 
    (effectively the function name). */
    const pdCOMMAND_LINE_CALLBACK pxCommandInterpreter;

    /* The number of parameters required by the command.  FreeRTOS+CLI will only
    execute the command if the number of parameters entered on the command line
    matches this number. */
    int8_t cExpectedNumberOfParameters;
} CLI_Command_Definition_t;
						

The CLI_Command_Definition_t structure

 

Examples

One of the FreeRTOS+CLI featured demos implements a file system "del" command. The command definition is given below.

 

static const CLI_Command_Definition_t xDelCommand =
{
    "del",
    "del <filename>: Deletes <filename> from the disk\r\n",
    prvDelCommand,
    1
};
						

The definition of the file system del command

Once this command is registered:

  • prvDelCommand() is executed each time the user types "del".
  • "del <filename>: Deletes <filename> from the disk\r\n" is output to describe the del command when the user types "help".
  • The del command expects one parameter (the name of the file being deleted). FreeRTOS+CLI will output an error string instead of executing prvDelCommand() if the number of input parameters is not exactly 1.

The del command is then registered with FreeRTOS+CLI using the following function call:

 

FreeRTOS_CLIRegisterCommand( &xDelCommand );
						

Registering the xDelCommand structure with FreeRTOS+CLI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值