Add commands to vivi and vivi

Source: Internet
Author: User

Add commands to vivi and vivi

Add your own commands in lib/command. c of vivi

The core data structure is user_command.

Typedef struct user_command {

Const char * name; // command name

Void (* prop func) (int argc, const char **); // command execution function

Struct user_command * next_cmd; // The next command

Const char * helpstr; // help

} User_command_t;

 

Step 1:

First, construct a user_command instance, for example:

User_command_t mytest_cmd = {

"Mytest ",

Command_mytest,

NULL,

"Mytest [{cmds}]/t-Add my command for test? "

};

 

Step 2:

Then implement the real command_test function of the command.

Void command_mytest (int argc, const char ** argv)

{

If (argc = 2)

If (strncmp (argv [1], "help", strlen (argv [1]) = 0)

{

Printk ("myTest Command Help/n ");

Return;

}

Printk ("myTest Command exec/n"); // This uses printk to output information

Return;

}

 

After the program extern user_command_t ....... Before adding, you should first write the function and then write the struct.

 

Step 3

Add commands to the System

In command. c

Add add_command (& mytest_cmd) to the end of int init_builtin_cmds (void) function );

This function is at the end of the program.

Generate a vivi Image

Make clean

Make menuconfig

Make

Installation: load flash vivi x

Test: Go to vivi and run the command: mytest

 

Execute help. The command mytest is displayed in the command list.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.