向vivi中加入命令

vivilib/command.c中添加自己的命令

核心数据结构user_command

typedef struct user_command {

    const char *name;                          //命令名

    void (*cmdfunc)(int argc, const char **);  //命令执行函数

    struct user_command *next_cmd;             //下一个命令

    const char *helpstr;                       //帮助

} user_command_t;

 

添加自定义命令的步骤-1

首先构造一个user_command的实例,比如:

user_command_t mytest_cmd = {

    “mytest",

    command_mytest,

    NULL,

    “mytest [{cmds}] /t/t/t– Add my command for test?"

};

 

添加自定义命令的步骤-2

然后实现命令的真正函数command_test

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”);  //这用printk输出信息

return;

}

 

在程序的后面 extern user_command_t ……. 之前添加,应该先写函数,再写结构体

 

添加自定义命令的步骤-3

将命令加入到系统

command.c中的

int init_builtin_cmds(void)函数的最后加入add_command(&mytest_cmd);

 这个函数在程序的最后面

生成vivi镜像

make clean

make menuconfig

make

烧录:load flash vivi x

测试:进入vivi,执行命令:mytest

 

执行help,在命令列表里就能看到mytest这个命令

posted @ 2014-12-19 19:39  Open_ShiFt  阅读(344)  评论(0编辑  收藏  举报