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.

CC2674R10: CAN_open() ignores params->userArg

Part Number: CC2674R10

Tool/software:

Hi all,

using simplelink_cc13xx_cc26xx_sdk_7_40_00_77 CAN driver for TCAN455X via SPI

CAN_open() is passed a CAN_Params struct:

typedef struct
{
    const CAN_MsgRAMConfig *msgRAMConfig;  /*!< Pointer to message RAM configuration */
    const CAN_BitRateTimingRaw *bitTiming; /*!< Pointer to raw bit timing values */
    CAN_EventCbk eventCbk;                 /*!< Pointer to event callback function */
    uint32_t eventMask;                    /*!< Mask of events to call event callback function for */
    void *userArg;                         /*!< User supplied arg for callback */
} CAN_Params;

Observation: the provided 'eventCbk' function get called as configured, but its 'userArg' parameter is always NULL, that is, params->userArg passed to CAN_open() does not get passed on to the callback as expected:

 *  @param[in]  userArg       A user supplied argument specified
 *                            in CAN_Params.
 */
typedef void (*CAN_EventCbk)(CAN_Handle handle, uint32_t event, uint32_t data, void *userArg);

CAN_open() does not transfer member 'userArg' to the CAN_Object - here's the code snippet out of CAN_open() in source/TI/drivers/CAN.c where one would expect his to happen:

'params' is also passed to CAN_initDevice() in source/TI/drivers/can/TCAN455X.c, but struct member 'userArg' is ignored there as well.

 

Is this a known limitation that will be fixed soon? I wanted to use 'userArg' and now have to resort to a global variable to work around this.

Regards,

Wolfgang

  • Hi Wolfgang,

    I see what you're saying. To me also it seems the CAN_Params.userArg is not actually referenced.

    A workaround could be:

        /* Open CAN driver with default configuration */
        CAN_Params_init(&canParams);
        canParams.eventCbk  = eventCallback;
        canParams.eventMask = CAN_EVENT_MASK;
        canParams.userArg   = (void *) yourArg; // toby added
    
        canHandle = CAN_open(CONFIG_CAN_0, &canParams);
        if (canHandle == NULL)
        {
            /* CAN_open() failed */
            while (1) {}
        }
    
        // toby added
        canHandle->object->userArg = canParams.userArg;
        // end added

    I'll check with the driver team if this is a known issue, though I suspect it should be.

    Thanks,
    Toby

  • A ticket is now filed to address this issue.

    Thanks for reporting it!

    I cannot provide an exact timeline for it, but my initial estimate would be end of Q3 or Q4.

  • Hi Toby,

    I also came up with this workaround, but it should be noted that it bears the (very small) risk of still getting userArg==NULL in early callbacks during initialization, depending on event mask and bus traffic. So userArg should be checked in the callback and not blindly dereferenced (good practice anyway).