Add your own commands to Vivi

Source: Internet
Author: User

 

Related Principles:

Related Mechanisms and initialization implementation are completed in lib/command. C. Including adding commands, searching commands, executing commands, and parsing commands.

The core functions of specific command execution are implemented in the corresponding module.

In this way, two layers of software architecture are formed: the top management layer -- command. C, and the bottom execution layer -- execution functions of the corresponding commands.

The core data structure is user_command.

Typedef struct user_command {

Const char * Name;

Void (* prop func) (INT argc, const char **);

Struct user_command * next_cmd;

Const char * helpstr;

} User_command_t;

 

Start:

 

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 ");

Return;

}

 

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 );

 

Step 4

Generate a Vivi Image

# Make clean

# Make menuconfig

# Make

 

Step 5

Installation: Load flash Vivi x

 

Step 6

Test: Go to Vivi and run the command: mytest

 

 

 

 

 

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.