• 向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这个命令

    转载请注明地址:http://www.cnblogs.com/OpenShiFt/ 谢谢!
  • 相关阅读:
    ARM 64位系统下运行32位程序
    CMakeFiles示例
    Linux c++ 试验10 一例undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'”
    EclipseC++学习笔记9 将文件从项目中排除与恢复
    WSL 一例运行时提示access denied解决办法
    arm64环境搭建2 几个小tip
    飞凌FCU2201 使用2 设置wifi sta模式
    minicom退出
    linux出现TIME_WAIT的原因
    模板类出现 undefined reference 错误
  • 原文地址:https://www.cnblogs.com/OpenShiFt/p/4174629.html
Copyright © 2020-2023  润新知