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.

TMS320F28377D: What exactly does "mask identifier" mean?

Part Number: TMS320F28377D

Hi,

When reading reference manual of CAN communication, I am very confused about the meaning of mask. I think literally speaking, "mask" means something covered and cannot be seen. So if we set those corresponding mask bits to "1", "mask" should take effect and we cannot really see those bits, eg: identifier. But when looking at the register description, it seems different. So I wonder if I set the ID mask bits to "0", do those ID still be used for acceptance filtering (comparing) or ignored (anything can pass)? And in the example code, masks are set to "0", do we want to use ID or not?

Thanks,

Yi

  • If you set an ID mask bit to zero, that ID bit in the address will be ignored. Either value of that ID bit will be accepted.

    The mask bits are ANDed with the ID bits before filtering. In C, the filter would look like this:

    if ((incoming_message_id & mask) == (message_object_id & mask))
    {
        accept_message();
    } else
    {
        ignore_message();
    }

    The example code doesn't use the mask -- all ID bits are compared. To use the mask, you would need to change this line:

    sRXCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE;

    to this:

    sRXCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
    

    You would also need to set sRXCANMessage.ui32MsgIdMask to a nonzero value.




  • Also note that ui32MsgIDMask is the actual mask itself. Whether or not to use the acceptance mask is determined by the UMask bit.

  • Hi Adam,

    Thanks for the reply. I got your idea that "The mask bits are ANDed with the ID bits" but am confused about what is going on in the example code.
    Since sRXCANMessage.ui32Flags will eventually goes like this:

    // Write out the registers to program the message object.
    HWREGH(ui32Base + CAN_O_IF1CMD + 2) = ui32CmdMaskReg >> 16;

    HWREGH(ui32Base + CAN_O_IF1MSK) = ui32MaskReg & CAN_REG_WORD_MASK;
    HWREGH(ui32Base + CAN_O_IF1MSK + 2) = ui32MaskReg >> 16;

    And before that, with MSG_OBJ_USE_ID_FILTER, it is:

    ui32MaskReg = 0;

    // Configure the Mask Registers.
    if(pMsgObject->ui32Flags & MSG_OBJ_USE_ID_FILTER)
    {
    if(bUseExtendedID)
    {
    // Set the 29 bits of Identifier mask that were requested.
    ui32MaskReg = pMsgObject->ui32MsgIDMask & CAN_IF1MSK_MSK_M;
    }
    else
    {

    // Put the 11 bit Mask Identifier into the upper bits of the field
    // in the register.
    ui32MaskReg = ((pMsgObject->ui32MsgIDMask << CAN_IF1ARB_STD_ID_S) &
    CAN_IF1ARB_STD_ID_M);
    }
    }

    If pMsgObject->ui32MsgIDMask = 0x0 here, even if it is ANDed with 0x1FFF000 (like this), it is still 0 at last. Then it is given to HWREGH, which results in 0 of corresponding Mask register bits. In this way, sRXCANMessage.ui32MsgIdMask = 0 means ignoring ID bits evenif not configuring like this: sRXCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER;
    I am very confused and maybe wrong somewhere. Can you give some detailed explanation?

    Thanks a lot.
  • Yes I noticed that and it is programmed in the example code like this:
    if(pMsgObject->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.
    ui32MsgCtrl |= CAN_IF1MCTL_UMASK;

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

    So I think it is OK to use the mask. But still do not understand how it goes when sRXCANMessage.ui32Flags = 0. Any hints?
  • There's a bit in the message object called UMask. You can find it in the IF1MCTL register. This bit determines how the filtering works. If the UMask bit is a 0, all of the arbitration bits are used for filtering, and the mask bits are ignored. If the UMask bit is a 1, both the arbitration bits and the mask bits are used for filtering.

    The driverlib function look at the ui32Flags variable to decide how to set Umask. If Umask becomes 0, the value of ui32MsgIdMask doesn't matter.
  • Hi, Adam

    I think I understand your point and find the location in example code where Umask bit is configured according to ui32Flags variable. But what I still do not understand is how "ui32MsgIDMask = 0;" means not using mask bits, since according to example code, it will end up with "0" after "AND" with "1" for several times.

    1.

    From example code of "external CAN transmit"

    // Initialize the receive message object used for receiving CAN messages.
    // Message Object Parameters:
    // Message Identifier: 0x5555
    // Message ID Mask: 0x0
    // Message Object Flags: Receive Interrupt
    // Message Data Length: 4 Bytes
    // Message Receive data: rxMsgData
    //
    sRXCANMessage.ui32MsgID = 0x5555;
    sRXCANMessage.ui32MsgIDMask = 0;
    sRXCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE;
    sRXCANMessage.ui32MsgLen = MSG_DATA_LENGTH;
    sRXCANMessage.pucMsgData = rxMsgData;
    CANMessageSet(CANB_BASE, RX_MSG_OBJ_ID, &sRXCANMessage,
    MSG_OBJ_TYPE_RX);

    So, here all mask bits are set to '0'.

    2.

    In the function of "CANMessageSet"

    // Configure the Mask Registers.
    if(pMsgObject->ui32Flags & MSG_OBJ_USE_ID_FILTER)
    {
    if(bUseExtendedID)
    {
    // Set the 29 bits of Identifier mask that were requested.
    ui32MaskReg = pMsgObject->ui32MsgIDMask & CAN_IF1MSK_MSK_M;
    }
    else
    {

    // Put the 11 bit Mask Identifier into the upper bits of the field
    // in the register.
    ui32MaskReg = ((pMsgObject->ui32MsgIDMask << CAN_IF1ARB_STD_ID_S) &
    CAN_IF1ARB_STD_ID_M);
    }
    }

    Here, CAN_IF1MSK_MSK_M = 0x1FFFFFFF,( or CAN_IF1ARB_STD_ID_M = 0x1FFC0000) so 

    ui32MaskReg = pMsgObject->ui32MsgIDMask & CAN_IF1MSK_MSK_M;

    equals to      

    ui32MaskReg = 0x0 & 0x1FFFFFFF = 0x0;    Nothing changes after "bit AND", no matter for extended ID or not.

    3.

    if(pMsgObject->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.
    ui32MsgCtrl |= CAN_IF1MCTL_UMASK;

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

    Here, Umask bit is not set because of no flag of FILTER.

    4.

    // Write out the registers to program the message object.
    HWREGH(ui32Base + CAN_O_IF1CMD + 2) = ui32CmdMaskReg >> 16;

    HWREGH(ui32Base + CAN_O_IF1MSK) = ui32MaskReg & CAN_REG_WORD_MASK;
    HWREGH(ui32Base + CAN_O_IF1MSK + 2) = ui32MaskReg >> 16;

    Here, ui32MaskReg value is put into MASK register, which is all 0x0 according to above process. If Umask is not set as in this example code, mask bits in MASK register (0x0) does not count. But if MSG_OBJ_USE_ID_FILTER is set in ui32Flags, then the same case of MASK register(0x0) will result in all ID bits ingored, right?

    So in this example code, because Umask bit is not set, we can set sRXCANMessage.ui32MsgIDMask = 0; for simple use. But if we want to mask some bits (ignore the ID bits), then when setting sRXCANMessage.ui32MsgIDMask, only those bits can be set as 0x0 and all other bits used for filtering should be set as "1". This is what I can understand to the best of knowledge, please let me know if it is right.

    Thanks a lot,

    Yi

  • You are correct. Setting ui32MsgIdMask to 0 does set the IF1MSK bits to 0. The mask is then ignored because UMASK=0. Sorry for being unclear before.
  • Hi Adam,

    Thanks a lot for the confirmation. Now I can say I understand it. Since 28032 I used before is defined the opposite way as 28377 in the CAN mask part, it took me a while to figure it out. Really appreciate it !!

    Yi
  • Yi,

       I will add  a note in our documentation to alert customers about this (i.e. the mask bits have opposite "polarity" in the DCAN module when compared to the eCAN module).

  • Hi Hareesh,

    I think that would be good for future use!

    Thanks,

    Yi