TI-radar AWR1843 ARM-Cortex R4F core  1
mss_cli.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * @file mss_cli.c
3  * @brief MSS Minimal CLI Implementation
4  * @author A. Astro, a.astro7x@gmail.com
5  * @date Jan 13 2020
6  * @version 0.1
7  *******************************************************************************/
8 
9 /*(*)******************************************************************************
10  * INCLUDE FILES
11  **********************************************************************************/
12 
13 /* Standard Include Files. */
14 #include <common/app_cfg.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <stddef.h>
18 #include <string.h>
19 #include <stdio.h>
20 
21 /* BIOS/XDC Include Files. */
22 #include <xdc/runtime/System.h>
23 #include <ti/sysbios/BIOS.h>
24 #include <ti/sysbios/knl/Task.h>
25 #include <ti/sysbios/knl/Event.h>
26 #include <ti/sysbios/knl/Semaphore.h>
27 #include <ti/sysbios/knl/Clock.h>
28 #include <ti/sysbios/heaps/HeapBuf.h>
29 #include <ti/sysbios/heaps/HeapMem.h>
30 #include <ti/sysbios/knl/Event.h>
31 
32 /* mmWave SDK Include Files: */
33 #include <ti/common/sys_common.h>
34 #include <ti/drivers/uart/UART.h>
35 #include <ti/drivers/osal/DebugP.h>
36 #include <ti/control/mmwavelink/mmwavelink.h>
37 #include <ti/utils/cli/cli.h>
38 
39 /* Application Include Files: */
40 #include "common/mmWave_XSS.h"
41 
42 
43 /*(*)******************************************************************************
44  * MSS CLI SPECIFIC Functions
45  **********************************************************************************/
46 
47 static int32_t MSS_CLISensorStart (int32_t argc, char* argv[]);
48 static int32_t MSS_CLISensorStop (int32_t argc, char* argv[]);
49 static int32_t MSS_CLIBasicCfg (int32_t argc, char* argv[]);
50 static int32_t MSS_CLIAdvancedFrameCfg (int32_t argc, char* argv[]);
51 
52 
60 static int32_t MSS_CLISensorStart (int32_t argc, char* argv[])
61 {
62  MMWave_CalibrationCfg calibrationCfg;
63  int32_t errCode;
64 
65  if (gMCB.runningStatus == true) {
66 
67  /* Already running. */
68  return 0;
69  }
70  /* The sensor can only be started; if the link has been configured */
71  if (gMCB.cfgStatus == true) {
72 
73  /* Initialize the calibration configuration: */
74  memset ((void *)&calibrationCfg, 0, sizeof(MMWave_CalibrationCfg));
75 
76  /* Populate the calibration configuration: */
77  calibrationCfg.dfeDataOutputMode =
78  MMWave_DFEDataOutputMode_ADVANCED_FRAME;
79  calibrationCfg.u.chirpCalibrationCfg.enableCalibration = true;
80  calibrationCfg.u.chirpCalibrationCfg.enablePeriodicity = true;
81  calibrationCfg.u.chirpCalibrationCfg.periodicTimeInFrames = 10U;
82 
83  System_printf ("[MSS] \t [DEBUG] Sensor will start momentarily. \n");
84 
85  /* Start the mmWave: */
86  if (MMWave_start (gMCB.ctrlHandle, &calibrationCfg, &errCode) < 0) {
87 
88  /* Error: Unable to start the mmWave control module */
89  System_printf ("[MSS] \t [ERROR] mmWave start failed [Error code %d]\n", errCode);
90  return -1;
91  }
92 
93  gMCB.runningStatus = true;
94  return 0;
95  }
96  else {
97  /* Invalid CLI use case; doing a sensor start without executing the basic or advanced configuration
98  * command. Inform the user and return an error code. */
99  System_printf ("[MSS] \t [ERROR] Please ensure that the XXXCfg CLI command is invoked before starting the sensor\n");
100  return -1;
101  }
102 }
103 
111 static int32_t MSS_CLISensorStop (int32_t argc, char* argv[])
112 {
113  int32_t errCode;
114 
115  if (gMCB.runningStatus == false) {
116  return 0; // Already stopped.
117  }
118 
119  /* The sensor can only be stopped; if the link has been configured */
120  if (gMCB.cfgStatus == true) {
121  /* Stop the sensor */
122  if (MMWave_stop (gMCB.ctrlHandle, &errCode) < 0) {
123  /* Error: Unable to stop the mmWave control module */
124  System_printf ("Error: mmWave stop failed [Error code %d]\n", errCode);
125  return -1;
126  }
127  System_printf ("Debug: Sensor has been stopped\n");
128 
129  /* The link is no longer configured. */
130  gMCB.runningStatus = true;
131  return 0;
132  }
133  else {
134  /* Invalid CLI use case; doing a sensor stop multiple times. Inform the user and return an error code. */
135  System_printf ("Error: Sensor has already been stopped. Reconfigure and start the sensor if required\n");
136  return -1;
137  }
138 }
139 
147 static int32_t MSS_CLIBasicCfg (int32_t argc, char* argv[]) {
148 
149  MMWave_OpenCfg openCfg;
150  int32_t errCode;
151  rlProfileCfg_t profileCfg;
152  rlChirpCfg_t chirpCfg;
153  rlFrameCfg_t frameCfg;
154  int32_t retVal;
155 
156  if (gMCB.cfgStatus == true) {
157  /* Radar has already been configured. */
158  return 0;
159  }
160 
161  /* Setup the calibration frequency: */
162  openCfg.freqLimitLow = 760U;
163  openCfg.freqLimitHigh = 810U;
164  openCfg.defaultAsyncEventHandler = MMWave_DefaultAsyncEventHandler_MSS;
165 
166  /* Initialize the minimal configuration: */
167  Cfg_ChannelCfgInitParams (&openCfg.chCfg);
168  Cfg_LowPowerModeInitParams(&openCfg.lowPowerMode);
169  Cfg_ADCOutCfgInitParams (&openCfg.adcOutCfg);
170 
171  /* Open the mmWave module: */
172  if (MMWave_open (gMCB.ctrlHandle, &openCfg, NULL, &errCode) < 0) {
173  System_printf ("[MSS] \t [ERROR] mmWave open configuration failed [Error code %d]\n", errCode);
174  return -1;
175  }
176 
177  /********************************************************************************
178  * MMWave Link and BSS is operational now. In minimal mode we have access to all
179  * the mmWave Link API to perform the configuration
180  *
181  * Profile configuration:
182  ********************************************************************************/
183  Cfg_ProfileCfgInitParams (0U, &profileCfg);
184  retVal = rlSetProfileConfig (RL_DEVICE_MAP_INTERNAL_BSS, 1U, &profileCfg);
185  if (retVal != RL_RET_CODE_OK) {
186  System_printf ("[MSS] \t [ERROR] Unable to configure the profile [Error %d]\n", retVal);
187  return -1;
188  }
189 
190  /********************************************************************************
191  * Chirp configuration:
192  ********************************************************************************/
193  Cfg_ChirpCfgInitParams (0U, &chirpCfg);
194  retVal = rlSetChirpConfig(RL_DEVICE_MAP_INTERNAL_BSS, 1U, &chirpCfg);
195 
196  if (retVal != RL_RET_CODE_OK) {
197  System_printf ("[MSS] \t [ERROR] Unable to configure the chirp [Error %d]\n", retVal);
198  return -1;
199  }
200 
201  /********************************************************************************
202  * Frame configuration:
203  ********************************************************************************/
204  Cfg_FrameCfgInitParams (&frameCfg);
205  retVal = rlSetFrameConfig(RL_DEVICE_MAP_INTERNAL_BSS, &frameCfg);
206  if (retVal != RL_RET_CODE_OK) {
207  System_printf ("[MSS] \t [ERROR] Unable to configure the frame [Error %d]\n", retVal);
208  return -1;
209  }
210 
211  /* The link has been configured. */
212  gMCB.cfgStatus = true;
213  System_printf ("[MSS] \t [DEBUG] Basic configuration completed. Start the sensor...\n");
214  return 0;
215 }
216 
225 static int32_t MSS_CLIAdvancedFrameCfg (int32_t argc, char* argv[])
226 {
227  MMWave_OpenCfg openCfg;
228  int32_t errCode;
229  rlProfileCfg_t profileCfg;
230  rlChirpCfg_t chirpCfg;
231  rlAdvFrameCfg_t advFrameCfg;
232  int32_t retVal;
233  int32_t indx;
234  rlRfLdoBypassCfg_t rfLdoBypassCfg[1] = {0};
235 
236  if (gMCB.cfgStatus == true) {
237  /* Radar has already been configured. */
238  return 0;
239  }
240 
241  /* Setup the calibration frequency: */
242  openCfg.freqLimitLow = 760U;
243  openCfg.freqLimitHigh = 810U;
244  openCfg.defaultAsyncEventHandler = MMWave_DefaultAsyncEventHandler_MSS;
245 
246  /* Initialize the minimal configuration: */
247  Cfg_ChannelCfgInitParams (&openCfg.chCfg);
248  Cfg_LowPowerModeInitParams(&openCfg.lowPowerMode);
249  Cfg_ADCOutCfgInitParams (&openCfg.adcOutCfg);
250 
251  /* Open the mmWave module: */
252  if (MMWave_open (gMCB.ctrlHandle, &openCfg, NULL, &errCode) < 0) {
253  System_printf ("[MSS] \t [ERROR] mmWave open configuration failed [Error code %d]\n", errCode);
254  return -1;
255  }
256  System_printf ("Set LDO Bypass\n");
257  rfLdoBypassCfg->ldoBypassEnable = 0x03;
258  retVal = rlRfSetLdoBypassConfig(RL_DEVICE_MAP_INTERNAL_BSS, (rlRfLdoBypassCfg_t*)rfLdoBypassCfg);
259 
260  if (retVal != RL_RET_CODE_OK) {
261  System_printf ("[MSS] \t [ERROR] LDO Bypass config failed [Error %d]\n", retVal);
262  return -1;
263  }
264 
265 
266  /********************************************************************************
267  * MMWave Link and BSS is operational now. In minimal mode we have access to all
268  * the mmWave Link API to perform the configuration
269  *
270  * Profile configurations:
271  ********************************************************************************/
272  for (indx = 0; indx < NUM_PROFILES; indx++) {
273 
274  Cfg_ProfileCfgInitParams (indx, &profileCfg);
275  retVal = rlSetProfileConfig (RL_DEVICE_MAP_INTERNAL_BSS, 1U, &profileCfg);
276  if (retVal != RL_RET_CODE_OK) {
277  System_printf ("[MSS] \t [ERROR] Unable to configure the profile %d [Error %d]\n", indx, retVal);
278  return -1;
279  }
280  }
281 
282  /********************************************************************************
283  * Chirp configurations:
284  ********************************************************************************/
285  for (indx = 0; indx < NUM_CHIRP_PROG; indx++) {
286 
287  Cfg_ChirpCfgInitParams (indx, &chirpCfg);
288  retVal = rlSetChirpConfig(RL_DEVICE_MAP_INTERNAL_BSS, 1U, &chirpCfg);
289  if (retVal != RL_RET_CODE_OK) {
290 
291  System_printf ("Error: Unable to configure chirp %d [Error %d]\n", indx, retVal);
292  return -1;
293  }
294  }
295 
296  /* Advanced Frame configuration. */
297  Cfg_AdvFrameCfgInitParams (&advFrameCfg);
298  retVal = rlSetAdvFrameConfig(RL_DEVICE_MAP_INTERNAL_BSS, &advFrameCfg);
299  if (retVal != RL_RET_CODE_OK)
300  {
301  System_printf ("[MSS]\t [ERROR] Advanced Frame configuration failed [Error %d]\n", retVal);
302  return -1;
303  }
304 
305  /* The link has been configured. */
306  gMCB.cfgStatus = true;
307  System_printf ("[MSS] \t [DEBUG] MMWave has been configured.\n");
308  return 0;
309 }
310 
316 void MSS_CLIInit (void) {
317 
318  CLI_Cfg cliCfg;
319  static char* dummy[1];
320 
321  /* Initialize the CLI configuration: */
322  memset((void *)&cliCfg, 0, sizeof(CLI_Cfg));
323 
324  /* Populate the CLI configuration: */
325  cliCfg.cliPrompt = "mmWAVE FMCW Radar Design:/>";
326  cliCfg.cliUartHandle = gMCB.commandUartHandle;
327  cliCfg.taskPriority = 3;
328  cliCfg.mmWaveHandle = gMCB.ctrlHandle;
329  cliCfg.enableMMWaveExtension = 0U;
330  cliCfg.usePolledMode = true;
331  cliCfg.tableEntry[0].cmd = "basicCfg";
332  cliCfg.tableEntry[0].helpString = "Basic Cfg [Hardcoded Parameters]";
333  cliCfg.tableEntry[0].cmdHandlerFxn = MSS_CLIBasicCfg;
334 
335  cliCfg.tableEntry[1].cmd = "advFrameCfg";
336  cliCfg.tableEntry[1].helpString = "Advanced Frame Cfg [Hardcoded Parameters]";
337  cliCfg.tableEntry[1].cmdHandlerFxn = MSS_CLIAdvancedFrameCfg;
338 
339  cliCfg.tableEntry[2].cmd = "sensorStart";
340  cliCfg.tableEntry[2].helpString = "Start the sensor; ensure that the configuration is completed";
341  cliCfg.tableEntry[2].cmdHandlerFxn = MSS_CLISensorStart;
342 
343  cliCfg.tableEntry[3].cmd = "sensorStop";
344  cliCfg.tableEntry[3].helpString = "Stop the sensor";
345  cliCfg.tableEntry[3].cmdHandlerFxn = MSS_CLISensorStop;
346 
347  #if 0
348  /* Open the CLI: */
349  if (CLI_open (&cliCfg) < 0)
350  {
351  System_printf ("[MSS] \t [ERROR] Unable to open the CLI\n");
352  return;
353  }
354  System_printf ("[MSS] \t [DEBUG] CLI is operational\n");
355  #endif
356 
357  /* The link is not configured. */
358  gMCB.cfgStatus = false;
359  gMCB.runningStatus = false;
360  gMCB.isMMWaveOpen = false;
361 
362  MSS_CLIAdvancedFrameCfg(1, dummy);
363 
364  MSS_CLISensorStart(2, dummy);
365  return;
366 }
367 
368 
NUM_PROFILES
#define NUM_PROFILES
Definition: app_cfg.h:79
MCB_t::isMMWaveOpen
bool isMMWaveOpen
! flag which indicates if the radar is transmitting or not
Definition: mmWave_XSS.h:243
MSS_CLIBasicCfg
static int32_t MSS_CLIBasicCfg(int32_t argc, char *argv[])
This is the CLI Handler for basic configuration.
Definition: mss_cli.c:147
MSS_CLIAdvancedFrameCfg
static int32_t MSS_CLIAdvancedFrameCfg(int32_t argc, char *argv[])
This is the CLI Handler for advanced frame configuration.
Definition: mss_cli.c:222
MSS_CLIInit
void MSS_CLIInit(void)
This is the CLI Execution Task.
Definition: mss_cli.c:311
MCB_t::commandUartHandle
UART_Handle commandUartHandle
! UART Logging Handle
Definition: mmWave_XSS.h:239
Cfg_AdvFrameCfgInitParams
void Cfg_AdvFrameCfgInitParams(rlAdvFrameCfg_t *ptrAdvFrameCfg)
The function initializes the frame configuration with the default parameters.
Definition: frame_cfg.c:43
Cfg_ProfileCfgInitParams
void Cfg_ProfileCfgInitParams(uint8_t profileNum, rlProfileCfg_t *ptrProfileCfg)
The function initializes the profile configuration with the default parameters.
Definition: frame_cfg.c:168
MCB_t::ctrlHandle
MMWave_Handle ctrlHandle
! Handle to the SOC frame interrupt listener Handle
Definition: mmWave_XSS.h:218
MCB_t::runningStatus
bool runningStatus
! flag which indicates if the mmWave link has been configured
Definition: mmWave_XSS.h:242
Cfg_ADCOutCfgInitParams
void Cfg_ADCOutCfgInitParams(rlAdcOutCfg_t *ptrADCOutCfg)
The function initializes the ADCOut configuration with the default parameters.
Definition: frame_cfg.c:309
NUM_CHIRP_PROG
#define NUM_CHIRP_PROG
Definition: app_cfg.h:78
MSS_CLISensorStart
static int32_t MSS_CLISensorStart(int32_t argc, char *argv[])
This is the CLI Handler for starting the sensor.
Definition: mss_cli.c:60
app_cfg.h
MSS_CLISensorStop
static int32_t MSS_CLISensorStop(int32_t argc, char *argv[])
This is the CLI Handler for stopping the sensor.
Definition: mss_cli.c:111
MCB_t::cfgStatus
bool cfgStatus
!mmWave stats
Definition: mmWave_XSS.h:241
gMCB
MCB gMCB
gMCB structure contains the tracking information required by the design is aligned using DATA_ALIGN p...
Definition: mss_main.c:163
Cfg_ChirpCfgInitParams
void Cfg_ChirpCfgInitParams(uint8_t chirpNum, rlChirpCfg_t *ptrChirpCfg)
The function initializes the chirp configuration with the default parameters.
Definition: frame_cfg.c:205
mmWave_XSS.h
Cfg_ChannelCfgInitParams
void Cfg_ChannelCfgInitParams(rlChanCfg_t *ptrChannelCfg)
The function initializes the channel configuration with the default parameters.
Definition: frame_cfg.c:286
Cfg_LowPowerModeInitParams
void Cfg_LowPowerModeInitParams(rlLowPowerModeCfg_t *ptrLowPowerMode)
The function initializes the low power configuration with the default parameters.
Definition: frame_cfg.c:265
Cfg_FrameCfgInitParams
void Cfg_FrameCfgInitParams(rlFrameCfg_t *ptrFrameCfg)
The function initializes the frame configuration with the default parameters.
Definition: frame_cfg.c:139