This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AWR1642: send config to AWR1642 without using visualizer. when I set a configuration, the AWR1642 crashed

Part Number: AWR1642

Hi,

I am trying to do a project using AWR1642 board on Windows platform. I want to be able to configure the board using code so i can have same configuration settings and need not to reconfigure it every time i power up the board. 

I modify code in path sdk\packages\ti\demo\xwr16xx\mmw and set config like below:

------

sensorStop
flushCfg
dfeDataOutputMode 1
channelCfg 15 3 0
adcCfg 2 1
adcbufCfg -1 0 0 1 0
profileCfg 0 77 438 7 48.98 0 0 15 1 256 6250 0 0 30
chirpCfg 0 0 0 0 0 0 0 1
chirpCfg 1 1 0 0 0 0 0 2
frameCfg 0 1 16 0 100 1 0
guiMonitor -1 1 0 0 0 0 0
cfarCfg -1 0 0 8 4 4 0 7510
cfarCfg -1 1 0 4 2 3 0 5120
peakGrouping -1 1 1 1 1 255
multiObjBeamForming -1 1 0.5
clutterRemoval -1 0
calibDcRangeSig -1 0 -5 8 256
extendedMaxVelocity -1 0
compRangeBiasAndRxChanPhase 0.0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
measureRangeBiasAndRxChanPhase 0 1.5 0.2
sensorStart

------

and The AWR1642 crashed on command guiMonitor. the crashed raised by MmwDemo_mboxWrite(). crashed happen as below. Hope you can help me to check this problem. thank you.

  • Hi,

    Can you please let us know what application you plan to develop with AWR1642? This will help us better answer your questions.

    Please let us know which version of mmWave SDK you are using and what are the changes you have made to the default files

    thank you
    Cesar
  • Hi Cesar,

    I am using mmwDemo in mmwave_sdk_01_01_00_02. I want to be able to configure the board with default configuration settings and need not to reconfigure it every time i power up the board. 

    refer the modification as 

    /*
     * @file ini_cfg.c
     *
     *  Created on: Nov 9, 2017
     *      Author: hstubeda
     *
     *   @brief
     *      MMWave Demo automatic self-configuration
     *
     *  \par
     *  NOTE:
     *      (C) Copyright 2017 Ross Video, Ltd.
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    #include <string.h>
    /* mmWave SDK Include Files: */
    #include <xdc/runtime/System.h>
    
    #include <ti/drivers/uart/UART.h>
    #include <ti/utils/cli/include/cli_internal.h>
    #include <ti/utils/cli/cli.h>
    
    /* local includes */
    //#include "cli.h"
    #include "ini_cfg.h"
    
    /**************************************************************************
     *************************** Extern Definitions ***************************
     **************************************************************************/
    /* CLI Extended Command Functions */
    extern int32_t MmwDemo_CLICfarCfg(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIPeakGroupingCfg(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIMultiObjBeamForming(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLICalibDcRangeSig(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLISensorStart(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLISensorStop(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIGuiMonSel(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLISetDataLogger(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIClutterRemoval(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIExtendedMaxVelocity(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg(int32_t argc, char* argv[]);
    extern int32_t MmwDemo_CLIADCBufCfg (int32_t argc, char* argv[]);
    
    /**************************************************************************
     ****************** Local Function Definitions ***************************
     **************************************************************************/
    
    /**
     *  @b Description
     *  @n
     *      This function uses CLI command string to configure the sensor;
     *      This function can be run from within code, and does not require user input from CLI.
     *
     *  @param[in] cmd[]
     *      CLI command, broken into its constituent arguments
     *      e.g multiObjBeamForming 1 0.5 is {"multiObjBeamForming", "1", "0.5"}
     *
     *  @retval
     *      Not Applicable.
     */
    void MmwDemo_CfgWithCmdString (uint32_t num_arg, char* cmd[])
    {
        if(strcmp("sensorStop", cmd[0]) == 0)
            MmwDemo_CLISensorStop(num_arg, cmd);
    
        //else if(strcmp("adcbufCfg", cmd[0]) == 0)
        //	MmwDemo_CLIADCBufCfg(num_arg, cmd);
    
        else if(strcmp("guiMonitor", cmd[0]) == 0)
            MmwDemo_CLIGuiMonSel(num_arg, cmd);
    
        else if(strcmp("cfarCfg", cmd[0]) == 0)
            MmwDemo_CLICfarCfg(num_arg, cmd);
    
        else if(strcmp("peakGrouping", cmd[0]) == 0)
            MmwDemo_CLIPeakGroupingCfg(num_arg, cmd);
    
        else if(strcmp("multiObjBeamForming", cmd[0]) == 0)
            MmwDemo_CLIMultiObjBeamForming(num_arg, cmd);
            
        else if(strcmp("clutterRemoval", cmd[0]) == 0)
            MmwDemo_CLIClutterRemoval(num_arg, cmd);
    
        else if(strcmp("calibDcRangeSig", cmd[0]) == 0)
            MmwDemo_CLICalibDcRangeSig(num_arg, cmd);
        
        else if(strcmp("extendedMaxVelocity", cmd[0]) == 0)
            MmwDemo_CLIExtendedMaxVelocity(num_arg, cmd);
        
        else if(strcmp("compRangeBiasAndRxChanPhase", cmd[0]) == 0)
        	MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg(num_arg, cmd);
        	
        else if(strcmp("measureRangeBiasAndRxChanPhase", cmd[0]) == 0)
        	MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg(num_arg, cmd);
        	
        else if(strcmp("sensorStart", cmd[0]) == 0)
            MmwDemo_CLISensorStart(num_arg, cmd);
    
        else
            CLI_MMWaveExtensionHandler(num_arg, cmd);
    
        return;
    }
    
    /**
     *  @b Description
     *  @n
     *      This function instantiates initial configuration structure using CLI command strings,
     *      and uses these strings to configure the sensor
     *
     *  @param[in] cmd
     *      Commands
     *
     *  @retval
     *      Not Applicable.
     */
    void MmwDemo_IniRSSDSSCfg(void)
    {
        String_Cfg_Cmds iniCfgCmds;
        uint32_t c = 0;
    
        iniCfgCmds.sensorStop[0] = "sensorStop";
    
        iniCfgCmds.flushCfg[0] = "flushCfg";
    
        iniCfgCmds.dfeDataOutputMode[0] = "dfeDataOutputMode";
        iniCfgCmds.dfeDataOutputMode[1] = "1";
    
        iniCfgCmds.channelCfg[0] = "channelCfg";
        iniCfgCmds.channelCfg[1] = "15";
        iniCfgCmds.channelCfg[2] = "3";
        iniCfgCmds.channelCfg[3] = "0";
    
        iniCfgCmds.adcCfg[0] = "adcCfg";
        iniCfgCmds.adcCfg[1] = "2";
        iniCfgCmds.adcCfg[2] = "1";
    
        iniCfgCmds.adcbufCfg[0] = "adcbufCfg";
        iniCfgCmds.adcbufCfg[1] = "-1";
        iniCfgCmds.adcbufCfg[2] = "0";
        iniCfgCmds.adcbufCfg[3] = "0";
        iniCfgCmds.adcbufCfg[4] = "1";
        iniCfgCmds.adcbufCfg[5] = "0";
    
        iniCfgCmds.profileCfg [0] = "profileCfg";
        iniCfgCmds.profileCfg[ 1] = "0";
        iniCfgCmds.profileCfg[ 2] = "77";
        iniCfgCmds.profileCfg[ 3] = "438";
        iniCfgCmds.profileCfg[ 4] = "7";
        iniCfgCmds.profileCfg[ 5] = "48.98";
        iniCfgCmds.profileCfg[ 6] = "0";
        iniCfgCmds.profileCfg[ 7] = "0";
        iniCfgCmds.profileCfg[ 8] = "15";
        iniCfgCmds.profileCfg[ 9] = "1";
        iniCfgCmds.profileCfg[10] = "256";
        iniCfgCmds.profileCfg[11] = "6250";
        iniCfgCmds.profileCfg[12] = "0";
        iniCfgCmds.profileCfg[13] = "0";
        iniCfgCmds.profileCfg[14] = "30";
    
        iniCfgCmds.chirpCfg1[0] = "chirpCfg";
        iniCfgCmds.chirpCfg1[1] = "0";
        iniCfgCmds.chirpCfg1[2] = "0";
        iniCfgCmds.chirpCfg1[3] = "0";
        iniCfgCmds.chirpCfg1[4] = "0";
        iniCfgCmds.chirpCfg1[5] = "0";
        iniCfgCmds.chirpCfg1[6] = "0";
        iniCfgCmds.chirpCfg1[7] = "0";
        iniCfgCmds.chirpCfg1[8] = "1";
    
        iniCfgCmds.chirpCfg2[0] = "chirpCfg";
        iniCfgCmds.chirpCfg2[1] = "1";
        iniCfgCmds.chirpCfg2[2] = "1";
        iniCfgCmds.chirpCfg2[3] = "0";
        iniCfgCmds.chirpCfg2[4] = "0";
        iniCfgCmds.chirpCfg2[5] = "0";
        iniCfgCmds.chirpCfg2[6] = "0";
        iniCfgCmds.chirpCfg2[7] = "0";
        iniCfgCmds.chirpCfg2[8] = "2";
    
        iniCfgCmds.frameCfg[0] = "frameCfg";
        iniCfgCmds.frameCfg[1] = "0";
        iniCfgCmds.frameCfg[2] = "1";
        iniCfgCmds.frameCfg[3] = "16";
        iniCfgCmds.frameCfg[4] = "0";
        iniCfgCmds.frameCfg[5] = "600";
        iniCfgCmds.frameCfg[6] = "1";
        iniCfgCmds.frameCfg[7] = "0"; //frame delay upon sensor startup; change this value between different sensors to avoid sensor cross-interference
    
        iniCfgCmds.guiMonitor[0] = "guiMonitor";
        iniCfgCmds.guiMonitor[1] = "-1";
        iniCfgCmds.guiMonitor[2] = "1";
        iniCfgCmds.guiMonitor[3] = "0";
        iniCfgCmds.guiMonitor[4] = "0";
        iniCfgCmds.guiMonitor[5] = "0";
        iniCfgCmds.guiMonitor[6] = "0";
        iniCfgCmds.guiMonitor[7] = "0";
    
        iniCfgCmds.cfarCfgRange[0] = "cfarCfg";
        iniCfgCmds.cfarCfgRange[1] = "-1";
        iniCfgCmds.cfarCfgRange[2] = "0";
        iniCfgCmds.cfarCfgRange[3] = "0";
        iniCfgCmds.cfarCfgRange[4] = "8";
        iniCfgCmds.cfarCfgRange[5] = "4";
        iniCfgCmds.cfarCfgRange[6] = "4";
        iniCfgCmds.cfarCfgRange[7] = "0";
        iniCfgCmds.cfarCfgRange[8] = "5120";
    
        iniCfgCmds.cfarCfgDoppler[0] = "cfarCfg";
        iniCfgCmds.cfarCfgDoppler[1] = "-1";
        iniCfgCmds.cfarCfgDoppler[2] = "1";
        iniCfgCmds.cfarCfgDoppler[3] = "0";
        iniCfgCmds.cfarCfgDoppler[4] = "4";
        iniCfgCmds.cfarCfgDoppler[5] = "2";
        iniCfgCmds.cfarCfgDoppler[6] = "3";
        iniCfgCmds.cfarCfgDoppler[7] = "0";
        iniCfgCmds.cfarCfgDoppler[8] = "5120";
    
        iniCfgCmds.peakGrouping[0] = "peakGrouping";
        iniCfgCmds.peakGrouping[1] = "-1";
        iniCfgCmds.peakGrouping[2] = "1";
        iniCfgCmds.peakGrouping[3] = "1";
        iniCfgCmds.peakGrouping[4] = "1";
        iniCfgCmds.peakGrouping[5] = "1";
        iniCfgCmds.peakGrouping[6] = "255";
    
        iniCfgCmds.multiObjBeamForming[0] = "multiObjBeamForming";
        iniCfgCmds.multiObjBeamForming[1] = "-1";
        iniCfgCmds.multiObjBeamForming[2] = "1";
        iniCfgCmds.multiObjBeamForming[3] = "0.5";
        
        iniCfgCmds.clutterRemoval[0] = "clutterRemoval";
        iniCfgCmds.clutterRemoval[1] = "-1";
        iniCfgCmds.clutterRemoval[2] = "0";
        
        iniCfgCmds.calibDcRangeSig[0] = "calibDcRangeSig";
        iniCfgCmds.calibDcRangeSig[1] = "-1";
        iniCfgCmds.calibDcRangeSig[2] = "0";
        iniCfgCmds.calibDcRangeSig[3] = "-5";
        iniCfgCmds.calibDcRangeSig[4] = "8";
        iniCfgCmds.calibDcRangeSig[5] = "256";
        
        iniCfgCmds.extendedMaxVelocity[0] = "extendedMaxVelocity";
        iniCfgCmds.extendedMaxVelocity[1] = "-1";
        iniCfgCmds.extendedMaxVelocity[2] = "0";
        
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 0] = "compRangeBiasAndRxChanPhase";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 1] = "0.0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 2] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 3] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 4] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 5] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 6] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 7] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 8] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[ 9] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[10] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[11] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[12] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[13] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[14] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[15] = "0";
        iniCfgCmds.compRangeBiasAndRxChanPhase[16] = "1";
        iniCfgCmds.compRangeBiasAndRxChanPhase[17] = "0";
        
        iniCfgCmds.measureRangeBiasAndRxChanPhase[0] = "measureRangeBiasAndRxChanPhase";
        iniCfgCmds.measureRangeBiasAndRxChanPhase[1] = "0";
        iniCfgCmds.measureRangeBiasAndRxChanPhase[2] = "1.5";
        iniCfgCmds.measureRangeBiasAndRxChanPhase[3] = "0.2";
    
        iniCfgCmds.sensorStart[0] = "sensorStart";
    
        //arrays cannot be set like this in C; need to copy them, or set each pointer individually, as was done above
        //iniCfgCmds.sensorStop          = {"sensorStop"};
        //iniCfgCmds.flushCfg            = {"flushCfg"};
        //iniCfgCmds.dfeDataOutputMode   = {"dfeDataOutputMode", "1"};
        //iniCfgCmds.channelCfg          = {"channelCfg", "15", "3", "0"};
        //iniCfgCmds.adcCfg              = {"adcCfg", "2", "1"};
        //iniCfgCmds.adcbufCfg           = {"adcbufCfg", "0", "0", "1", "1"};
        //iniCfgCmds.profileCfg          = {"profileCfg", "0", "77", "194", "7", "40", "0", "0", "100", "1", "64", "2000", "0", "0", "30"};
        //iniCfgCmds.chirpCfg1           = {"chirpCfg1", "0", "0", "0", "0", "0", "0", "0", "1"};
        //iniCfgCmds.chirpCfg2           = {"chirpCfg2", "1", "1", "0", "0", "0", "0", "0", "2"};
        //iniCfgCmds.frameCfg            = {"frameCfg", "0", "1", "16", "0", "100", "1", "0"};
        //iniCfgCmds.guiMonitor          = {"guiMonitor", "1", "0", "0", "0", "0", "0"};
        //iniCfgCmds.cfarCfgRange        = {"cfarCfg", "0", "0", "8", "4", "4", "0", "3413"};
        //iniCfgCmds.cfarCfgDoppler      = {"cfarCfg", "1", "0", "4", "2", "3", "0", "5120"};
        //iniCfgCmds.peakGrouping        = {"peakGrouping", "1", "1", "1", "1", "63"};
        //iniCfgCmds.multiObjBeamForming = {"multiObjBeamForming", "1", "0.5"};
        //iniCfgCmds.calibDcRangeSig     = {"calibDcRangeSig", "1", "-5", "20", "256"};
        //iniCfgCmds.sensorStart         = {"sensorStart"};
    
        MmwDemo_CfgWithCmdString ( 1, iniCfgCmds.sensorStop         			);
        System_printf ("3sensorStop done\n");
        for (c = 1 ; c <= 50000000 ; c++); //this delay ensures the sensor stops
        System_printf ("3delay done\n");
        MmwDemo_CfgWithCmdString ( 1, iniCfgCmds.flushCfg           			);
        System_printf ("3flushCfg done\n");
        MmwDemo_CfgWithCmdString ( 2, iniCfgCmds.dfeDataOutputMode  			);
        System_printf ("3dfeDataOutputMode done\n");
        MmwDemo_CfgWithCmdString ( 4, iniCfgCmds.channelCfg         			);
        System_printf ("3channelCfg done\n");
        MmwDemo_CfgWithCmdString ( 3, iniCfgCmds.adcCfg             			);
        System_printf ("3adcCfg done\n");
        MmwDemo_CfgWithCmdString ( 6, iniCfgCmds.adcbufCfg          			);
        System_printf ("3adcbufCfg done\n");
        MmwDemo_CfgWithCmdString (15, iniCfgCmds.profileCfg         			);
        System_printf ("3profileCfg done\n");
        MmwDemo_CfgWithCmdString ( 9, iniCfgCmds.chirpCfg1          			);
        System_printf ("3chirpCfg1 done\n");
        MmwDemo_CfgWithCmdString ( 9, iniCfgCmds.chirpCfg2          			);
        System_printf ("3chirpCfg2 done\n");
        MmwDemo_CfgWithCmdString ( 8, iniCfgCmds.frameCfg           			);
        System_printf ("3frameCfg done\n");
        System_printf ("3guiMonitor start\n");
        MmwDemo_CfgWithCmdString ( 8, iniCfgCmds.guiMonitor         			);
        System_printf ("3guiMonitor done\n");
        MmwDemo_CfgWithCmdString ( 9, iniCfgCmds.cfarCfgRange       			);
        System_printf ("3cfarCfgRange done\n");
        MmwDemo_CfgWithCmdString ( 9, iniCfgCmds.cfarCfgDoppler     			);
        System_printf ("3cfarCfgDoppler done\n");
        MmwDemo_CfgWithCmdString ( 7, iniCfgCmds.peakGrouping       			);
        System_printf ("3peakGrouping done\n");
        MmwDemo_CfgWithCmdString ( 4, iniCfgCmds.multiObjBeamForming			);
        System_printf ("3multiObjBeamForming done\n");
        MmwDemo_CfgWithCmdString ( 3, iniCfgCmds.clutterRemoval					);
        System_printf ("3clutterRemoval done\n");
        MmwDemo_CfgWithCmdString ( 6, iniCfgCmds.calibDcRangeSig				);
        System_printf ("3calibDcRangeSig done\n");
        MmwDemo_CfgWithCmdString ( 3, iniCfgCmds.extendedMaxVelocity			);
        System_printf ("3extendedMaxVelocity done\n");
        MmwDemo_CfgWithCmdString (18, iniCfgCmds.compRangeBiasAndRxChanPhase	);
        System_printf ("3compRangeBiasAndRxChanPhase done\n");
        MmwDemo_CfgWithCmdString ( 4, iniCfgCmds.measureRangeBiasAndRxChanPhase	);
        System_printf ("3measureRangeBiasAndRxChanPhase done\n");
        MmwDemo_CfgWithCmdString ( 1, iniCfgCmds.sensorStart        			);
        System_printf ("3sensorStart done\n");
    
        return;
    }
    
    
    6712.ini_cfg.h
    /*
     *   @file  cli.c
     *
     *   @brief
     *      Mmw (Milli-meter wave) DEMO CLI Implementation
     *
     *  \par
     *  NOTE:
     *      (C) Copyright 2016 Texas Instruments, Inc.
     *
     *  Redistribution and use in source and binary forms, with or without
     *  modification, are permitted provided that the following conditions
     *  are met:
     *
     *    Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     *    Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the
     *    distribution.
     *
     *    Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /**************************************************************************
     *************************** Include Files ********************************
     **************************************************************************/
    
    /* Standard Include Files. */
    #include <stdint.h>
    #include <stdlib.h>
    #include <stddef.h>
    #include <string.h>
    #include <stdio.h>
    
    /* BIOS/XDC Include Files. */
    #include <xdc/std.h>
    #include <xdc/cfg/global.h>
    #include <xdc/runtime/IHeap.h>
    #include <xdc/runtime/System.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/Memory.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    #include <ti/sysbios/knl/Event.h>
    #include <ti/sysbios/knl/Semaphore.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/heaps/HeapBuf.h>
    #include <ti/sysbios/heaps/HeapMem.h>
    #include <ti/sysbios/knl/Event.h>
    
    /* mmWave SDK Include Files: */
    #include <ti/common/sys_common.h>
    #include <ti/common/mmwave_sdk_version.h>
    #include <ti/drivers/uart/UART.h>
    #include <ti/control/mmwavelink/mmwavelink.h>
    #include <ti/utils/cli/cli.h>
    #include <ti/utils/cli/include/cli_internal.h>
    
    /* Demo Include Files */
    #include "ti/demo/xwr16xx/mmw/mss/mss_mmw.h"
    #include "ti/demo/xwr16xx/mmw/mss/ini_cfg.h"
    #include "ti/demo/xwr16xx/mmw/common/mmw_messages.h"
    
    /**************************************************************************
     *************************** Local Definitions ****************************
     **************************************************************************/
    /* CLI Extended Command Functions */
    /*static*/ int32_t MmwDemo_CLICfarCfg (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIPeakGroupingCfg (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIMultiObjBeamForming (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLICalibDcRangeSig (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIExtendedMaxVelocity (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIClutterRemoval (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLISensorStart (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLISensorStop (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIGuiMonSel (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLISetDataLogger (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIADCBufCfg (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg (int32_t argc, char* argv[]);
    /*static*/ int32_t MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg (int32_t argc, char* argv[]);
    
    /**************************************************************************
     *************************** Extern Definitions *******************************
     **************************************************************************/
    
    extern MmwDemo_MCB    gMmwMssMCB;
    extern int32_t MmwDemo_mboxWrite(MmwDemo_message     * message);
    
    /**************************************************************************
     *************************** CLI  Function Definitions ********************
     **************************************************************************/
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for the sensor start command
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLISensorStart (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLISensorStart START\n");
        bool doReconfig = true;
        if (argc==2)
        {
            doReconfig = (bool) atoi (argv[1]);
        }
        /* Post sensorSTart event to notify configuration is done */
        MmwDemo_notifySensorStart(doReconfig);
        /* Pend for completion */
        return (MmwDemo_waitSensorStartComplete());
    }
    
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for the sensor stop command
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLISensorStop (int32_t argc, char* argv[])
    {
    	/* Post sensorSTOP event to notify sensor stop command */
        MmwDemo_notifySensorStop();
        /* Pend for completion */
        MmwDemo_waitSensorStopComplete();
        return 0;
    }
    
    static int32_t MmwDemo_CLIGetSubframe (int32_t argc, char* argv[], int32_t expectedArgc, int8_t* subFrameNum)
    {
        System_printf ("MmwDemo_CLIGetSubframe() START\n");
        int8_t subframe;
        
        /* Sanity Check: Minimum argument check */
        if (argc != expectedArgc)
        {
            CLI_write ("Error: Invalid usage of the CLI command\n");
            return -1;
        }
    
        /*Subframe info is always in position 1*/
        subframe = (int8_t) atoi(argv[1]);
    
        if(subframe >= (int8_t)RL_MAX_SUBFRAMES)
        {
            CLI_write ("Error: Subframe number is invalid\n");
            return -1;
        }
        
        *subFrameNum = (int8_t)subframe;
    
        return 0;
    }
    
    static void MmwDemo_mssCfgUpdate(void *srcPtr, uint32_t offset, uint32_t size, int8_t subFrameNum)
    {
        System_printf ("MmwDemo_mssCfgUpdate() START\n");    
        /* if subFrameNum undefined, broadcast to all sub-frames */
        if(subFrameNum == MMWDEMO_SUBFRAME_NUM_FRAME_LEVEL_CONFIG)
        {
            uint8_t  indx;
            for(indx = 0; indx < RL_MAX_SUBFRAMES; indx++)
            {
                memcpy((void *)((uint32_t) &gMmwMssMCB.cliCfg[indx] + offset), srcPtr, size);
            }
            
        }
        else
        {
            /* Apply configuration to specific subframe (or to position zero for the legacy case
               where there is no advanced frame config) */
            memcpy((void *)((uint32_t) &gMmwMssMCB.cliCfg[subFrameNum] + offset), srcPtr, size);
        }
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for gui monitoring configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIGuiMonSel (int32_t argc, char* argv[])
    {
        MmwDemo_GuiMonSel   guiMonSel;
        MmwDemo_message     message;
        int8_t              subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 8, &subFrameNum) < 0)
        {
            return -1;
        }
        System_printf ("MmwDemo_CLIGuiMonSel(): subFrameNum=[%d]\n", subFrameNum);
    
        /* Initialize the guiMonSel configuration: */
        memset ((void *)&guiMonSel, 0, sizeof(MmwDemo_GuiMonSel));
    
        /* Populate configuration: */
        System_printf("%d %d %d %d %d %d %d\n", atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5]), atoi(argv[6]), atoi(argv[7]));
        guiMonSel.detectedObjects           = atoi (argv[2]);
        guiMonSel.logMagRange               = atoi (argv[3]);
        guiMonSel.noiseProfile              = atoi (argv[4]);
        guiMonSel.rangeAzimuthHeatMap       = atoi (argv[5]);
        guiMonSel.rangeDopplerHeatMap       = atoi (argv[6]);
        guiMonSel.statsInfo                 = atoi (argv[7]);
    
        /* Save Configuration to use later */
        //memcpy((void *)&gMmwMssMCB.cfg.guiMonSel, (void *)&guiMonSel, sizeof(MmwDemo_GuiMonSel));
        MmwDemo_mssCfgUpdate((void *)&guiMonSel, offsetof(MmwDemo_CliCfg_t, guiMonSel), sizeof(MmwDemo_GuiMonSel), subFrameNum);
        System_printf ("MmwDemo_CLIGuiMonSel(): gMmwMssMCB.cliCfg[0] [%d %d %d %d %d %d]\n",
                       gMmwMssMCB.cliCfg[0].guiMonSel.detectedObjects,
                       gMmwMssMCB.cliCfg[0].guiMonSel.logMagRange,
                       gMmwMssMCB.cliCfg[0].guiMonSel.noiseProfile,
                       gMmwMssMCB.cliCfg[0].guiMonSel.rangeAzimuthHeatMap,
                       gMmwMssMCB.cliCfg[0].guiMonSel.rangeDopplerHeatMap,
                       gMmwMssMCB.cliCfg[0].guiMonSel.statsInfo);
        System_printf ("MmwDemo_CLIGuiMonSel(): gMmwMssMCB.cliCfg[1] [%d %d %d %d %d %d]\n",
                       gMmwMssMCB.cliCfg[1].guiMonSel.detectedObjects,
                       gMmwMssMCB.cliCfg[1].guiMonSel.logMagRange,
                       gMmwMssMCB.cliCfg[1].guiMonSel.noiseProfile,
                       gMmwMssMCB.cliCfg[1].guiMonSel.rangeAzimuthHeatMap,
                       gMmwMssMCB.cliCfg[1].guiMonSel.rangeDopplerHeatMap,
                       gMmwMssMCB.cliCfg[1].guiMonSel.statsInfo);
        System_printf ("MmwDemo_CLIGuiMonSel(): gMmwMssMCB.cliCfg[2] [%d %d %d %d %d %d]\n",
                       gMmwMssMCB.cliCfg[2].guiMonSel.detectedObjects,
                       gMmwMssMCB.cliCfg[2].guiMonSel.logMagRange,
                       gMmwMssMCB.cliCfg[2].guiMonSel.noiseProfile,
                       gMmwMssMCB.cliCfg[2].guiMonSel.rangeAzimuthHeatMap,
                       gMmwMssMCB.cliCfg[2].guiMonSel.rangeDopplerHeatMap,
                       gMmwMssMCB.cliCfg[2].guiMonSel.statsInfo);
        System_printf ("MmwDemo_CLIGuiMonSel(): gMmwMssMCB.cliCfg[3] [%d %d %d %d %d %d]\n",
                       gMmwMssMCB.cliCfg[3].guiMonSel.detectedObjects,
                       gMmwMssMCB.cliCfg[3].guiMonSel.logMagRange,
                       gMmwMssMCB.cliCfg[3].guiMonSel.noiseProfile,
                       gMmwMssMCB.cliCfg[3].guiMonSel.rangeAzimuthHeatMap,
                       gMmwMssMCB.cliCfg[3].guiMonSel.rangeDopplerHeatMap,
                       gMmwMssMCB.cliCfg[3].guiMonSel.statsInfo);
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_GUIMON_CFG;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.guiMonSel, (void *)&guiMonSel, sizeof(MmwDemo_GuiMonSel));
        System_printf("message.body.guiMonSel sz=[%d], guiMonSel sz=[%d]\n", sizeof(message.body.guiMonSel), sizeof(MmwDemo_GuiMonSel));
    
        if (MmwDemo_mboxWrite(&message) == 0) {
            System_printf("MmwDemo_CLIGuiMonSel: MmwDemo_mboxWrite 0\n");
            return 0;
        }
        else {
            System_printf("MmwDemo_CLIGuiMonSel: MmwDemo_mboxWrite -1\n");
            return -1;
        }
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for CFAR configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLICfarCfg (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLICfarCfg START\n");
        MmwDemo_CfarCfg     cfarCfg;
        MmwDemo_message     message;
        uint32_t            procDirection;
        int8_t              subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 9, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration: */
        memset ((void *)&cfarCfg, 0, sizeof(MmwDemo_CfarCfg));
    
        /* Populate configuration: */
        procDirection             = (uint32_t) atoi (argv[2]);
        cfarCfg.averageMode       = (uint8_t) atoi (argv[3]);
        cfarCfg.winLen            = (uint8_t) atoi (argv[4]);
        cfarCfg.guardLen          = (uint8_t) atoi (argv[5]);
        cfarCfg.noiseDivShift     = (uint8_t) atoi (argv[6]);
        cfarCfg.cyclicMode        = (uint8_t) atoi (argv[7]);
        cfarCfg.thresholdScale    = (uint16_t) atoi (argv[8]);
    
        /* Save Configuration to use later */     
        //memcpy((void *)&gMmwMssMCB.cliCfg.cfarCfg[procDirection], (void *)&cfarCfg, sizeof(MmwDemo_CfarCfg));
        if (procDirection == 0)
        {
            MmwDemo_mssCfgUpdate((void *)&cfarCfg, offsetof(MmwDemo_CliCfg_t, cfarCfgRange),
                sizeof(MmwDemo_CfarCfg), subFrameNum);
        }
        else
        {
            MmwDemo_mssCfgUpdate((void *)&cfarCfg, offsetof(MmwDemo_CliCfg_t, cfarCfgDoppler),
                sizeof(MmwDemo_CfarCfg), subFrameNum);
        }
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
        if (procDirection == 0)
        {
            message.type = MMWDEMO_MSS2DSS_CFAR_RANGE_CFG;
        }
        else if (procDirection == 1)
        {
            message.type = MMWDEMO_MSS2DSS_CFAR_DOPPLER_CFG;
        }
        else
        {
            return -1;
        }
    
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.cfarCfg, (void *)&cfarCfg, sizeof(MmwDemo_CfarCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;    
    }
    
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for Peak grouping configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIPeakGroupingCfg (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLIPeakGroupingCfg START\n");
        MmwDemo_PeakGroupingCfg peakGroupingCfg;
        MmwDemo_message         message;
        int8_t                  subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 7, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration: */
        memset ((void *)&peakGroupingCfg, 0, sizeof(MmwDemo_PeakGroupingCfg));
    
        /* Populate configuration: */
        peakGroupingCfg.scheme               = (uint8_t) atoi (argv[2]);
        peakGroupingCfg.inRangeDirectionEn   = (uint8_t) atoi (argv[3]);
        peakGroupingCfg.inDopplerDirectionEn = (uint8_t) atoi (argv[4]);
        peakGroupingCfg.minRangeIndex    = (uint16_t) atoi (argv[5]);
        peakGroupingCfg.maxRangeIndex    = (uint16_t) atoi (argv[6]);
    
        if (peakGroupingCfg.scheme != 1 && peakGroupingCfg.scheme != 2)
        {
            CLI_write ("Error: Invalid peak grouping scheme\n");
            return -1;
        }
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&peakGroupingCfg, offsetof(MmwDemo_CliCfg_t, peakGroupingCfg),
            sizeof(MmwDemo_PeakGroupingCfg), subFrameNum);
        //memcpy((void *)&gMmwMssMCB.cfg.peakGroupingCfg, (void *)&peakGroupingCfg, sizeof(MmwDemo_PeakGroupingCfg));
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_PEAK_GROUPING_CFG;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.peakGroupingCfg, (void *)&peakGroupingCfg, sizeof(MmwDemo_PeakGroupingCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for multi object beam forming configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIMultiObjBeamForming (int32_t argc, char* argv[])
    {
    	//System_printf ("MmwDemo_CLIMultiObjBeamForming START\n");
        MmwDemo_MultiObjBeamFormingCfg cfg;
        MmwDemo_message     message;
        int8_t              subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 4, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration: */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_MultiObjBeamFormingCfg));
    
        /* Populate configuration: */
        cfg.enabled                     = (uint8_t) atoi (argv[2]);
        cfg.multiPeakThrsScal           = (float) atof (argv[3]);
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&cfg, offsetof(MmwDemo_CliCfg_t, multiObjBeamFormingCfg),
            sizeof(MmwDemo_MultiObjBeamFormingCfg), subFrameNum);
        //memcpy((void *)&gMmwMssMCB.cfg.multiObjBeamFormingCfg, (void *)&cfg, sizeof(MmwDemo_MultiObjBeamFormingCfg));
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_MULTI_OBJ_BEAM_FORM;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.multiObjBeamFormingCfg, (void *)&cfg, sizeof(MmwDemo_MultiObjBeamFormingCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    uint32_t log2Approx(uint32_t x)
    {
    	//System_printf ("log2Approx START\n");
        uint32_t idx, detectFlag = 0;
    
        if ( x < 2)
        {
            return (0);
        }
    
        idx = 32U;
        while((detectFlag==0U) || (idx==0U))
        {
            if(x & 0x80000000U)
            {
                detectFlag = 1;
            }
            x <<= 1U;
            idx--;
        }
    
        if(x != 0)
        {
            idx = idx + 1;
        }
    
        return(idx);
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for DC range calibration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLICalibDcRangeSig (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLICalibDcRangeSig START\n");
        MmwDemo_CalibDcRangeSigCfg cfg;
        MmwDemo_message            message;
        uint32_t                   log2NumAvgChirps;
        int8_t                     subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 6, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration for DC range signature calibration */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_CalibDcRangeSigCfg));
    
        /* Populate configuration: */
        cfg.enabled          = (uint16_t) atoi (argv[2]);
        cfg.negativeBinIdx   = (int16_t)  atoi (argv[3]);
        cfg.positiveBinIdx   = (int16_t)  atoi (argv[4]);
        cfg.numAvgChirps     = (uint16_t)  atoi (argv[5]);
    
        if (cfg.negativeBinIdx > 0)
        {
            CLI_write ("Error: Invalid negative bin index\n");
            return -1;
        }
        if ((cfg.positiveBinIdx - cfg.negativeBinIdx + 1) > DC_RANGE_SIGNATURE_COMP_MAX_BIN_SIZE)
        {
            CLI_write ("Error: Number of bins exceeds the limit\n");
            return -1;
        }
        log2NumAvgChirps = (uint32_t) log2Approx (cfg.numAvgChirps);
        if (cfg.numAvgChirps != (1 << log2NumAvgChirps))
        {
            CLI_write ("Error: Number of averaged chirps is not power of two\n");
            return -1;
        }
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&cfg, offsetof(MmwDemo_CliCfg_t, calibDcRangeSigCfg),
            sizeof(MmwDemo_CalibDcRangeSigCfg), subFrameNum);
        //memcpy((void *)&gMmwMssMCB.cfg.calibDcRangeSigCfg, (void *)&cfg, sizeof(MmwDemo_CalibDcRangeSigCfg));
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_CALIB_DC_RANGE_SIG;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.calibDcRangeSigCfg, (void *)&cfg, sizeof(MmwDemo_CalibDcRangeSigCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for Velocity Disambiguation Configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIExtendedMaxVelocity (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLIExtendedMaxVelocity START\n");
        MmwDemo_ExtendedMaxVelocityCfg cfg;
        MmwDemo_message                message;
        int8_t                         subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 3, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration for DC range signature calibration */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_ExtendedMaxVelocityCfg));
    
        /* Populate configuration: */
        cfg.enabled          = (uint16_t) atoi (argv[2]);
    
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&cfg, offsetof(MmwDemo_CliCfg_t, extendedMaxVelocityCfg),
            sizeof(MmwDemo_ExtendedMaxVelocityCfg), subFrameNum);
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_EXTENDED_MAX_VELOCITY;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.extendedMaxVelocityCfg, (void *)&cfg, sizeof(MmwDemo_ExtendedMaxVelocityCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    /**
     *  @b Description
     *  @n
     *      Clutter removal Configuration
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIClutterRemoval (int32_t argc, char* argv[])
    {
    	//System_printf ("MmwDemo_CLIClutterRemoval START\n");
        MmwDemo_ClutterRemovalCfg cfg;
        MmwDemo_message     message;
        int8_t              subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 3, &subFrameNum) < 0)
        {
            return -1;
        }
    
        /* Initialize configuration for clutter removal */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_ClutterRemovalCfg));
    
        /* Populate configuration: */
        cfg.enabled          = (uint16_t) atoi (argv[2]);
    
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&cfg, offsetof(MmwDemo_CliCfg_t, clutterRemovalCfg),
            sizeof(MmwDemo_ClutterRemovalCfg), subFrameNum);
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_CLUTTER_REMOVAL;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.clutterRemovalCfg, (void *)&cfg, sizeof(MmwDemo_ClutterRemovalCfg));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for data logger set command
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLISetDataLogger (int32_t argc, char* argv[])
    {
    	System_printf ("MmwDemo_CLISetDataLogger START\n");
        MmwDemo_message     message;
    
        /* Sanity Check: Minimum argument check */
        if (argc != 2)
        {
            CLI_write ("Error: Invalid usage of the CLI command\n");
            return -1;
        }
    
    
        /* Save Configuration to use later */
        if (strcmp(argv[1], "mssLogger") == 0)  
            gMmwMssMCB.cfg.dataLogger = 0;
        else if (strcmp(argv[1], "dssLogger") == 0)  
            gMmwMssMCB.cfg.dataLogger = 1;
        else
        {
            CLI_write ("Error: Invalid usage of the CLI command\n");
            return -1;
        }
           
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
    
        message.type = MMWDEMO_MSS2DSS_SET_DATALOGGER;
        message.body.dataLogger = gMmwMssMCB.cfg.dataLogger;
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for data logger set command
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIADCBufCfg (int32_t argc, char* argv[])
    {
    	MmwDemo_ADCBufCfg   adcBufCfg;
        MmwDemo_message     message;
        int8_t              subFrameNum;
    
        if(MmwDemo_CLIGetSubframe(argc, argv, 6, &subFrameNum) < 0)
        {
            System_printf ("Error: MmwDemo_CLIADCBufCfg error\n");
            return -1;
        }
    
        System_printf ("Debug: MmwDemo_CLIADCBufCfg\n");
    
        /* Initialize the ADC Output configuration: */
        memset ((void *)&adcBufCfg, 0, sizeof(MmwDemo_ADCBufCfg));
    
        /* Populate configuration: */
        adcBufCfg.adcFmt          = (uint8_t) atoi (argv[2]);
        adcBufCfg.iqSwapSel       = (uint8_t) atoi (argv[3]);
        adcBufCfg.chInterleave    = (uint8_t) atoi (argv[4]);
        adcBufCfg.chirpThreshold  = (uint8_t) atoi (argv[5]);
    
        /* Save Configuration to use later */
        MmwDemo_mssCfgUpdate((void *)&adcBufCfg, offsetof(MmwDemo_CliCfg_t, adcBufCfg),
            sizeof(MmwDemo_ADCBufCfg), subFrameNum);
    
        System_printf ("2Debug: MmwDemo_CLIADCBufCfg\n");
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
        message.type = MMWDEMO_MSS2DSS_ADCBUFCFG;
        message.subFrameNum = subFrameNum;
        memcpy((void *)&message.body.adcBufCfg, (void *)&adcBufCfg, sizeof(MmwDemo_ADCBufCfg));
    
        System_printf ("3Debug: MmwDemo_CLIADCBufCfg\n");
    
        if (MmwDemo_mboxWrite(&message) == 0) {
            System_printf ("4Debug: MmwDemo_CLIADCBufCfg\n");
            return 0;
        }
        else {
            System_printf ("5Debug: MmwDemo_CLIADCBufCfg\n");
            return -1;
        }
    }
    
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for compensation of range bias and channel phase offsets
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg (int32_t argc, char* argv[])
    {
    	//System_printf ("MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg START\n");
        MmwDemo_compRxChannelBiasCfg_t   cfg;
        MmwDemo_message     message;
        int32_t Re, Im;
        int32_t argInd;
        int32_t i;
    
        /* Sanity Check: Minimum argument check */
        if (argc != (1+1+SYS_COMMON_NUM_TX_ANTENNAS*SYS_COMMON_NUM_RX_CHANNEL*2))
        {
            CLI_write ("Error: Invalid usage of the CLI command\n");
            return -1;
        }
    
        /* Initialize configuration: */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_compRxChannelBiasCfg_t));
    
        /* Populate configuration: */
        cfg.rangeBias          = (float) atof (argv[1]);
    
        argInd = 2;
        for (i=0; i < SYS_COMMON_NUM_TX_ANTENNAS*SYS_COMMON_NUM_RX_CHANNEL; i++)
        {
            Re = (int32_t) (atof (argv[argInd++]) * 32768.);
            Re = MMWDEMO_SATURATE_HIGH(Re);
            Re = MMWDEMO_SATURATE_LOW(Re);
            cfg.rxChPhaseComp[i].real = (int16_t) Re;
    
            Im = (int32_t) (atof (argv[argInd++]) * 32768.);
            Im = MMWDEMO_SATURATE_HIGH(Im);
            Im = MMWDEMO_SATURATE_LOW(Im);
            cfg.rxChPhaseComp[i].imag = (int16_t) Im;
    
        }
        /* Save Configuration to use later */
        memcpy((void *) &gMmwMssMCB.cliCommonCfg.compRxChanCfg, &cfg, sizeof(MmwDemo_compRxChannelBiasCfg_t));
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
        message.type = MMWDEMO_MSS2DSS_COMP_RANGE_BIAS_AND_RX_CHAN_PHASE;
        memcpy((void *)&message.body.compRxChanCfg, (void *)&cfg, sizeof(MmwDemo_compRxChannelBiasCfg_t));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Handler for measurement configuration of range bias
     *      and channel phase offsets
     *
     *  @param[in] argc
     *      Number of arguments
     *  @param[in] argv
     *      Arguments
     *
     *  @retval
     *      Success -   0
     *  @retval
     *      Error   -   <0
     */
    int32_t MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg (int32_t argc, char* argv[])
    {
    	//System_printf ("MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg START\n");
        MmwDemo_measureRxChannelBiasCfg_t   cfg;
        MmwDemo_message     message;
    
        /* Sanity Check: Minimum argument check */
        if (argc != 4)
        {
            CLI_write ("Error: Invalid usage of the CLI command\n");
            return -1;
        }
    
        /* Initialize configuration: */
        memset ((void *)&cfg, 0, sizeof(MmwDemo_measureRxChannelBiasCfg_t));
    
        /* Populate configuration: */
        cfg.enabled          = (uint8_t) atoi (argv[1]);
        cfg.targetDistance   = (float) atof (argv[2]);
        cfg.searchWinSize   = (float) atof (argv[3]);
    
        /* Save Configuration to use later */
        memcpy((void *) &gMmwMssMCB.cliCommonCfg.measureRxChanCfg, &cfg, sizeof(MmwDemo_measureRxChannelBiasCfg_t));
    
        /* Send configuration to DSS */
        memset((void *)&message, 0, sizeof(MmwDemo_message));
        message.type = MMWDEMO_MSS2DSS_MEASURE_RANGE_BIAS_AND_RX_CHAN_PHASE;
        memcpy((void *)&message.body.measureRxChanCfg, (void *)&cfg, sizeof(MmwDemo_measureRxChannelBiasCfg_t));
    
        if (MmwDemo_mboxWrite(&message) == 0)
            return 0;
        else
            return -1;
    }
    
    //static int32_t MmwDemo_CLIProfileCfg (int32_t argc, char* argv[])
    //{
    //	CLI_write ("MmwDemo_CLIProfileCfg START\n");
    //    rlProfileCfg_t          profileCfg;
    //    uint8_t                 index;
    //    int32_t                 errCode;
    //    MMWave_ProfileHandle    profileHandle;
    //    MMWave_ProfileHandle*   ptrBaseCfgProfileHandle;
    //
    //    /* Sanity Check: Minimum argument check */
    //    if (argc != 15)
    //    {
    //        CLI_write ("Error: Invalid usage of the CLI command\n");
    //        return -1;
    //    }
    //
    //    CLI_write ("MmwDemo_CLIProfileCfg argc==15\n");
    //
    //    /* Sanity Check: Profile configuration is valid only for the Frame or
    //                     Advanced Frame Mode: */
    //    /*
    //    if ((gCLIMMWaveControlCfg.dfeDataOutputMode != MMWave_DFEDataOutputMode_FRAME) &&
    //        (gCLIMMWaveControlCfg.dfeDataOutputMode != MMWave_DFEDataOutputMode_ADVANCED_FRAME))
    //    {
    //        CLI_write ("Error: Configuration is valid only if the DFE Output Mode is Frame or Advanced Frame\n");
    //        return -1;
    //    }
    //
    //    if (gCLIMMWaveControlCfg.dfeDataOutputMode == MMWave_DFEDataOutputMode_FRAME)
    //    {
    //        ptrBaseCfgProfileHandle = &gCLIMMWaveControlCfg.u.frameCfg.profileHandle[0U];
    //    }
    //    else
    //    {
    //        ptrBaseCfgProfileHandle = &gCLIMMWaveControlCfg.u.advancedFrameCfg.profileHandle[0U];
    //    }
    //    */
    //
    //    /* Initialize the profile configuration: */
    //    memset ((void *)&profileCfg, 0, sizeof(rlProfileCfg_t));
    //
    //    /* Populate the profile configuration: */
    //    profileCfg.profileId             = atoi (argv[1]);
    //    profileCfg.startFreqConst        = (uint32_t) (atof(argv[2]) * (1U << 26) / 3.6);
    //    profileCfg.idleTimeConst         = (uint32_t)((float)atof (argv[3]) * 1000 / 10);
    //    profileCfg.adcStartTimeConst     = (uint32_t)((float)atof (argv[4]) * 1000 / 10);
    //    profileCfg.rampEndTime           = (uint32_t)((float)atof (argv[5]) * 1000 / 10);
    //    profileCfg.txOutPowerBackoffCode = atoi (argv[6] );
    //    profileCfg.txPhaseShifter        = atoi (argv[7]);
    //    profileCfg.freqSlopeConst        = (int16_t)(atof (argv[8]) * (1U << 26) / (3.6*1e3*900)); //2^26 * 1e6/((3.6*1e9)*900)
    //    profileCfg.txStartTime           = (uint32_t)((float)atof (argv[9]) * 1000 / 10);
    //    profileCfg.numAdcSamples         = atoi (argv[10]);
    //    profileCfg.digOutSampleRate      = atoi (argv[11]);
    //    profileCfg.hpfCornerFreq1        = atoi (argv[12]);
    //    profileCfg.hpfCornerFreq2        = atoi (argv[13]);
    //    profileCfg.rxGain                = atoi (argv[14]);
    //
    //    /* Search for a free space in the mmWave configuration block: */
    //    for (index = 0U; index < MMWAVE_MAX_PROFILE; index++)
    //    {
    //        /* Did we get a free entry? */
    //        if (ptrBaseCfgProfileHandle[index] == NULL)
    //        {
    //            /* YES: We can add the profile. */
    //            break;
    //        }
    //    }
    //    if (index == MMWAVE_MAX_PROFILE)
    //    {
    //        /* Error: All the profiles have been exhausted */
    //        CLI_write ("MmwDemo_CLIProfileCfg index==MMWAVE_MAX_PROFILE\n");
    //        return -1;
    //    }
    //
    //    /* Add the profile to the mmWave module: */
    //    profileHandle = MMWave_addProfile (gMmwMssMCB.ctrlHandle, &profileCfg, &errCode);
    //    if (profileHandle == NULL)
    //    {
    //        /* Error: Unable to add the profile. Return the error code back */
    //        CLI_write ("MmwDemo_CLIProfileCfg profileHandle==NULL\n");
    //        return errCode;
    //    }
    //
    //    /* Record the profile: */
    //    ptrBaseCfgProfileHandle[index] = profileHandle;
    //    return 0;
    //}
    
    /**
     *  @b Description
     *  @n
     *      This is the CLI Execution Task
     *
     *  @retval
     *      Not Applicable.
     */
    void MmwDemo_CLIInit (void)
    {
    	//System_printf ("MmwDemo_CLIInit START\n");
        CLI_Cfg     cliCfg;
        char        demoBanner[256];
        uint32_t    cnt;
    
        /* Create Demo Banner to be printed out by CLI */
        sprintf(&demoBanner[0], 
                           "******************************************\n" \
                           "xWR16xx MMW Demo (((SRR 201801021033))) %02d.%02d.%02d.%02d\n"  \
                           "******************************************\n", 
                            MMWAVE_SDK_VERSION_MAJOR,
                            MMWAVE_SDK_VERSION_MINOR,
                            MMWAVE_SDK_VERSION_BUGFIX,
                            MMWAVE_SDK_VERSION_BUILD
                );
    
        /* Initialize the CLI configuration: */
        memset ((void *)&cliCfg, 0, sizeof(CLI_Cfg));
    
        /* Populate the CLI configuration: */
        cliCfg.cliPrompt                    = "mmwDemo:/>";
        cliCfg.cliBanner                    = demoBanner;
        cliCfg.cliUartHandle                = gMmwMssMCB.commandUartHandle;
        cliCfg.taskPriority                 = 3;
        cliCfg.mmWaveHandle                 = gMmwMssMCB.ctrlHandle;
        cliCfg.enableMMWaveExtension        = 1U;
        cliCfg.usePolledMode                = true;
        cnt=0;
        cliCfg.tableEntry[cnt].cmd            = "sensorStart";
        cliCfg.tableEntry[cnt].helpString     = "[doReconfig(optional, default:enabled)]";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLISensorStart;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "sensorStop";
        cliCfg.tableEntry[cnt].helpString     = "No arguments";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLISensorStop;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "guiMonitor";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <detectedObjects> <logMagRange> <noiseProfile> <rangeAzimuthHeatMap> <rangeDopplerHeatMap> <statsInfo>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIGuiMonSel;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "cfarCfg";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <procDirection> <averageMode> <winLen> <guardLen> <noiseDiv> <cyclicMode> <thresholdScale>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLICfarCfg;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "peakGrouping";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <groupingMode> <rangeDimEn> <dopplerDimEn> <startRangeIdx> <endRangeIdx>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIPeakGroupingCfg;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "dataLogger";
        cliCfg.tableEntry[cnt].helpString     = "<mssLogger | dssLogger>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLISetDataLogger;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "multiObjBeamForming";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <enabled> <threshold>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIMultiObjBeamForming;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "calibDcRangeSig";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <enabled> <negativeBinIdx> <positiveBinIdx> <numAvgFrames>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLICalibDcRangeSig;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "extendedMaxVelocity";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <enabled>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIExtendedMaxVelocity;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "clutterRemoval";
        cliCfg.tableEntry[cnt].helpString     = "<enabled>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIClutterRemoval;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "adcbufCfg";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <adcOutputFmt> <SampleSwap> <ChanInterleave> <ChirpThreshold>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIADCBufCfg;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "compRangeBiasAndRxChanPhase";
        cliCfg.tableEntry[cnt].helpString     = "<rangeBias> <Re00> <Im00> <Re01> <Im01> <Re02> <Im02> <Re03> <Im03> <Re10> <Im10> <Re11> <Im11> <Re12> <Im12> <Re13> <Im13> ";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLICompRangeBiasAndRxChanPhaseCfg;
        cnt++;
    
        cliCfg.tableEntry[cnt].cmd            = "measureRangeBiasAndRxChanPhase";
        cliCfg.tableEntry[cnt].helpString     = "<enabled> <targetDistance> <searchWin>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIMeasureRangeBiasAndRxChanPhaseCfg;
        cnt++;
        
        /*
        cliCfg.tableEntry[cnt].cmd            = "profileCfg";
        cliCfg.tableEntry[cnt].helpString     = "<subFrameIdx> <groupingMode> <rangeDimEn> <dopplerDimEn> <startRangeIdx> <endRangeIdx>";
        cliCfg.tableEntry[cnt].cmdHandlerFxn  = MmwDemo_CLIProfileCfg;
        cnt++;
        */
    
        /* Open the CLI: */
        if (CLI_open (&cliCfg) < 0)
        {
            System_printf ("Error: Unable to open the CLI\n");
            return;
        }
        System_printf ("Debug: CLI is operational\n");
    
        //initial sensor configuration without CLI
        MmwDemo_IniRSSDSSCfg();
    
        return;
    }
    
    
    

    You can see the config commands are successful until guiMonitor -1 1 0 0 0 0 0

    Please guide me how to fix this.

    BRs,
    Zoe

  • Hi Sir,

    I just found one thing. If I set Breakpoint before MmwDemo_mboxWrite() and make sure stepInto Mailbox_write(). It works!! MSS receive ACK from DSS. Otherwise, the AWR1642 crashed if I run application directly. Is it because the work time by Mailbox_write() is not enough to deal with? How to avoid this error happen? Hope you can help me to check this problem. thank you.

    Best Regards,
    Zoe

  • Basically what you are trying to do is bypass CLI. Unfortunately, the way CLI is integrated into the demo, commands that are sent from the UART not only trigger communication with DSS (theC674 DSP) but also cause the sequence MMWave API calls to configure the BSS, running calibration, etc. All of this must be maintained if CLI is not used.

    A simpler way to do this is to just block copy the desired sequence of CLI commands into your UART terminal program (e.g. Tera-Term). If this chokes, you will need to edit the "Transmit delay", increasing the msec/char and msec/line delays until it works.

    If you still desire to embed your configuration into the demo, then you will need to trace each command from the CLI handler to DSS, noting what APIs are called and what configuration structures are updated. Then duplicate this without CLI. If it crashes (as you have shown above) then something isn't happening in the right order, or possibly not allowing each command to complete before starting the next.