Xiaojie雷达之路---TI实战笔记---CLI源码解析

文章目录

前言

这篇文章主要是讲解一下CLI源码,前段时间看automated_parking源码,只是知道CLI用于将上位机发送的命令传给AWR1843 EVM,而且也知道是通过串口来进行发送的,当时也没有太多关注内部是怎么实现的,今天和一位成电的研三学姐聊天,学姐突然提到这个问题,这个触及到了知识盲区,因此对CLI进行了重新的审视。下面,进入正文。

正文

看任何程序首先是从main函数开始,依次找到MRR_MSS_initTask()->MRR_MSS_CLIInit (),CLI映入眼帘,下面主角就登场了,进入函数内部
在这里插入图片描述
405行至410行就是对cli进行一些基本的配置,下面是CLI_Cfg结构体的内容:

typedef struct CLI_Cfg_t
{
    
    
    /**
     * @brief   CLI Prompt string (if any to be displayed)
     */
    char*               cliPrompt;

    /**
     * @brief   Optional banner string if any to be displayed on startup of the CLI
     */
    char*               cliBanner;

    /**
     * @brief   UART Command Handle used by the CLI
     */
    UART_Handle         cliUartHandle;

    /**
     * @brief   The CLI has an mmWave extension which can be enabled by this
     * field. The extension supports the well define mmWave link CLI command(s)
     * In order to use the extension the application should have initialized
     * and setup the mmWave.
     */
    uint8_t             enableMMWaveExtension;

    /**
     * @brief   The SOC driver handle is used to acquire device part number
     */
    SOC_Handle          socHandle;

    /**
     * @brief   The mmWave control handle which needs to be specified if
     * the mmWave extensions are being used. The CLI Utility works only
     * in the FULL configuration mode. If the handle is opened in
     * MINIMAL configuration mode the CLI mmWave extension will fail
     */
    MMWave_Handle       mmWaveHandle;

    /**
     * @brief   Task Priority: The CLI executes in the context of a task
     * which executes with this priority
     */
    uint8_t             taskPriority;

    /**
     * @brief   Flag which determines if the the CLI Write should use the UART
     * in polled or blocking mode.
     */
    bool                usePolledMode;

    /**
     * @brief   This is the table which specifies the supported CLI commands
     */
    CLI_CmdTableEntry   tableEntry[CLI_MAX_CMD];
}CLI_Cfg;

下面这行代码将UART与CLI联系到了一起

cliCfg.cliUartHandle                = gMrrMSSMCB.commandUartHandle;

从412行至426行是中一个tableEntry数组,最大可以为32,CLI_CmdTableEntry结构体如下:

typedef struct CLI_CmdTableEntry_t
{
    
    
    /**
     * @brief   Command string
     */
    char*               cmd;

    /**
     * @brief   CLI Command Help string
     */
    char*               helpString;

    /**
     * @brief   Command Handler to be executed
     */
    CLI_CmdHandler      cmdHandlerFxn;
}CLI_CmdTableEntry;

cmd值得是命令,cmdHandlerFxn指向的是要对应命令要执行的回调函数。

接下来就到了CLI_open()这个函数,源码在mmwave_sdk_version\packages\ti\utils\cli\src中,让我们查看CLI_open()这个源码,如下:
在这里插入图片描述
前面的都是对CLI命令的一些配置,最后倒数5行至倒数4行才是重要的,这几行的代码就是创建了一个线程,这个线程的优先级是3,所能同的空间大小为4KB,这个线程要执行的函数是CLI_task,下面转到CLI_task查看程序,CLI函数如下:
在这里插入图片描述
可以看到程序一直在while(1)中执行,而看到UART_read()就明白了,实际上CLI内部也就是调用的UART,是利用UART来实现的

总结

CLI内部就是通过调用UART来实现的,是接收上位机给EVM板发送的指令

猜你喜欢

转载自blog.csdn.net/Xiao_Jie123/article/details/111185233
今日推荐