Hi everyone!
I am currently transporting the can_pal_S32K148 example to an FreeRTOS based project.
I created two different tasks, one for sending the other one for receiving
Sending in a separate Task is no problem.
But now i want to do some receiving.
Everything is fine as long as i use the Lines from the example project in my receive task:
/* Define receive buffer */
can_message_t recvMsg;
/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg);
/* Wait until the previous FlexCAN receive is completed */
while(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY);
/* Check the received message ID and payload */
if((recvMsg.data[0] == LED0_CHANGE_REQUESTED) &&
recvMsg.id == RX_MSG_ID)
{
/* Toggle output value LED0 */
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED0));
}
else if((recvMsg.data[0] == LED1_CHANGE_REQUESTED) &&
recvMsg.id == RX_MSG_ID)
{
/* Toggle output value LED1 */
PINS_DRV_TogglePins(GPIO_PORT, (1 << LED1));
}
If i send a data everything works without a problem.
But with this option I have the whole Idle time inside the while loop waiting for the state to get "unbusy", which I don't want to have.
So i tried to change it to something like this:
/* Start receiving data in RX_MAILBOX. */
CAN_Receive(&can_pal1_instance, RX_MAILBOX, &recvMsg);
/* Wait until the previous FlexCAN receive is completed */
if(CAN_GetTransferStatus(&can_pal1_instance, RX_MAILBOX) == STATUS_BUSY)
{
return;
}
Because if i call this cyclic it should be the same like with the while, right?
Which works fine, if i send CAN Message with the wrong IDs.
But as soon as I send the CAN Message with the wright ID, for example 2 as done in the can_pal_S32K148 example, the whole system stops and I end up being stuck in the FreeRtos Watchdog.
I decreased the calling cycle to 1ms, which is the fastes cycle I can adjust at the FreeRTOS.
Is there any way to avoid this kind of error?
Or do I have to extract the CAN_GetTransferStatus function to some kind of IRQ and communicate with a flag that the can is not longer busy?
Best regards
Christof