If a program needs access to variables which are used/changed by an interrupt routine they have to be declared volatile.
That's clear so far, but what is the best method then to access such variables?
There are examples of code which use ATOMIC_BLOCK to copy the variable, here value, and then use value_copy outside the interrupt:
Other ones use cli() and sei():
cli() and sei() are disabling/enabling all interrupts.
What happens with ATOMIC_BLOCK(ATOMIC_RESTORESTATE)?
That's clear so far, but what is the best method then to access such variables?
There are examples of code which use ATOMIC_BLOCK to copy the variable, here value, and then use value_copy outside the interrupt:
Code:
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
value_copy = value;
}
Code:
cli();
value_copy = value;
sei();
cli() and sei() are disabling/enabling all interrupts.
What happens with ATOMIC_BLOCK(ATOMIC_RESTORESTATE)?