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