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.