TI-radar AWR1843 ARM-Cortex R4F core  1
mss_main.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * @file mss_main.c
3  * @brief The application runs on top of the Master Sub-system (MSS)
4  * which is powered by an ARM Cortex-R4F processor
5  * Main tasks is to running user Application code.
6  * Control RF-Front End core Cortex-R4F Radar subsystem (BSS)
7  * via API messages.Perform radar signal processing.
8  * Finally, It Sends obtained raw-data to the DSP subsystem for
9  * further digital processing to the (DSS) core.
10  * @author A. Astro, a.astro7x@gmail.com
11  * @date Jan 13 2020
12  * @version 0.1
13  *******************************************************************************/
14 
15 
16 /**************************************************************************
17  *************************** Include Files ********************************
18  **************************************************************************/
19 
20 // Standard Include Files
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <stddef.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <math.h>
27 
28 // BIOS/XDC Include Files
29 #include <xdc/std.h>
30 #include <xdc/cfg/global.h>
31 #include <xdc/runtime/IHeap.h>
32 #include <xdc/runtime/System.h>
33 #include <xdc/runtime/Error.h>
34 #include <xdc/runtime/Memory.h>
35 #include <ti/sysbios/BIOS.h>
36 #include <ti/sysbios/knl/Task.h>
37 #include <ti/sysbios/knl/Event.h>
38 #include <ti/sysbios/knl/Semaphore.h>
39 #include <ti/sysbios/knl/Clock.h>
40 #include <ti/sysbios/heaps/HeapBuf.h>
41 #include <ti/sysbios/heaps/HeapMem.h>
42 #include <ti/sysbios/knl/Event.h>
43 #include <ti/sysbios/family/arm/v7a/Pmu.h>
44 #include <ti/sysbios/family/arm/v7r/vim/Hwi.h>
45 
46 // mmWave SDK Include Files
47 #include <ti/control/mmwavelink/mmwavelink.h>
48 #include <ti/control/mmwave/mmwave.h>
49 #include <ti/control/mmwavelink/include/rl_driver.h>
50 #include <ti/common/sys_common.h>
51 
52 
53 // TI Drivers Include Files
54 #include <ti/drivers/soc/soc.h>
55 #include <ti/drivers/esm/esm.h>
56 #include <ti/drivers/crc/crc.h>
57 #include <ti/drivers/uart/UART.h>
58 #include <ti/drivers/gpio/gpio.h>
59 #include <ti/drivers/mailbox/mailbox.h>
60 #include <ti/drivers/pinmux/include/pinmux_xwr18xx.h>
61 #include <ti/drivers/osal/DebugP.h>
62 #include <ti/drivers/canfd/canfd.h>
63 #include <ti/drivers/pinmux/pinmux.h>
64 #include <ti/drivers/cbuff/cbuff.h>
65 
66 // Utilities Include Files
67 #include <ti/utils/testlogger/logger.h>
68 #include <ti/utils/cli/cli.h>
69 
70 // Application Include Files
71 #include "common/mmw_messages.h"
72 #include "common/mmWave_XSS.h"
73 #include <common/app_cfg.h>
74 
75 
76 #define TASK_PRIO_1 1
77 #define TASK_PRIO_2 2
78 #define TASK_PRIO_3 3
79 #define TASK_PRIO_4 4
80 #define TASK_PRIO_5 5
81 #define TASK_PRIO_6 6
82 
83 
84 
85 /* ******************************************************************************
86  ENABLE APPLICATION SPECIFIC INSTRUCTIONS
87  *******************************************************************************/
88 // #define CAN
89 // #define CAN_FD
90 // #define AWR1843_GPIO
91 
92 
93 #if defined (CAN) || defined (CAN_FD)
94 
95 /*
96  * CAN Driver Based Functions -----------------------
97  * @CAN Related
98  * Adopted from SPRACF7 April 2018
99  * Document Name: "Adding CAN-FD Tx and Rx to an Exi-
100  * sting mmWave Project"-----------------------------
101  */
102 static void MCANAppInitParams(CANFD_MCANInitParams* mcanCfgParams);
103 static void MCANAppCallback(CANFD_MsgObjHandle handle, CANFD_Reason reason);
104 static void MCANAppErrStatusCallback(CANFD_Handle handle, CANFD_Reason reason, CANFD_ErrStatusResp* errStatusResp);
105 static void Can_Initialize(void);
106 static uint32_t Get_CanMessageIdentifier(MmwDemo_output_message_type type);
107 static int32_t Can_Transmit_Schedule( uint32_t msg_id, uint8_t *txmsg, uint32_t len);
108 
109 /* User-Defined Function to deploy the CAN module in our application */
110 static void CAN_init(void);
111 
112 /*---------------------------------------------------
113  * Enable CANFD confugiuration from MCAN Module
114  * MCAN := Modular Controller Area Network
115  * Possible Configs: Classical CAN, CAN FD
116  */
117 
118 #ifdef CAN
119 CANFD_MCANFrameType frameType = CANFD_MCANFrameType_CLASSIC;
120 #endif
121 
122 #ifdef CANFD
123 CANFD_MCANFrameType frameType = CANFD_MCANFrameType_FD;
124 #endif
125 
126 /*
127  * Public-scope Variables DEFINITIONS ---------------
128  * @CAN Related
129  * Adopted from SPRACF7 April 2018
130  * Document Name: "Adding CAN-FD Tx and Rx to an Exi-
131  * sting mmWave Project"-----------------------------
132  */
133 volatile uint32_t gTxDoneFlag = 0;
134 volatile uint32_t gRxDoneFlag = 0;
135 volatile uint32_t gTxPkts = 0;
136 volatile uint32_t gRxPkts = 0;
137 volatile uint32_t gErrStatusInt = 0;
138 volatile uint32_t iterationCount = 0U;
139 uint32_t dataLength = 0U;
140 uint8_t rxData[64U];
141 uint32_t txDataLength;
142 uint32_t rxDataLength;
143 
144 CANFD_Handle canHandle;
145 CANFD_MsgObjHandle txMsgObjHandle;
146 CANFD_MCANMsgObjCfgParams txMsgObjectParams;
147 
148 #endif
149 
150 
151 
152 #pragma DATA_ALIGN(gMCB, 16);
153 
164  // MCPI_LOGBUF_INIT(9216);
169 
170 
171  /* ******************************************************************************
172  mmWave SPECIFIC Functions
173  *******************************************************************************/
174 
175 static void MSS_mmWaveInitTASK (UArg arg0, UArg arg1);
176 static void MSS_mmWaveConfigCallbackFxn(MMWave_CtrlCfg* ptrCtrlCfg);
177 static void MSS_chirpIntCallback(uintptr_t arg);
178 static void MSS_mmWaveStartCallbackFxn(MMWave_CalibrationCfg* ptrCalibrationCfg);
179 static void MSS_mmWaveStopCallbackFxn(void);
180 static void MSS_frameStartIntCallback(uintptr_t arg);
181 static void MSS_mmWaveCtrlTask (UArg arg0, UArg arg1);
182 static void MSS_mmWaveOpenCallbackFxn(MMWave_OpenCfg* ptrOpenCfg);
183 static void MSS_mmWaveCloseCallbackFxn(void);
184 static int32_t MSS_eventFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload);
185 
186 /* ******************************************************************************
187  Mailbox SPECIFIC Functions
188  *******************************************************************************/
189 static void mboxCallbackFxn_MSS_ch0(Mbox_Handle handle, Mailbox_Type peer);
190 static void mboxIn_uartOut_TASK(UArg arg0, UArg arg1);
191 int32_t MSS_mboxWrite(mmWaveMSG *msg);
192 
193 
194 /*@**********************************************************************
195  * MSS_chirpIntCallback
196  ************************************************************************/
219 static void MSS_chirpIntCallback(uintptr_t arg) {
220 
221  gMCB.chirpInt++;
222  //gMCB.chirpIntcumSum++;
223 
227  if (gMCB.subframeId == NUM_SUBFRAMES) {
228  gMCB.subframeId = 0;
229  } else {
230  return;
231  }
232  gMCB.chirpInt = 0;
233  } else {
234  return;
235  }
236 }
237 
238 /*@**********************************************************************
239  * MSS_frameStartIntCallback
240  ************************************************************************/
253 static void MSS_frameStartIntCallback(uintptr_t arg) {
254 
256  //gMSSMCB.subframeCntFromFrameStart++;
257  if (gMCB.frameStartToken == 1) {
258  if (gMCB.chirpInt == 0) {
259  gMCB.frameStartToken = 0;
260  }else {
261  DebugP_assert(0);
262  }
263  } else {
264  return;
265  }
266 }
267 
268 /*@**********************************************************************
269  * MSS_eventFxn
270  ************************************************************************/
283 static int32_t MSS_eventFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload) {
284 
285  System_printf ("Debug: BSS Event MsgId: %d [Sub Block Id: %d Sub Block Length: %d]\n",msgId, sbId, sbLen);
286 #if 0
287  uint16_t asyncSB = RL_GET_SBID_FROM_UNIQ_SBID(sbId);
288  // Process the received message
289  switch (msgId) {
290  case RL_RF_ASYNC_EVENT_MSG: {
291  // Received Asychronous Message:
292  switch (asyncSB) {
293  case RL_RF_AE_CPUFAULT_SB: {
294  // Post event to datapath task notify BSS events
295  //Event_post(gMSSMCB.eventHandle, MMWDEMO_BSS_CPUFAULT_EVT);
296  break;
297  }
298  case RL_RF_AE_ESMFAULT_SB: {
299  /* Post event to datapath task notify BSS events */
300  //Event_post(gMSSMCB.eventHandle, MMWDEMO_BSS_ESMFAULT_EVT);
301  break;
302  }
303  case RL_RF_AE_INITCALIBSTATUS_SB: {
304  /* This event should be handled by mmwave internally, ignore the event here */
305  break;
306  }
307  case RL_RF_AE_FRAME_TRIGGER_RDY_SB: {
308  break;
309  }
310  case RL_RF_AE_MON_TIMING_FAIL_REPORT_SB: {
311  break;
312  }
313  case RL_RF_AE_RUN_TIME_CALIB_REPORT_SB: {
314  break;
315  }
316  default: {
317  System_printf ("[MSS] \t [ERROR] Asynchronous Event SB Id %d not handled\n", asyncSB);
318  break;
319  }
320  }
321  break;
322  }
323  default: {
324  System_printf ("[MSS] \t [ERROR] Asynchronous message %d is NOT handled\n", msgId);
325  break;
326  }
327  }
328 #endif
329  return 0;
330 }
331 
332 /*@**********************************************************************
333  * MSS_mmWaveConfigCallbackFxn
334  ************************************************************************/
344 //***********************************************************************/
345 
346 static void MSS_mmWaveConfigCallbackFxn(MMWave_CtrlCfg* ptrCtrlCfg) {
347 
348  DebugP_assert(0);
349 }
350 
351 /*@**********************************************************************
352  * MSS_mmWaveStartCallbackFxn
353  ************************************************************************/
362 static void MSS_mmWaveStartCallbackFxn(MMWave_CalibrationCfg* ptrCalibrationCfg) {
363 
364  /* Post an event to main data path task.
365  This function in only called when mmwave_start() is called on DSS */
367 
368  /* Post event to Notify that event start is done */
370 }
371 
372 /*@**********************************************************************
373  * MSS_mmWaveStopCallbackFxn
374  ************************************************************************/
385 static void MSS_mmWaveStopCallbackFxn(void) {
386 
388 }
389 
390 /*@**********************************************************************
391  * MSS_mmWaveOpenCallbackFxn
392  ************************************************************************/
400 static void MSS_mmWaveOpenCallbackFxn(MMWave_OpenCfg* ptrOpenCfg) {
401 
402  return;
403 }
404 
405 /*@**********************************************************************
406  * MSS_mmWaveCloseCallbackFxn
407  ************************************************************************/
416 static void MSS_mmWaveCloseCallbackFxn(void){
417 
418  return;
419 }
420 
421 /*@**********************************************************************
422  * MmwDemo_mboxWrite
423  ************************************************************************/
432 int32_t MSS_mboxWrite(mmWaveMSG *msg) {
433 
434  int32_t retVal = -1;
435 
436  retVal = Mailbox_write (gMCB.mboxHandle, (uint8_t*)msg, sizeof(mmWaveMSG));
437  if (retVal == sizeof(mmWaveMSG)) {
438  retVal = 0;
439  }
440  return retVal;
441 }
442 
443 /*@**********************************************************************
444  * mboxIn_uartOut_TASK
445  ************************************************************************/
457 static void mboxIn_uartOut_TASK(UArg arg0, UArg arg1)
458 {
459  mmWaveMSG msg;
460  int32_t retVal = 0;
461 
462  /* wait for new message and process all the messages received from the peer */
463  while(1) {
464 
465  Semaphore_pend(gMCB.mboxSemHandle, BIOS_WAIT_FOREVER);
466 
467  /* Read the message from the peer mailbox: We are not trying to protect the read
468  * from the peer mailbox because this is only being invoked from a single thread */
469  retVal = Mailbox_read(gMCB.mboxHandle, (uint8_t*)&msg, sizeof(mmWaveMSG));
470  if (retVal < 0) {
471  /* Error: Unable to read the message. Setup the error code and return values */
472  System_printf ("[MSS] \t [Error][MAILBOX]: Mailbox read failed [Error code %d]\n", retVal);
473  }
474  else if(retVal == 0) {
475  /* We are done: There are no messages available from the peer execution domain. */
476  continue;
477  }
478  else {
479  /* Flush out the contents of the mailbox to indicate that we are done with the message. This will
480  * allow us to receive another message in the mailbox while we process the received message. */
481  Mailbox_readFlush(gMCB.mboxHandle);
482 
483  /* Process the received message: */
484  switch(msg.type) {
486  /* Got detected objects , to be shipped out through UART */
487  {
488  uint32_t totalPacketLen;
489  uint32_t numPaddingBytes;
490  uint32_t itemIdx;
491  uint32_t AddressSOC;
492 
493  /* Send header */
494  totalPacketLen = sizeof(mmWave_OUT_MSG_header);
495  UART_writePolling (gMCB.loggingUartHandle,
496  (uint8_t*)&msg.body.detObj.header,
497  sizeof(mmWave_OUT_MSG_header));
498 #if defined (CAN) || defined (CAN_FD)
499  txMsgObjectParams.msgIdentifier = Get_CanMessageIdentifier((MmwDemo_output_message_type)MMWDEMO_HEADER);
500  Can_Transmit_Schedule( txMsgObjectParams.msgIdentifier, (uint8_t*)&message.body.detObj.header,sizeof(mmWave_OUT_MSG_header));
501 #endif
502 
503  /* Send TLVs */
504  for (itemIdx = 0; itemIdx < msg.body.detObj.header.numTLVs; itemIdx++){
505 
506  UART_writePolling (gMCB.loggingUartHandle,
507  (uint8_t*)&msg.body.detObj.tlv[itemIdx],
508  sizeof(mmWave_OUT_MSG_tl));
509 
510  /* Address has to be translated from the DSS core
511  * SOC_translateAddress
512  * SOC_translateAddress(<some pointer>, SOC_TranslateAddr_Dir_FROM_OTHER_CPU, NULL)
513  * must be used on any pointers that came from the DSP
514  * in order to access the corresponding data.
515  * This is easy to overlook, but you will get garbage results or cause other problems
516  * if you don't translate the pointer before accessing its contents.
517  */
518  AddressSOC = SOC_translateAddress(msg.body.detObj.tlv[itemIdx].address, SOC_TranslateAddr_Dir_FROM_OTHER_CPU, NULL);
519  UART_writePolling (gMCB.loggingUartHandle,
520  (uint8_t*)AddressSOC,
521  msg.body.detObj.tlv[itemIdx].length);
522 
523 #if defined (CAN) || defined (CAN_FD)
524  txMsgObjectParams.msgIdentifier = Get_CanMessageIdentifier((MmwDemo_output_message_type)msg.body.detObj.tlv[itemIdx].type);
525  Can_Transmit_Schedule(txMsgObjectParams.msgIdentifier, (uint8_t*)&msg.body.detObj.tlv[itemIdx],sizeof(mmWave_OUT_MSG_tl));
526  Can_Transmit_Schedule( txMsgObjectParams.msgIdentifier, (uint8_t*)SOC_translateAddress(msg.body.detObj.tlv[itemIdx].address,SOC_TranslateAddr_Dir_FROM_OTHER_CPU,NULL), msg.body.detObj.tlv[itemIdx].length);
527 #endif
528  /* The totalPacketLen element of the detection results header
529  * must be a multiple of 32 bytes.
530  * The DSP rounds up to the nearest multiple,
531  * but when modifying it in the MSS you must redo this step after making any additions.
532  * You may notice data missing in your serial frames if you don't round to the proper length.*/
533  totalPacketLen += sizeof(mmWave_OUT_MSG_tl) + msg.body.detObj.tlv[itemIdx].length;
534  }
535 
536  /* Send padding to make total packet length multiple of MMWDEMO_OUTPUT_MSG_SEGMENT_LEN */
537  numPaddingBytes = MMW_OUTPUT_MSG_SEGMENT_LEN - (totalPacketLen & (MMW_OUTPUT_MSG_SEGMENT_LEN-1));
538  if (numPaddingBytes<MMW_OUTPUT_MSG_SEGMENT_LEN) {
539 
540  uint8_t padding[MMW_OUTPUT_MSG_SEGMENT_LEN];
541  memset(&padding, 0xf, MMW_OUTPUT_MSG_SEGMENT_LEN);
542  UART_writePolling (gMCB.loggingUartHandle, padding, numPaddingBytes);
543 
544 #if defined (CAN) || defined (CAN_FD)
545  txMsgObjectParams.msgIdentifier = Get_CanMessageIdentifier((MmwDemo_output_message_type)MMWDEMO_PADDING);
546  Can_Transmit_Schedule( txMsgObjectParams.msgIdentifier, padding,numPaddingBytes);
547 #endif
548  }
549  }
550 
551  /* Send a message to MSS to log the output data */
552  memset((void *)&msg, 0, sizeof(mmWaveMSG));
553  msg.type = MBOX_MSS2DSS_DETOBJ_SHIPPED;
554 
555  retVal = MSS_mboxWrite(&msg);
556 
557  if (retVal != 0) {
558  System_printf ("[MSS] \t [ERROR][MAILBOX] Mailbox send message id=%d failed \n", msg.type);
559  }
560 
561  break;
562 
564  {
565  /* Send the received DSS assert info through CLI */
566  CLI_write("[MSS] \t [DSS][EXCEP] DSS Exception: %s, line %d.\n", msg.body.assertInfo.file, msg.body.assertInfo.line);
567  break;
568  }
569  default:
570  {
571  /* Message not support */
572  System_printf ("[MSS] \t [ERROR][MAILBOX] unsupport Mailbox message id=%d\n", msg.type);
573  break;
574  }
575  }
576  }
577  }
578 }
579 
580 /*@**********************************************************************
581  * mboxCallbackFxn_MSS_ch0
582  ************************************************************************/
596 static void mboxCallbackFxn_MSS_ch0(Mbox_Handle handle, Mailbox_Type peer)
597 {
598  Semaphore_post(gMCB.mboxSemHandle);
599 }
600 
601 /*@**********************************************************************
602  * MSS_mmWaveCtrlTask
603  ************************************************************************/
614 static void MSS_mmWaveCtrlTask (UArg arg0, UArg arg1) {
615  int32_t errCode;
616 
617  while (1) {
618  /* Execute the mmWave control module: */
619  if (MMWave_execute (gMCB.ctrlHandle, &errCode) < 0) {
620 
621  System_printf ("Error: mmWave control execution failed [Error code %d]\n", errCode);
622  }
623  }
624 }
625 
626 
627 /*@**********************************************************************
628  * MSS_mmWaveInitTASK
629  ************************************************************************/
643 static void MSS_mmWaveInitTASK (UArg arg0, UArg arg1) {
644 
645  Task_Params taskParams;
646  UART_Params uartParams;
647  Semaphore_Params semParams;
648  Mailbox_Config mboxCfg;
649  SOC_SysIntListenerCfg listenerCfg;
650  MMWave_InitCfg initCfg;
651  int32_t errCode;
652 
653  /* ************************************************
654  * Initialize and Configure the Device Drivers
655  * UART, CAN, Mailbox, and GPIOs
656  * ************************************************/
657  System_printf("[MSS] \t Launched the Initialization Task\n");
658  //\ref PINMUXTOOL-V4-CLOUD
662 
663  Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINN5_PADBE, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
664  Pinmux_Set_FuncSel(SOC_XWR18XX_PINN5_PADBE, SOC_XWR18XX_PINN5_PADBE_MSS_UARTA_TX);
665 
666  Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINN4_PADBD, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
667  Pinmux_Set_FuncSel(SOC_XWR18XX_PINN4_PADBD, SOC_XWR18XX_PINN4_PADBD_MSS_UARTA_RX);
668 
669  Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINF14_PADAJ, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
670  Pinmux_Set_FuncSel(SOC_XWR18XX_PINF14_PADAJ, SOC_XWR18XX_PINF14_PADAJ_MSS_UARTB_TX);
671 
672  Pinmux_Set_OverrideCtrl(SOC_XWR18XX_PINP8_PADBM, PINMUX_OUTEN_RETAIN_HW_CTRL, PINMUX_INPEN_RETAIN_HW_CTRL);
673  Pinmux_Set_FuncSel(SOC_XWR18XX_PINP8_PADBM, SOC_XWR18XX_PINP8_PADBM_DSS_UART_TX);
674 
676  UART_init();
677  System_printf("[MSS] \t UART initialized .. \n");
678 
682  #if defined (CAN) || defined (CAN_FD)
683  CAN_init();
684  System_printf("[MSS] \t CAN initialized .. \n");
685  #endif
686 
687 #ifdef AWR1843_GPIO
688 
689  GPIO_init();
690  System_printf("[MSS] \t GPIO initialized .. \n");
691 #endif
692 
694  Mailbox_init(MAILBOX_TYPE_MSS);
695  if(Mailbox_Config_init(&mboxCfg) < 0) {
696  System_printf("[MSS] \t [Error][MAILBOX] Unable to initialize configuration\n");
697  }else {
698  System_printf("[MSS] \t [Mailbox] Mailbox initialized .. \n");
699  }
700 
701  /* ************************************************
702  * Open and Configure the Device Drivers
703  * UART, CAN, Mailbox, and GPIOs
704  * ************************************************/
705 
706  /* Init Params, Open and Setup the UART Driver: Command Instance */
707  UART_Params_init(&uartParams);
708  uartParams.baudRate = 115200;
709  uartParams.isPinMuxDone = 1;
710  uartParams.clockFrequency = MSS_SYS_VCLK;
711  //MSS_SYS_VCLK := 200MHz
712 
713  gMCB.commandUartHandle = UART_open(0, &uartParams);
714  if (gMCB.commandUartHandle == NULL) {
715  System_printf("[MSS] \t [Error][UART] Unable to open the Command UART Instance\n");
716  } else {
717  System_printf("[MSS] \t [UART][CFG_PORT] open the Command UART Instance \n");
718  System_printf("[MSS] \t [UART][CFG_PORT] clockFrequency=%fMHz \n", uartParams.clockFrequency/1e6);
719  System_printf("[MSS] \t [UART][CFG_PORT] baudRate=%d \n",uartParams.baudRate);
720  }
721 
722 
723  /* Init Params, Open and Setup the UART Driver: Logging Instance */
724  UART_Params_init(&uartParams);
725  uartParams.writeDataMode = UART_DATA_BINARY;
726  uartParams.readDataMode = UART_DATA_BINARY;
727  uartParams.baudRate = 115200*8;
728  uartParams.isPinMuxDone = 1U;
729  uartParams.clockFrequency = MSS_SYS_VCLK;
730  //MSS_SYS_VCLK : 200MHz
731  gMCB.loggingUartHandle = UART_open(1, &uartParams);
732  if (gMCB.loggingUartHandle == NULL) {
733  System_printf("[MSS] \t [Error] Unable to open the logging UART Instance\n");
734  } else {
735  System_printf("[MSS] \t [UART][DATA_PORT] open the logging UART Instance \n");
736  System_printf("[MSS] \t [UART][DATA_PORT] clockFrequency=%fMHz \n", uartParams.clockFrequency/1e6);
737  System_printf("[MSS] \t [UART][DATA_PORT] baudRate=%d \n",uartParams.baudRate);
738  }
739 
740 
741  /* ************************************************
742  * Creating communication channel between MSS & DSS
743  * ************************************************/
744 
745  // Create a binary semaphore to handle mailbox interrupt
746  Semaphore_Params_init(&semParams);
747  semParams.mode = Semaphore_Mode_BINARY;
748  gMCB.mboxSemHandle = Semaphore_create(0, &semParams, NULL);
749 
750  // Setup the default mailbox configuration
751  Mailbox_Config_init(&mboxCfg);
752  // Setup the configuration:
753  mboxCfg.chType = MAILBOX_CHTYPE_MULTI;
754  mboxCfg.chId = MAILBOX_CH_ID_0;
755  mboxCfg.writeMode = MAILBOX_MODE_BLOCKING;
756  mboxCfg.readMode = MAILBOX_MODE_CALLBACK;
757  mboxCfg.readCallback = &mboxCallbackFxn_MSS_ch0;
758 
759  /*
760  * typedef void(* Mailbox_Callback) (Mbox_Handle handle, Mailbox_Type remoteEndpoint)
761  * void mboxCallbackFxn_MSS_ch0(Mbox_Handle handle, Mailbox_Type peer) {
762  * sem_post();
763  * }
764  * mboxCfg.readCallback = &mboxCallbackFxn_MSS_ch0;
765  *
766  * This creates a type, named Mailbox_Callback which is a pointer to a function that
767  * takes a 2 inputs handle: Which is returned by Mailbox_open
768  * and Mailbox_Type which is could be MAILBOX_TYPE_MSS or MAILBOX_TYPE_DSS
769  * and returns nothing, which matches the signature of the function
770  * mboxCallbackFxn_MSS_ch0.
771  * To use it; we assign the function reference to the pointer readCallback
772  */
773 
774  // Initialization of Mailbox Virtual Channel
775  gMCB.mboxHandle = Mailbox_open(MAILBOX_TYPE_DSS, &mboxCfg, &errCode);
776  if (gMCB.mboxHandle == NULL) {
777  System_printf("[MSS] \t [Error][MAILBOX] Unable to open the Mailbox to the DSS [Error code %d]\n", errCode);
778  } else {
779  System_printf("[MSS] \t [MAILBOX] Opening Mailbox Channel to the DSP Subsystem [DSS] .. \n");
780  }
781 
782  // Create task to handle mailbox messages
783  Task_Params_init(&taskParams);
784  taskParams.stackSize = 16*1024;
785  Task_create(mboxIn_uartOut_TASK, &taskParams, NULL);
786 
787  // Register Chirp Available Listener, populate configurations
788  // The hardware event SOC_XWR18XX_MSS_CHIRP_AVAIL_IRQ is the only way to know when the samples are available in the ADC buffer.
789  // https://e2e.ti.com/support/sensors/f/1023/t/837299?IWR1443-ADC-data-to-L3
790  memset ((void*)&listenerCfg, 0, sizeof(SOC_SysIntListenerCfg));
791  listenerCfg.systemInterrupt = SOC_XWR18XX_MSS_CHIRP_AVAIL_IRQ; // Chirp Available Interrupt
792  listenerCfg.listenerFxn = MSS_chirpIntCallback; //TestFmk_chirpISR
793  listenerCfg.arg = 0;
794 
795  gMCB.chirpIntHandle = SOC_registerSysIntListener (gMCB.socHandle, &listenerCfg, &errCode);
796  if (gMCB.chirpIntHandle == NULL) {
797  System_printf ("[MSS] \t [Error] Unable to register the Chirp Available Listener/Interrupt [Error code %d]\n", errCode);
798  return;
799  }
800 
801  // Register Frame Start Listener, populate configurations
802  memset ((void*)&listenerCfg, 0, sizeof(SOC_SysIntListenerCfg));
803  listenerCfg.systemInterrupt = SOC_XWR18XX_MSS_FRAME_START_INT; //Frame Start Interrupt
804  listenerCfg.listenerFxn = MSS_frameStartIntCallback;
805  listenerCfg.arg = 0;
806 
807  gMCB.frameStartIntHandle = SOC_registerSysIntListener (gMCB.socHandle, &listenerCfg, &errCode);
808 
809  if (gMCB.frameStartIntHandle == NULL) {
810  System_printf("[MSS] \t [Error] Unable to register the Frame start Listener/Interrupt [Error code %d]\n", errCode);
811  return ;
812  }
813 
814  /* Initialize the mmWave module:*/
815  memset ((void *)&initCfg, 0, sizeof(MMWave_InitCfg));
816 
817  /* Populate the initialization configuration:
818  * The MMWAve is configured in minimal isolation mode. */
819  initCfg.domain = MMWave_Domain_MSS;
820  initCfg.socHandle = gMCB.socHandle;
821  initCfg.eventFxn = &MSS_eventFxn;
822  initCfg.cfgMode = MMWave_ConfigurationMode_MINIMAL;
823  initCfg.executionMode = MMWave_ExecutionMode_ISOLATION;
824  initCfg.linkCRCCfg.useCRCDriver = 1U;
825  initCfg.linkCRCCfg.crcChannel = CRC_Channel_CH1;
826  initCfg.cooperativeModeCfg.cfgFxn = &MSS_mmWaveConfigCallbackFxn;
827  initCfg.cooperativeModeCfg.startFxn = &MSS_mmWaveStartCallbackFxn;
828  initCfg.cooperativeModeCfg.stopFxn = &MSS_mmWaveStopCallbackFxn;
829  initCfg.cooperativeModeCfg.openFxn = &MSS_mmWaveOpenCallbackFxn;
830  initCfg.cooperativeModeCfg.closeFxn = &MSS_mmWaveCloseCallbackFxn;
831 
832  // Initialize and setup the mmWave Control module
833  gMCB.ctrlHandle = MMWave_init(&initCfg, &errCode);
834  if (gMCB.ctrlHandle == NULL) {
835  // Error: Unable to initialize the mmWave control module
836  System_printf ("[MSS] \t [Error][Init][mmWAVE] mmWave Control Initialization failed [Error code %d]\n", errCode);
837  return;
838  } else {
839  System_printf ("[MSS] \t [Debug][Init][mmWAVE] Initialized the mmWave module\n");
840  }
841 
842  // Synchronize the mmWave module:
843  while (1) {
844  int32_t syncStatus;
845 
846  // Get the synchronization status:
847  syncStatus = MMWave_sync(gMCB.ctrlHandle, &errCode);
848  if (syncStatus < 0) {
849  // Error: Unable to synchronize the mmWave control module
850  System_printf ("Error: mmWave Control Synchronization failed [Error code %d]\n", errCode);
851  return;
852  }
853  if (syncStatus == 1) {
854  // Synchronization acheived:
855  System_printf ("[MSS] \t [SYNCH][mmWAVE]: mmWave Control Synchronization Achieved\n");
856  // MCPI_setFeatureTestResult("MMWave MSS Synchronization", MCPI_TestResult_PASS);
857  break;
858  }
859  // Sleep and poll again:
860  Task_sleep(1);
861  }
862 
863  System_printf ("[MSS] \t [DEBUG][SYNCH] Synchronized the mmWave module\n");
864 
865  // This one is defined @common/mrr_config_consts.h
866  #ifdef SUBFRAME_CONF_MRR_USRR
869  #else
870  #ifdef SUBFRAME_CONF_MRR
872  #endif
873  #ifdef SUBFRAME_CONF_USRR
875  #endif
876  #endif
877 
878 
879  /*
880  * Launch the mmWave control execution task
881  * This should have a higher priroity than any other task which uses the
882  * mmWave control API
883  */
884  Task_Params_init(&taskParams);
885  taskParams.priority = TASK_PRIO_6;
886  taskParams.stackSize = 3*1024;
887  Task_create(MSS_mmWaveCtrlTask, &taskParams, NULL);
888 
889  // Setup the CLI
890  MSS_CLIInit();
891 }
892 
893 
894 //********************************************************
895 //* ********************MAIN******************************
896 //********************************************************
914  //**********************************************************
915 
916 int32_t main(void) {
917 
918  Task_Params taskParams; //< define Task_Params instance config structure
919  int32_t errCode; //< define an integer to retrieve error messeges
920  SOC_Cfg socCfg; //< define SOC_Cfg structure to to open & initialize the SOC Driver.
921 
922  /* Initialize Error Signaling Module MSS_ESM for hardware diagnostics within the MSS core */
923  ESM_init(0U);
924  //MCPI_Initialize();
925  /* Initialize the global structure Master Control Block MCB */
926  memset((void*)&gMCB, 0, sizeof(MCB));
927 
928  /* Initialize the SOC configuration: */
929  memset((void *)&socCfg, 0, sizeof(SOC_Cfg));
930 
931  /* Populate the SOC configuration: Set the clock source on 200MHz */
932  socCfg.clockCfg = SOC_SysClock_INIT;
933 
934  /* Initialize the SOC Module to ensure that the Memory Protection Unit
935  * (MPU) settings are correctly configured.
936  */
937 
938  gMCB.socHandle = SOC_init (&socCfg, &errCode);
939  if (gMCB.socHandle == NULL) {
940  System_printf ("[MSS] \t [Error][SOC] SOC Module Initialization failed [Error code %d]\n", errCode);
941  return -1;
942  }
943 
944  /* Check if the SOC is a secure device */
945  if (SOC_isSecureDevice(gMCB.socHandle, &errCode)) {
946  /* Disable firewall for JTAG and LOGGER (UART) */
947  SOC_controlSecureFirewall(gMCB.socHandle,
948  (uint32_t)(SOC_SECURE_FIREWALL_JTAG | SOC_SECURE_FIREWALL_LOGGER),
949  SOC_SECURE_FIREWALL_DISABLE, &errCode);
950  }
951 
952  System_printf ("**********************************************************\n");
953  System_printf ("[MSS] \t [DEBUG] Launching the Millimeter Wave Application\n");
954  System_printf ("**********************************************************\n");
955 
956  /* Initialize the Task Parameters. */
957  Task_Params_init(&taskParams);
958  taskParams.priority = TASK_PRIO_1; // Default 3
959  Task_create(MSS_mmWaveInitTASK, &taskParams, NULL);
960 
961  /* Start BIOS */
962  BIOS_start();
963  return 0;
964 }
965 
MSS_CLIInit
void MSS_CLIInit(void)
This is the CLI Execution Task.
Definition: mss_cli.c:311
MBOX_MSS2DSS_DETOBJ_SHIPPED
Definition: mmw_messages.h:130
MSS_mmWaveOpenCallbackFxn
static void MSS_mmWaveOpenCallbackFxn(MMWave_OpenCfg *ptrOpenCfg)
This is the application registered callback function which is invoked after the MSS has been opened.
Definition: mss_main.c:400
MCB_t::chirpInt
int32_t chirpInt
! The total number of chirp available interrupts.
Definition: mmWave_XSS.h:248
mboxCallbackFxn_MSS_ch0
static void mboxCallbackFxn_MSS_ch0(Mbox_Handle handle, Mailbox_Type peer)
mboxCallbackFxn_MSS_ch0 is a callback function. Function is invoked for each received messege from th...
Definition: mss_main.c:596
mboxIn_uartOut_TASK
static void mboxIn_uartOut_TASK(UArg arg0, UArg arg1)
The Task is used to handle the recieved messages from the DSS Peer over the mailbox virtual communica...
Definition: mss_main.c:457
MMW_OUTPUT_MSG_SEGMENT_LEN
#define MMW_OUTPUT_MSG_SEGMENT_LEN
Output packet length is a multiple of this value, must be power of 2.
Definition: mmw_messages.h:17
MCB_t::commandUartHandle
UART_Handle commandUartHandle
! UART Logging Handle
Definition: mmWave_XSS.h:239
MSS_mmWaveConfigCallbackFxn
static void MSS_mmWaveConfigCallbackFxn(MMWave_CtrlCfg *ptrCtrlCfg)
This is the application registered callback function which is invoked after the configuration has bee...
Definition: mss_main.c:346
DSS_START_COMPLETED_EVT
#define DSS_START_COMPLETED_EVT
sensor start CLI event SYS/BIOS events are a means of communication between Tasks and threads SYS/BIO...
Definition: mmWave_XSS.h:80
MCB_t::numChirpsPerSubframe
int32_t numChirpsPerSubframe[NUM_SUBFRAMES]
! A counter for chirp interrupts. It is reset every subframe.
Definition: mmWave_XSS.h:249
MSS_chirpIntCallback
static void MSS_chirpIntCallback(uintptr_t arg)
This is the callback function registered with the ADC Driver which is invoked when a chirp is availab...
Definition: mss_main.c:219
MSS_mboxWrite
int32_t MSS_mboxWrite(mmWaveMSG *msg)
Definition: mss_main.c:432
MSS_mmWaveCtrlTask
static void MSS_mmWaveCtrlTask(UArg arg0, UArg arg1)
This is the task which provides an execution context for the mmWave control module.
Definition: mss_main.c:614
mmw_messages.h
MCB_t::mboxHandle
Mbox_Handle mboxHandle
! Handle to the SOC Module
Definition: mmWave_XSS.h:214
mmW_MSS_STATS_t::datapathStopEvt
uint8_t datapathStopEvt
! Counter which tracks the number of datapath start event detected
Definition: mmWave_XSS.h:195
MCB_t::subframeId
int32_t subframeId
! The number of chirps per subframe.
Definition: mmWave_XSS.h:250
SUBFRAME_USRR_NUM_CHIRPS_TOTAL
#define SUBFRAME_USRR_NUM_CHIRPS_TOTAL
Definition: config_chirp_design_USRR20.h:102
MCB_t::frameStartIntHandle
SOC_SysIntListenerHandle frameStartIntHandle
! Handle to the SOC chirp interrupt listener Handle
Definition: mmWave_XSS.h:217
MCB_t::ctrlHandle
MMWave_Handle ctrlHandle
! Handle to the SOC frame interrupt listener Handle
Definition: mmWave_XSS.h:218
MCB_t::subframeCntFromChirpInt
int32_t subframeCntFromChirpInt
! token for frame start events.
Definition: mmWave_XSS.h:245
MCB_t::stats
mmW_MSS_STATS stats
! UART Command Handle used to interface with the CLI
Definition: mmWave_XSS.h:240
MSS_mmWaveStartCallbackFxn
static void MSS_mmWaveStartCallbackFxn(MMWave_CalibrationCfg *ptrCalibrationCfg)
Application registered callback function which is invoked on the peer domain just before the mmWave l...
Definition: mss_main.c:362
MSS_eventFxn
static int32_t MSS_eventFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload)
This is a registered event function which is invoked when an event is recieved from the BSS....
Definition: mss_main.c:283
MCB_t::loggingUartHandle
UART_Handle loggingUartHandle
! MSS system event handle
Definition: mmWave_XSS.h:238
app_cfg.h
MBOX_DSS2MSS_DETOBJ_READY
Definition: mmw_messages.h:140
MSS_frameStartIntCallback
static void MSS_frameStartIntCallback(uintptr_t arg)
This is the callback function registered with the ADC Driver which is invoked when a frame is started...
Definition: mss_main.c:253
main
int32_t main(void)
Main Program entrypoint. This is the entrypoint for the MSS firmware which describe the startup seque...
Definition: mss_main.c:916
MCB_t::chirpIntHandle
SOC_SysIntListenerHandle chirpIntHandle
! Semaphore handle for the mailbox communication
Definition: mmWave_XSS.h:216
MCB_t::socHandle
SOC_Handle socHandle
Definition: mmWave_XSS.h:213
mmW_MSS_STATS_t::datapathStartEvt
uint8_t datapathStartEvt
! Counter which tracks the number of datapath config
Definition: mmWave_XSS.h:194
MSS_mmWaveStopCallbackFxn
static void MSS_mmWaveStopCallbackFxn(void)
This is the application registered callback function which is invoked after the MSS has been stopped....
Definition: mss_main.c:385
mmWave_OUT_MSG_tl_t
The structure defines the message body for reporting detected objects from data path....
Definition: mmw_messages.h:83
TASK_PRIO_6
#define TASK_PRIO_6
Definition: mss_main.c:81
MCB_t
DSP-Subsystem (DSS) Master control block (MCB) The structure is used to hold handling information,...
Definition: mmWave_XSS.h:210
mmWave_OUT_MSG_header_t
The structure defines the message header for reporting detection information from data path....
Definition: mmw_messages.h:46
gMCB
MCB gMCB
gMCB structure contains the tracking information required by the design is aligned using DATA_ALIGN p...
Definition: mss_main.c:163
MCB_t::eventHandle
Event_Handle eventHandle
mmWave control handle use to initialize the link infrastructure, which allows communication between t...
Definition: mmWave_XSS.h:237
mmWave_XSS.h
mmWaveMSG_t
The structure defines the message structure used for communication between MSS and DSS.
Definition: mmw_messages.h:227
MBOX_DSS2MSS_ASSERT_INFO
Definition: mmw_messages.h:142
MCB_t::frameStartToken
int32_t frameStartToken
! flag which indicates if the basic radar configuration is completed.
Definition: mmWave_XSS.h:244
MCB_t::mboxSemHandle
Semaphore_Handle mboxSemHandle
! Handle to the peer Mailbox used to exchange messages between the MSS and DSS
Definition: mmWave_XSS.h:215
SUBFRAME_MRR_NUM_CHIRPS_TOTAL
#define SUBFRAME_MRR_NUM_CHIRPS_TOTAL
Definition: config_chirp_design_MRR120.h:102
mmWave_OUT_MSG_header
struct mmWave_OUT_MSG_header_t mmWave_OUT_MSG_header
The structure defines the message header for reporting detection information from data path....
MSS_mmWaveInitTASK
static void MSS_mmWaveInitTASK(UArg arg0, UArg arg1)
Initialize the MCPI Log Message Buffer.
Definition: mss_main.c:643
NUM_SUBFRAMES
#define NUM_SUBFRAMES
Definition: app_cfg.h:80
MSS_mmWaveCloseCallbackFxn
static void MSS_mmWaveCloseCallbackFxn(void)
This is the application registered callback function which is invoked after the MSS has been closed.
Definition: mss_main.c:416
mmWave_OUT_MSG_tl
struct mmWave_OUT_MSG_tl_t mmWave_OUT_MSG_tl
The structure defines the message body for reporting detected objects from data path....
TASK_PRIO_1
#define TASK_PRIO_1
Definition: mss_main.c:76