Skip to content

Race Condition in CAN_DataSend #76

@annego15

Description

@annego15

Hi foxBMS team. I experienced issues with CAN messages with wrong data being sent. Every few minutes a message with senseless data is sent on valid CAN IDs.

The issue seems to come from the function CAN_DataSend (in the file src/app/driver/can/can.c) being called from multiple tasks, but this function is not threadsafe, leading to a race condition and corrupted data.
For example if a fatal error is detected the function CANTX_SendMessageFatalErrorCode is called which calls CAN_DataSend from a high priority task. However, it can happen that the periodic CAN send task was running and in the middle of executing CAN_DataSend. In this case two CAN messages are sent in the same mailbox and depending on when exactly the the lower priority task was preempted data is sent on a wrong ID or the data is completely messed.

I was able to fix the issue by wrapping the for loop in CAN_DataSend with OS_EnterTaskCritical(); and OS_ExitTaskCritical();

Metadata

Metadata

Assignees

No one assigned

    Labels

    CANRelated to the CAN, either on the embedded platform of the fox CLIembeddedRelated to the embedded softwarefix-available

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions