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.

CCS/HALCOGEN: CAN bus DLC With Dynamic Message Box ID

Part Number: HALCOGEN


Tool/software: Code Composer Studio

I am using a library "Cubesat Space Protocol" to send network packets for my application over CAN bus. The interface provided by this library implements a CAN bus framing protocol which requires that I update the outgoing CAN ID for every byte because the protocol runs a state machine to reassemble the packets (and encodes information about the network connection in the ID). I've spent a long time trying to understand the 'message box' framework provided by Halcogen, but I may still not be understanding things correctly.

I am developing this with a loopback on the TMS570LC43 Hercules HDK (the big one with 2 built in CAN outputs) with a physical connection between CAN1 and CAN2, and I have configured in Halcogen for each CAN1 and CAN2 to have even numbered message boxes in receiving/intrurrupt mode, and 0x00000000 ID mask to  accept any IDs, and DLCs on each message boxes descending (i.e., message box 1 => transmit & DLC = 8, message box 2 => receive & DLC = 8, message box 3 => transmit & DLC = 7, ..., message box 16 => receive & DLC = 1 etc.). My assumption is that the message will be received by the message box with the corresponding DLC if they all accept any ID, but perhaps this is a bad assumption? If this is not the case, will I need to check the register to see the DLC of the incoming frame?

On the TX side, I have the following function which accepts the data, ID, dlc, and then sends on message box that I have configured with the corresponding DLC.

static int csp_can_tx_frame(void * driver_data, uint32_t id, const uint8_t * data, uint8_t dlc)
{
    if (dlc > 8) {
        return CSP_ERR_INVAL;
    }
    id = id | 0b01100000000000000000000000000000; // set into extended transmission mode 

    canBASE_t *canREG = canREG1;

    switch (dlc) {
    case 8:
        canUpdateID(canREG, canMESSAGE_BOX1, id);
        canTransmit(canREG, canMESSAGE_BOX1, data);
        break;
    case 7:
        canUpdateID(canREG, canMESSAGE_BOX3, id);
        canTransmit(canREG, canMESSAGE_BOX3, data);
        break;
    case 6:
        canUpdateID(canREG, canMESSAGE_BOX5, id);
        canTransmit(canREG, canMESSAGE_BOX5, data);
        break;
    case 5:
        canUpdateID(canREG, canMESSAGE_BOX7, id);
        canTransmit(canREG, canMESSAGE_BOX7, data);
        break;
    case 4:
        canUpdateID(canREG, canMESSAGE_BOX9, id);
        canTransmit(canREG, canMESSAGE_BOX9, data);
        break;
    case 3:
        canUpdateID(canREG, canMESSAGE_BOX11, id);
        canTransmit(canREG, canMESSAGE_BOX11, data);
        break;
    case 2:
        canUpdateID(canREG, canMESSAGE_BOX13, id);
        canTransmit(canREG, canMESSAGE_BOX13, data);
        break;
    case 1:
        canUpdateID(canREG, canMESSAGE_BOX15, id);
        canTransmit(canREG, canMESSAGE_BOX15, data);
        break;
    }

    return CSP_ERR_NONE;
}

And then on the receiving end, which doesn't properly assign the correct message box on transmissions less than 8 bytes.

void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
    portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
    can_frame_t rxFrame;
    rxFrame.id = canGetID(node, messageBox);
    switch (messageBox) {
    case 2:
        rxFrame.dlc = 8;
        break;
    case 4:
        rxFrame.dlc = 7;
        break;
    case 6:
        rxFrame.dlc = 6;
        break;
    case 8:
        rxFrame.dlc = 5;
        break;
    case 10:
        rxFrame.dlc = 4;
        break;
    case 12:
        rxFrame.dlc = 3;
        break;
    case 14:
        rxFrame.dlc = 2;
        break;
    case 16:
        rxFrame.dlc = 1;
        break;
    }
    canGetData(node, messageBox, rxFrame.data);
    xQueueSendToBackFromISR(canData, &rxFrame, &xHigherPriorityTaskWoken);
    portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}



Note: the ID and data are correctly received, but the message box in the notification function does not correspond to the one that I would expect.

Am I incorrect in assuming that, having changed the IDs, the DLC's will be properly received and assigned to the corresponding message box? And if so, how can I make this work?