-
Notifications
You must be signed in to change notification settings - Fork 172
Description
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();