DECLARING OBJECTS VOLATILE
There are three main reasons for declaring an object volatile:
● Shared access; the object is shared between several tasks in a multitasking
environment
● Trigger access; as for a memory-mapped SFR where the fact that an access occurs
has an effect
● Modified access; where the contents of the object can change in ways not known to
the compiler.
Definition of access to volatile objects
The ISO/ANSI standard defines an abstract machine, which governs the behavior of
accesses to volatile declared objects. The AVR IAR C/C++ Compiler considers each
read and write access to an object that has been declared volatile as an access. The
unit for the access is either the entire object or, for accesses to an element in a composite
object—such as an array, struct, class, or union—the element. For example:
Код
char volatile a;
a = 5; /* A write access */
a += 6; /* First a read then a write access */
An access to a bitfield is treated as an access to the underlaying type.
Rules for accesses
Accesses to volatile declared objects are subject to the following rules:
1 All accesses are preserved
2 All accesses are complete, that is, the whole object is accessed
3 All accesses are performed in the same order as given in the abstract machine
4 All accesses are atomic, that is, non-interruptable.
The AVR IAR C/C++ Compiler adheres to these rules for all 8-bit types.
The following object types are treated in a special way:
For all combinations of object types not listed, only rule number one applies.
обясните , пожалуйста, толково как этим и где пользоваться и какой смысл такого обяв.. в даном примере