1. Need to access a volatile shared variable between main & interrupt. Trying to write code irrespective of 8,16 or 32 bit machine.
2. I have a code as below. But problem is even I have a lock varible i.e main_read, it is not atomic again.
For example, it will break into number of assembly instruction depending on 8,16 or 32.
Again if in between these instruction, interrupt comes, problem will arise.
3. Current I do like this:
2. I have a code as below. But problem is even I have a lock varible i.e main_read, it is not atomic again.
For example, it will break into number of assembly instruction depending on 8,16 or 32.
Again if in between these instruction, interrupt comes, problem will arise.
3. Current I do like this:
Code:
volatile uint8_t vol_var,vol_var_copy; /* took two variable & one as its copy */
void main_code(void)
{
main_read = 1;
data_read = vol_var;
main_read = 0;
if(1 == main_interrupted)
{
data_read = vol_var_copy;
main_interrupted = 0;
}
}
void isr(void)
{
if(0 == main_read)
{
vol_var = value;
}
else
{
main_interrupted = 1;
vol_var_copy = value;
}
}