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>
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>
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>
67 #include <ti/utils/testlogger/logger.h>
68 #include <ti/utils/cli/cli.h>
93 #if defined (CAN) || defined (CAN_FD)
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);
110 static void CAN_init(
void);
119 CANFD_MCANFrameType frameType = CANFD_MCANFrameType_CLASSIC;
123 CANFD_MCANFrameType frameType = CANFD_MCANFrameType_FD;
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;
141 uint32_t txDataLength;
142 uint32_t rxDataLength;
144 CANFD_Handle canHandle;
145 CANFD_MsgObjHandle txMsgObjHandle;
146 CANFD_MCANMsgObjCfgParams txMsgObjectParams;
152 #pragma DATA_ALIGN(gMCB, 16);
184 static int32_t
MSS_eventFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload);
283 static int32_t
MSS_eventFxn(uint16_t msgId, uint16_t sbId, uint16_t sbLen, uint8_t *payload) {
285 System_printf (
"Debug: BSS Event MsgId: %d [Sub Block Id: %d Sub Block Length: %d]\n",msgId, sbId, sbLen);
287 uint16_t asyncSB = RL_GET_SBID_FROM_UNIQ_SBID(sbId);
290 case RL_RF_ASYNC_EVENT_MSG: {
293 case RL_RF_AE_CPUFAULT_SB: {
298 case RL_RF_AE_ESMFAULT_SB: {
303 case RL_RF_AE_INITCALIBSTATUS_SB: {
307 case RL_RF_AE_FRAME_TRIGGER_RDY_SB: {
310 case RL_RF_AE_MON_TIMING_FAIL_REPORT_SB: {
313 case RL_RF_AE_RUN_TIME_CALIB_REPORT_SB: {
317 System_printf (
"[MSS] \t [ERROR] Asynchronous Event SB Id %d not handled\n", asyncSB);
324 System_printf (
"[MSS] \t [ERROR] Asynchronous message %d is NOT handled\n", msgId);
472 System_printf (
"[MSS] \t [Error][MAILBOX]: Mailbox read failed [Error code %d]\n", retVal);
474 else if(retVal == 0) {
488 uint32_t totalPacketLen;
489 uint32_t numPaddingBytes;
496 (uint8_t*)&msg.body.detObj.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));
504 for (itemIdx = 0; itemIdx < msg.body.detObj.header.numTLVs; itemIdx++){
507 (uint8_t*)&msg.body.detObj.tlv[itemIdx],
518 AddressSOC = SOC_translateAddress(msg.body.detObj.tlv[itemIdx].address, SOC_TranslateAddr_Dir_FROM_OTHER_CPU, NULL);
520 (uint8_t*)AddressSOC,
521 msg.body.detObj.tlv[itemIdx].length);
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);
533 totalPacketLen +=
sizeof(
mmWave_OUT_MSG_tl) + msg.body.detObj.tlv[itemIdx].length;
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);
552 memset((
void *)&msg, 0,
sizeof(
mmWaveMSG));
558 System_printf (
"[MSS] \t [ERROR][MAILBOX] Mailbox send message id=%d failed \n", msg.type);
566 CLI_write(
"[MSS] \t [DSS][EXCEP] DSS Exception: %s, line %d.\n", msg.body.assertInfo.file, msg.body.assertInfo.line);
572 System_printf (
"[MSS] \t [ERROR][MAILBOX] unsupport Mailbox message id=%d\n", msg.type);
621 System_printf (
"Error: mmWave control execution failed [Error code %d]\n", errCode);
645 Task_Params taskParams;
646 UART_Params uartParams;
647 Semaphore_Params semParams;
648 Mailbox_Config mboxCfg;
649 SOC_SysIntListenerCfg listenerCfg;
650 MMWave_InitCfg initCfg;
657 System_printf(
"[MSS] \t Launched the Initialization Task\n");
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);
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);
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);
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);
677 System_printf(
"[MSS] \t UART initialized .. \n");
682 #if defined (CAN) || defined (CAN_FD)
684 System_printf(
"[MSS] \t CAN initialized .. \n");
690 System_printf(
"[MSS] \t GPIO initialized .. \n");
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");
698 System_printf(
"[MSS] \t [Mailbox] Mailbox initialized .. \n");
707 UART_Params_init(&uartParams);
708 uartParams.baudRate = 115200;
709 uartParams.isPinMuxDone = 1;
710 uartParams.clockFrequency = MSS_SYS_VCLK;
715 System_printf(
"[MSS] \t [Error][UART] Unable to open the Command UART Instance\n");
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);
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;
733 System_printf(
"[MSS] \t [Error] Unable to open the logging UART Instance\n");
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);
746 Semaphore_Params_init(&semParams);
747 semParams.mode = Semaphore_Mode_BINARY;
751 Mailbox_Config_init(&mboxCfg);
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;
775 gMCB.
mboxHandle = Mailbox_open(MAILBOX_TYPE_DSS, &mboxCfg, &errCode);
777 System_printf(
"[MSS] \t [Error][MAILBOX] Unable to open the Mailbox to the DSS [Error code %d]\n", errCode);
779 System_printf(
"[MSS] \t [MAILBOX] Opening Mailbox Channel to the DSP Subsystem [DSS] .. \n");
783 Task_Params_init(&taskParams);
784 taskParams.stackSize = 16*1024;
790 memset ((
void*)&listenerCfg, 0,
sizeof(SOC_SysIntListenerCfg));
791 listenerCfg.systemInterrupt = SOC_XWR18XX_MSS_CHIRP_AVAIL_IRQ;
797 System_printf (
"[MSS] \t [Error] Unable to register the Chirp Available Listener/Interrupt [Error code %d]\n", errCode);
802 memset ((
void*)&listenerCfg, 0,
sizeof(SOC_SysIntListenerCfg));
803 listenerCfg.systemInterrupt = SOC_XWR18XX_MSS_FRAME_START_INT;
810 System_printf(
"[MSS] \t [Error] Unable to register the Frame start Listener/Interrupt [Error code %d]\n", errCode);
815 memset ((
void *)&initCfg, 0,
sizeof(MMWave_InitCfg));
819 initCfg.domain = MMWave_Domain_MSS;
822 initCfg.cfgMode = MMWave_ConfigurationMode_MINIMAL;
823 initCfg.executionMode = MMWave_ExecutionMode_ISOLATION;
824 initCfg.linkCRCCfg.useCRCDriver = 1U;
825 initCfg.linkCRCCfg.crcChannel = CRC_Channel_CH1;
836 System_printf (
"[MSS] \t [Error][Init][mmWAVE] mmWave Control Initialization failed [Error code %d]\n", errCode);
839 System_printf (
"[MSS] \t [Debug][Init][mmWAVE] Initialized the mmWave module\n");
848 if (syncStatus < 0) {
850 System_printf (
"Error: mmWave Control Synchronization failed [Error code %d]\n", errCode);
853 if (syncStatus == 1) {
855 System_printf (
"[MSS] \t [SYNCH][mmWAVE]: mmWave Control Synchronization Achieved\n");
863 System_printf (
"[MSS] \t [DEBUG][SYNCH] Synchronized the mmWave module\n");
866 #ifdef SUBFRAME_CONF_MRR_USRR
870 #ifdef SUBFRAME_CONF_MRR
873 #ifdef SUBFRAME_CONF_USRR
884 Task_Params_init(&taskParams);
886 taskParams.stackSize = 3*1024;
918 Task_Params taskParams;
926 memset((
void*)&
gMCB, 0,
sizeof(
MCB));
929 memset((
void *)&socCfg, 0,
sizeof(SOC_Cfg));
932 socCfg.clockCfg = SOC_SysClock_INIT;
940 System_printf (
"[MSS] \t [Error][SOC] SOC Module Initialization failed [Error code %d]\n", errCode);
948 (uint32_t)(SOC_SECURE_FIREWALL_JTAG | SOC_SECURE_FIREWALL_LOGGER),
949 SOC_SECURE_FIREWALL_DISABLE, &errCode);
952 System_printf (
"**********************************************************\n");
953 System_printf (
"[MSS] \t [DEBUG] Launching the Millimeter Wave Application\n");
954 System_printf (
"**********************************************************\n");
957 Task_Params_init(&taskParams);