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.

TMS570LS3137 DCAN transmit pkt drop frame



Hello,

Now I debug the 570 DCAN module. I am using the can bus to transmit pkt, using another USB-CAN to inspect the pkt.

My code are following :

    for(i=0;i<ulFrameNum;i++)
    {
        ulMbId = canMESSAGE_BOX18+i%(canMESSAGE_BOX32-canMESSAGE_BOX17);
        while(canIsTxMessagePending(pCanReg, ulMbId)) /* check the message object tx finished  */
        {
 
        }
        if(i>0)
        {
            ulLstMbId = (i+15-1)%15+18;
            while(canIsTxMessagePending(pCanReg, ulLstMbId))  /* check last MB tx finished */
             {
                g_ulDelayCnt[i]++;
            }
        }
        if(i==ulFrameNum-1) /* last frame */
        {
            unMsgId.tCANMsgID.ulSegFlag = CAN_DATA_SEG_LAST;
            g_stCanMsgObj[ulMbId].ui32MsgLen = ulLen%8?(ulLen%8):8;
        }
        else /* middle frame */
        {
            unMsgId.tCANMsgID.ulSegFlag = CAN_DATA_SEG_MID;
            g_stCanMsgObj[ulMbId].ui32MsgLen = 8;
        }
        unMsgId.tCANMsgID.ulFrameId = i;
        unMsgId.tCANMsgID.ulFrameTtlNum= ulFrameNum;
        g_stCanMsgObj[ulMbId].ui32MsgID = unMsgId.ulMsgId;
        g_stCanMsgObj[ulMbId].pui8MsgData = pucDataTmp+i*8;
        CANMessageSet(pCanReg, ulMbId, &(g_stCanMsgObj[ulMbId]), MSG_OBJ_TYPE_TX);
    }

void  CANMessageSet(canBASE_t * const pCanReg, uint32_t ui32ObjID,
              tCANMsgObject *psMsgObject, tMsgObjType eMsgType)
{
    uint8_t ui8CmdMaskReg;
    uint32_t ui32MaskReg;
    uint32_t ui32ArbReg;
    uint16_t ui16MsgCtrl;
    bool bTransferData;
    bool bUseExtendedID;

    bTransferData = 0;

    /* Check the arguments. */
    ASSERT_FS( pCanReg!=NULL );
    ASSERT_FS( psMsgObject!=NULL);
    ASSERT_FS((ui32ObjID <= canMESSAGE_BOX64) && (ui32ObjID != 0));
    ASSERT_FS((eMsgType == MSG_OBJ_TYPE_TX) ||
             (eMsgType == MSG_OBJ_TYPE_TX_REMOTE) ||
             (eMsgType == MSG_OBJ_TYPE_RX) ||
             (eMsgType == MSG_OBJ_TYPE_RX_REMOTE) ||
             (eMsgType == MSG_OBJ_TYPE_TX_REMOTE) ||
             (eMsgType == MSG_OBJ_TYPE_RXTX_REMOTE));

    /* Wait for busy bit to clear */
    while(pCanReg->IF2STAT & CAN_IF2CRQ_BUSY)
    {
    }

    /* See if we need to use an extended identifier or not. */
    if((psMsgObject->ui32MsgID > CAN_MAX_11BIT_MSG_ID) ||
       (psMsgObject->ui32Flags & MSG_OBJ_EXTENDED_ID))
    {
        bUseExtendedID = 1;
    }
    else
    {
        bUseExtendedID = 0;
    }

    /* This is always a write to the Message object as this call is setting
    a message object.  This call always sets all size bits so it sets both
    data bits.  The call uses the CONTROL register to set control bits so this
    bit needs to be set as well. */
    ui8CmdMaskReg = (CAN_IF2CMSK_WRNRD | CAN_IF2CMSK_DATAA |
                      CAN_IF2CMSK_DATAB | CAN_IF2CMSK_CONTROL);

    /* Initialize the values to a known state before filling them in based on
    the type of message object that is being configured. */
    ui32ArbReg = 0;
    ui16MsgCtrl = 0;
    ui32MaskReg = 0;

    switch(eMsgType)
    {
        /* Transmit message object. */
        case MSG_OBJ_TYPE_TX:
        {
            /* Set the TXRQST bit and the reset the rest of the register. */
            ui16MsgCtrl |= CAN_IF2MCTL_TXRQST;
            ui32ArbReg = CAN_IF2ARB_DIR;
            bTransferData = 1;
            break;
        }

        /* Transmit remote request message object */
        case MSG_OBJ_TYPE_TX_REMOTE:
        {
            /* Set the TXRQST bit and the reset the rest of the register. */
            ui16MsgCtrl |= CAN_IF2MCTL_TXRQST;
            ui32ArbReg = 0;
            break;
        }

        /* Receive message object. */
        case MSG_OBJ_TYPE_RX:
        {
            /*This clears the DIR bit along with everything else.  The TXRQST
            bit was cleared by defaulting ui16MsgCtrl to 0.*/
            ui32ArbReg = 0;
            break;
        }

        /* Receive remote request message object. */
        case MSG_OBJ_TYPE_RX_REMOTE:
        {
            /* The DIR bit is set to one for remote receivers.  The TXRQST bit
            was cleared by defaulting ui16MsgCtrl to 0.*/
            ui32ArbReg = CAN_IF2ARB_DIR;

            // Set this object so that it only indicates that a remote frame
            // was received and allow for software to handle it by sending back
            // a data frame.
            //
            ui16MsgCtrl = CAN_IF2MCTL_UMASK;

            //
            // Use the full Identifier by default.
            //
            ui32MaskReg = 0x1fffffff;

            //
            // Make sure to send the mask to the message object.
            //
            ui8CmdMaskReg |= CAN_IF2CMSK_MASK;
            break;
        }

        //
        // Remote frame receive remote, with auto-transmit message object.
        //
        case MSG_OBJ_TYPE_RXTX_REMOTE:
        {
            //
            // Oddly the DIR bit is set to one for remote receivers.
            //
            ui32ArbReg = CAN_IF2ARB_DIR;

            //
            // Set this object to auto answer if a matching identifier is seen.
            //
            ui16MsgCtrl = CAN_IF2MCTL_RMTEN | CAN_IF2MCTL_UMASK;

            //
            // The data to be returned needs to be filled in.
            //
            bTransferData = 1;
            break;
        }

        //
        // This case never happens due to the ASSERT statement at the
        // beginning of this function.
        //
        default:
        {
            return;
        }
    }

    //
    // Configure the Mask Registers.
    //
    if(psMsgObject->ui32Flags & MSG_OBJ_USE_ID_FILTER)
    {
        if(bUseExtendedID)
        {
            //
            // Set the 29 bits of Identifier mask that were requested.
            //
            ui32MaskReg = psMsgObject->ui32MsgIDMask & CAN_IF2MSK_IDMSK_M;
        }
        else
        {
            // Put the 11 bit Mask Identifier into the upper bits of the field
            // in the register.
            //
            ui32MaskReg = (psMsgObject->ui32MsgIDMask & CAN_IF2MSK_IDMSK_S);
        }
    }

    //
    // If the caller wants to filter on the extended ID bit then set it.
    //
    if((psMsgObject->ui32Flags & MSG_OBJ_USE_EXT_FILTER) ==
       MSG_OBJ_USE_EXT_FILTER)
    {
        ui32MaskReg |= CAN_IF2MSK_MXTD;
    }

    //
    // The caller wants to filter on the message direction field.
    //
    if((psMsgObject->ui32Flags & MSG_OBJ_USE_DIR_FILTER) ==
       MSG_OBJ_USE_DIR_FILTER)
    {
        ui32MaskReg |= CAN_IF2MSK_MDIR;
    }

    if(psMsgObject->ui32Flags &
       (MSG_OBJ_USE_ID_FILTER | MSG_OBJ_USE_DIR_FILTER |
        MSG_OBJ_USE_EXT_FILTER))
    {
        //
        // Set the UMASK bit to enable using the mask register.
        //
        ui16MsgCtrl |= CAN_IF2MCTL_UMASK;

        //
        // Set the MASK bit so that this gets transferred to the Message
        // Object.
        //
        ui8CmdMaskReg |= CAN_IF2CMSK_MASK;
    }

    //
    // Set the Arb bit so that this gets transferred to the Message object.
    //
    ui8CmdMaskReg |= CAN_IF2CMSK_ARB;

    //
    // Configure the Arbitration registers.
    //
    if(bUseExtendedID)
    {
        //
        // Set the 29 bit version of the Identifier for this message object.
        //
        ui32ArbReg |= psMsgObject->ui32MsgID & CAN_IF2ARB_ID_M;

        //
        // Mark the message as valid and set the extended ID bit.
        //
        ui32ArbReg |= CAN_IF2ARB_MSGVAL | CAN_IF2ARB_XTD;
    }
    else
    {
        //
        // Set the 11 bit version of the Identifier for this message object.
        // The lower 18 bits are set to zero.
        //
        ui32ArbReg |= psMsgObject->ui32MsgID & CAN_IF2ARB_ID_S;

        //
        // Mark the message as valid.
        //
        ui32ArbReg |= CAN_IF2ARB_MSGVAL;
    }

    //
    // Set the data length since this is set for all transfers.  This is also a
    // single transfer and not a FIFO transfer so set EOB bit.
    //
    ui16MsgCtrl |= (psMsgObject->ui32MsgLen & CAN_IF2MCTL_DLC_M);

    //
    // Mark this as the last entry if this is not the last entry in a FIFO.
    //
    if((psMsgObject->ui32Flags & MSG_OBJ_FIFO) == 0)
    {
        ui16MsgCtrl |= CAN_IF2MCTL_EOB;
    }
    else
    {
        ui16MsgCtrl &= (~CAN_IF2MCTL_EOB);
    }

    //
    // Enable transmit interrupts if they should be enabled.
    //
    if(psMsgObject->ui32Flags & MSG_OBJ_TX_INT_ENABLE)
    {
        ui16MsgCtrl |= CAN_IF2MCTL_TXIE;
    }

    //
    // Enable receive interrupts if they should be enabled.
    //
    if(psMsgObject->ui32Flags & MSG_OBJ_RX_INT_ENABLE)
    {
        ui16MsgCtrl |= CAN_IF2MCTL_RXIE;
    }

    //
    // Write the data out to the CAN Data registers if needed.
    //
    if(bTransferData)
    {
        CANDataRegWrite(pCanReg,ui32ObjID,psMsgObject->pui8MsgData);
    }

    //
    // Write out the registers to program the message object.
    //
    pCanReg->IF2CMD = ui8CmdMaskReg;
    pCanReg->IF2MSK = ui32MaskReg;
    pCanReg->IF2ARB = ui32ArbReg;
    pCanReg->IF2MCTL = ui16MsgCtrl;

    //
    // Transfer the message object to the message object specified by
    // ui32ObjID.
    //
    pCanReg->IF2NO = ui32ObjID & CAN_IF2CRQ_MNUM;
}
when I send pkt about 80 frames, there are 2 or 3 frames droped, the frame no droped was the same every time . Pls help me why this happened.