I'm a beginner in c language.
I have a function which writes some specific value into a register:
if(something == someCondition )
{
Write_into_register( Msg->R_addres, Msg->value );
}
This works so far. I have also a read function, which just reads the value which is written into the register:
uint read_value_from_register( R_addres addr ){}
This works also fine.
Now I would like to have something like this:
- Each time the value is written to register, check if it is really the correct value written into register (with my read function)
- If the value is not written or it is not the same value, try 3 times to write the correct value
- If the 3rd attempt is not successful, raise an error
How to represent this algorithm and combine it with my existing functions? Can you represent it just as pseudo-code? Will be thankful!
Have tried something like this:
int index;
Write_into_register(addres, value );
for (index=0;index<3;i++)
if (value== read_value_from_register(addres))
return 1;
else
return ERROR;