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.

IWR6843AOPEVM: The CAN function CANFD_createRxRangeMsgObject do not work as expected.

Part Number: IWR6843AOPEVM

I set up the function like this:

rxRangeMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;

rxRangeMsgObjectParams.startMsgIdentifier = 0x1D3;

rxRangeMsgObjectParams.endMsgIdentifier = 0x1D5;

 

rxMsgObjHandle3 = CANFD_createRxRangeMsgObject(canHandle, &rxRangeMsgObjectParams, &errCode);

 

I do not get any error mesages. When I send messages to the EVM in the range above the callback funtion is not called.

 

Normal rx objects works with no problems defined as below:

 rxMsgObjectParams.direction = CANFD_Direction_RX;

    rxMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;//CANFD_MCANXidType_11_BIT;//CANFD_MCANXidType_29_BIT;

    rxMsgObjectParams.msgIdentifier = 0x1D1;

    rxMsgObjHandle = CANFD_createMsgObject(canHandle, &rxMsgObjectParams,

                                           &errCode);

 

One weird thing is that if I send an can message to the EVM that is not set up as an object, the callback function is still called but with an empty handle. 

If I send a can message that is set up in the range the callback funtion is not called at all. It is like the functinality of the range function is inverted. 

/* Standard Include Files. */
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <math.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>
#include <ti/sysbios/family/arm/v7a/Pmu.h>
#include <ti/sysbios/family/arm/v7r/vim/Hwi.h>
#include <ti/sysbios/utils/Load.h>
#include <ti/common/mmwave_error.h>

/* mmWave SDK Include Files: */
#include <ti/common/sys_common.h>
#include <ti/common/mmwave_sdk_version.h>
#include <ti/drivers/soc/soc.h>
#include <ti/drivers/esm/esm.h>
#include <ti/drivers/pinmux/pinmux.h>
#include <ti/drivers/crc/crc.h>
#include <ti/drivers/gpio/gpio.h>
#include <ti/drivers/mailbox/mailbox.h>
#include <ti/control/mmwave/mmwave.h>
#include <ti/control/dpm/dpm.h>
#include <ti/datapath/dpc/objectdetection/objdethwa/objectdetection.h>
#include <ti/drivers/osal/DebugP.h>
#include <ti/drivers/uart/UART.h>
#include <ti/utils/cli/cli.h>
#include <ti/utils/mathutils/mathutils.h>
#include <ti/utils/cycleprofiler/cycle_profiler.h>
#include <ti/demo/utils/mmwdemo_rfparser.h>
#include <ti/demo/xwr64xx/mmw/mmw_output.h>
#include <ti/drivers/canfd/canfd.h>

#include <ti/demo/xwr64xx/mmw/mmw.h>


/**************************************************************************
 *************************** Global Definitions ***************************
 **************************************************************************/
volatile uint32_t gTxDoneFlag = 0, gRxDoneFlag = 0, gParityErrFlag = 0;
volatile uint32_t gTxPkts = 0, gRxPkts = 0, gErrStatusInt = 0;
volatile uint32_t iterationCount = 0U;
uint32_t dataLength = 0U;
uint32_t msgLstErrCnt = 0U;
uint32_t gDisplayStats = 0;
uint8_t rxData[64U];
uint32_t txDataLength, rxDataLength;
CANFD_MCANFrameType frameType = CANFD_MCANFrameType_CLASSIC;
static void MCANAppInitParams(CANFD_MCANInitParams* mcanCfgParams);
CANFD_Handle canHandle;
CANFD_MsgObjHandle txMsgObjHandle;
CANFD_MCANMsgObjCfgParams txMsgObjectParams;

extern MmwDemo_MCB    gMmwMCB;

/**************************************************************************
 *************************** CAN Driver Initialize Function ***********************
 **************************************************************************/
static void MCANAppErrStatusCallback(CANFD_Handle handle, CANFD_Reason reason,
                                     CANFD_ErrStatusResp* errStatusResp);
static void MCANAppCallback(CANFD_MsgObjHandle handle, CANFD_Reason reason);

//CANFD_MsgObjHandle rxMsgObjHandle,rxMsgObjHandle2;

void Can_Initalize(void)
{
    int32_t errCode = 0;
    int32_t retVal = 0;
    CANFD_MCANInitParams mcanCfgParams;
    CANFD_MCANBitTimingParams mcanBitTimingParams;
    CANFD_MCANMsgObjCfgParams rxMsgObjectParams;
    CANFD_MCANRxMsgObjRangeCfgParams rxRangeMsgObjectParams;
    CANFD_MsgObjHandle rxMsgObjHandle,rxMsgObjHandle2,rxMsgObjHandle3;
    gTxDoneFlag = 0;
    gRxDoneFlag = 0;
    /* Setup the PINMUX to bring out the XWR16xx CAN pins */
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PINE14_PADAE,
                            PINMUX_OUTEN_RETAIN_HW_CTRL,
                            PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PINE14_PADAE,
                       SOC_XWR68XX_PINE14_PADAE_CANFD_TX);
    Pinmux_Set_OverrideCtrl(SOC_XWR68XX_PIND13_PADAD,
                            PINMUX_OUTEN_RETAIN_HW_CTRL,
                            PINMUX_INPEN_RETAIN_HW_CTRL);
    Pinmux_Set_FuncSel(SOC_XWR68XX_PIND13_PADAD,
                       SOC_XWR68XX_PIND13_PADAD_CANFD_RX);
    /* Configure the divide value for MCAN source clock */
    SOC_setPeripheralClock(gMmwMCB.socHandle, SOC_MODULE_MCAN,
                           SOC_CLKSOURCE_VCLK, 4U, &errCode);
    /* Initialize peripheral memory */
    SOC_initPeripheralRam(gMmwMCB.socHandle, SOC_MODULE_MCAN, &errCode);
    MCANAppInitParams(&mcanCfgParams);
    /* Initialize the CANFD driver */
    canHandle = CANFD_init(&mcanCfgParams, &errCode);
    if (canHandle == NULL)
    {
        System_printf(
                "Error: CANFD Module Initialization failed [Error code %d]\n",
                errCode);
        return;
    }
    /* Configuring 1Mbps and 5Mbps as nominal and data bit-rate respectively
     Prop seg: 8
     Ph seg 1: 6
     Ph Seg2 : 5
     Sync jump: 1
     BRP(Baud rate Prescaler): 2
     Nominal Bit rate = (40)/(((8+6+5)+1)*BRP) = 1Mhz
     Timing Params for Data Bit rate:
     Prop seg: 2
     Ph seg 1: 2
     Ph Seg2 : 3
     Sync jump: 1
     BRP(Baud rate Prescaler): 1
     Nominal Bit rate = (40)/(((2+2+3)+1)*BRP) = 5Mhz
     */
    mcanBitTimingParams.nomBrp = 0x2U;
    mcanBitTimingParams.nomPropSeg = 0x8U;
    mcanBitTimingParams.nomPseg1 = 0x6U;
    mcanBitTimingParams.nomPseg2 = 0x5U;
    mcanBitTimingParams.nomSjw = 0x1U;
    mcanBitTimingParams.dataBrp = 0x1U;
    mcanBitTimingParams.dataPropSeg = 0x2U;
    mcanBitTimingParams.dataPseg1 = 0x2U;
    mcanBitTimingParams.dataPseg2 = 0x3U;
    mcanBitTimingParams.dataSjw = 0x1U;
    /* Configure the CAN driver */
    retVal = CANFD_configBitTime(canHandle, &mcanBitTimingParams, &errCode);
    if (retVal < 0)
    {
        System_printf(
                "Error: CANFD Module configure bit time failed [Error code %d]\n",
                errCode);
        return;
    }
    /* Setup the transmit message object */
    txMsgObjectParams.direction = CANFD_Direction_TX;
    txMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
    txMsgObjectParams.msgIdentifier = 0xD1;
    txMsgObjHandle = CANFD_createMsgObject(canHandle, &txMsgObjectParams,
                                           &errCode);
    if (txMsgObjHandle == NULL)
    {
        System_printf(
                "Error: CANFD create Tx message object failed [Error code %d]\n",
                errCode);
        return;
    }
    /* Setup the receive message object */
    rxMsgObjectParams.direction = CANFD_Direction_RX;
    rxMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;//CANFD_MCANXidType_11_BIT;//CANFD_MCANXidType_29_BIT;
    rxMsgObjectParams.msgIdentifier = 0x1D1;
    rxMsgObjHandle = CANFD_createMsgObject(canHandle, &rxMsgObjectParams,
                                           &errCode);
    if (rxMsgObjHandle == NULL)
    {
        System_printf(
                "Error: CANFD create Rx message object failed [Error code %d]\n",
                errCode);
        return;
    }

    rxMsgObjectParams.msgIdentifier = 0x1D2;
    rxMsgObjHandle2 = CANFD_createMsgObject(canHandle, &rxMsgObjectParams,
                                           &errCode);
    if (rxMsgObjHandle2 == NULL)
    {
        System_printf(
                "Error: CANFD create Rx message object failed [Error code %d]\n",
                errCode);
        return;
    }

    rxRangeMsgObjectParams.msgIdType = CANFD_MCANXidType_29_BIT;
    rxRangeMsgObjectParams.startMsgIdentifier = 0x1D3;
    rxRangeMsgObjectParams.endMsgIdentifier = 0x1D5;

    rxMsgObjHandle3 = CANFD_createRxRangeMsgObject(canHandle, &rxRangeMsgObjectParams, &errCode);
    if (rxMsgObjHandle3 == NULL)
       {
           System_printf(
                   "Error: CANFD create range Rx message object failed [Error code %d]\n",
                   errCode);
           return;
       }
}
/**************************************************************************
 ******************** CAN Parameters initialize Function *****************
 **************************************************************************/
static void MCANAppInitParams(CANFD_MCANInitParams* mcanCfgParams)
{
    /*Intialize MCAN Config Params*/
    memset(mcanCfgParams, sizeof(CANFD_MCANInitParams), 0);
    mcanCfgParams->fdMode = 0x1U;
    mcanCfgParams->brsEnable = 0x1U;
    mcanCfgParams->txpEnable = 0x0U;
    mcanCfgParams->efbi = 0x0U;
    mcanCfgParams->pxhddisable = 0x0U;
    mcanCfgParams->darEnable = 0x1U;
    mcanCfgParams->wkupReqEnable = 0x1U;
    mcanCfgParams->autoWkupEnable = 0x1U;
    mcanCfgParams->emulationEnable = 0x0U;
    mcanCfgParams->emulationFAck = 0x0U;
    mcanCfgParams->clkStopFAck = 0x0U;
    mcanCfgParams->wdcPreload = 0x0U;
    mcanCfgParams->tdcEnable = 0x1U;
    mcanCfgParams->tdcConfig.tdcf = 0U;
    mcanCfgParams->tdcConfig.tdco = 8U;
    mcanCfgParams->monEnable = 0x0U;
    mcanCfgParams->asmEnable = 0x0U;
    mcanCfgParams->tsPrescalar = 0x0U;
    mcanCfgParams->tsSelect = 0x0U;
    mcanCfgParams->timeoutSelect = CANFD_MCANTimeOutSelect_CONT;
    mcanCfgParams->timeoutPreload = 0x0U;
    mcanCfgParams->timeoutCntEnable = 0x0U;
    mcanCfgParams->filterConfig.rrfe = 0x1U;
    mcanCfgParams->filterConfig.rrfs = 0x1U;
    mcanCfgParams->filterConfig.anfe = 0x1U;
    mcanCfgParams->filterConfig.anfs = 0x1U;
    mcanCfgParams->msgRAMConfig.lss = 127U;
    mcanCfgParams->msgRAMConfig.lse = 64U;
    mcanCfgParams->msgRAMConfig.txBufNum = 32U;
    mcanCfgParams->msgRAMConfig.txFIFOSize = 0U;
    mcanCfgParams->msgRAMConfig.txBufMode = 0U;
    mcanCfgParams->msgRAMConfig.txEventFIFOSize = 0U;
    mcanCfgParams->msgRAMConfig.txEventFIFOWaterMark = 0U;
    mcanCfgParams->msgRAMConfig.rxFIFO0size = 0U;
    mcanCfgParams->msgRAMConfig.rxFIFO0OpMode = 0U;
    mcanCfgParams->msgRAMConfig.rxFIFO0waterMark = 0U;
    mcanCfgParams->msgRAMConfig.rxFIFO1size = 64U;
    mcanCfgParams->msgRAMConfig.rxFIFO1waterMark = 64U;
    mcanCfgParams->msgRAMConfig.rxFIFO1OpMode = 64U;
    mcanCfgParams->eccConfig.enable = 1;
    mcanCfgParams->eccConfig.enableChk = 1;
    mcanCfgParams->eccConfig.enableRdModWr = 1;
    mcanCfgParams->errInterruptEnable = 1U;
    mcanCfgParams->dataInterruptEnable = 1U;
    mcanCfgParams->appErrCallBack = MCANAppErrStatusCallback;
    mcanCfgParams->appDataCallBack = MCANAppCallback;
}

static void MCANAppCallback(CANFD_MsgObjHandle handle, CANFD_Reason reason)
{
    int32_t errCode, retVal;
    uint32_t id;
    CANFD_MCANFrameType rxFrameType;
    CANFD_MCANXidType rxIdType;
    if (reason == CANFD_Reason_TX_COMPLETION)
    {
        {
            gTxPkts++;
            gTxDoneFlag = 1;
            return;
        }
    }
    if (reason == CANFD_Reason_RX)
    {
        {
            /* Reset the receive buffer */
            memset(&rxData, 0, sizeof(rxData));
            dataLength = 0;
            retVal = CANFD_getData(handle, &id, &rxFrameType, &rxIdType,
                                   &rxDataLength, &rxData[0], &errCode);
            if (retVal < 0)
            {
         //   System_printf ("Error: CAN receive data for iteration %d failed [Error code %d]\n", iterationCount, errCode);
                    return;
            }
            if (rxFrameType != frameType)
            {
           // System_printf ("Error: CAN received incorrect frame type Sent %d Received %d for iteration %d failed\n", frameType, rxFrameType, iterationCount);
                    return;
            }
            /* Validate the data */
            gRxPkts++;
            gRxDoneFlag = 1;
            return;
        }
    }
    if (reason == CANFD_Reason_TX_CANCELED)
    {
        {
            gTxPkts++;
            gTxDoneFlag = 1;
            gRxDoneFlag = 1;
            return;
        }
    }
}

static void MCANAppErrStatusCallback(CANFD_Handle handle, CANFD_Reason reason,
                                     CANFD_ErrStatusResp* errStatusResp)
{
    /*Record the error count */
    gErrStatusInt++;
    return;
}



int32_t  MCANApp_transmitDataBuffer(uint32_t msg_id, CANFD_MCANFrameType frameType,
                               uint32_t dataLength, const uint8_t* txmsg)
{
    int32_t errCode;
    static int32_t retVal;
    int32_t index = 0;
    uint32_t len = dataLength;

    if(frameType == CANFD_MCANFrameType_FD)
    {
        Task_sleep(1);
        while(len > 64U)
        {
            retVal = CANFD_transmitData (txMsgObjHandle, msg_id, CANFD_MCANFrameType_FD, 64U, &txmsg[index],
                    &errCode);
            index = index + 64U;
            len = len - 64U;
            Task_sleep(1);
        }
        retVal = CANFD_transmitData (txMsgObjHandle, msg_id, CANFD_MCANFrameType_FD, len, &txmsg[index],
                &errCode);
    }
    else
    {
        while(len > 8U)
        {
            retVal = CANFD_transmitData (txMsgObjHandle, msg_id,
                    CANFD_MCANFrameType_CLASSIC, 8U, &txmsg[index], &errCode);
            if (retVal < 0)
            {
                continue;
            }
            index = index + 8U;
            len = len - 8U;
        }
        retVal = CANFD_transmitData (txMsgObjHandle, msg_id, CANFD_MCANFrameType_CLASSIC,
                len, &txmsg[index], &errCode);
      /*  while(retVal < 0)
        {
            retVal = CANFD_transmitData (txMsgObjHandle, msg_id, CANFD_MCANFrameType_CLASSIC, len,
                    &txmsg[index], &errCode);
        }*/
    }
    return 0;
}


void  MCANApp_testTask(UArg arg0, UArg arg1)
{
/*    int32_t     retVal;
    DPM_Buffer  resultBuffer;
    DPC_ObjectDetection_ExecuteResultExportedInfo exportInfo;
    DPC_ObjectDetection_ExecuteResult *result;*/
    uint8_t txmsg[8] = {0,1,2,3,4,5,6,7};

    while (1)
    {
   //     MCANApp_transmitDataBuffer(1001, CANFD_MCANFrameType_CLASSIC, 8, txmsg);
        Task_sleep(1000);
    }
}