Hello,
I have to write a piece of code for the following situation: there are 2 microcontrollers (a failsafe uC and a main uC) and they comunicate through SPI; the main uC receives at every 20ms frames on CAN; the main uC must send to the failsafe uC the intact frame received on CAN, while it (main uC) is in HP. The used programming language is C. Question: how could I do that, in embedded C? All I need is an algorithm.
I came out with an algorithm, but I do not know if it's ok, so I need the opinion of someone that has experience:
boolean flag1;// flag to be set to 1 if frame is received on CAN
if (HP) // if in HP - could while(HP) be used?
{
if(flag1) //if a frame is received
{
send_failsafe(can_frame); //send the frame to second uC
flag1=0; //reset the flag
}
else
{
// do nothing; wait for the next frame
}
} //this piece of code is executed every 10ms, and the frames are received every //20ms, so that's why the flag must be reseted, so that the same frame is not to be //sent twice
So, what do you think? any suggestions?
Thank you for support!