|
|
|
|
|
by emilfihlman
2391 days ago
|
|
>Also, while it's probably ok in this usage since it's a 32-bit cpu, it would be better to use atomic access intrinsics or a critical section and memory barriers rather than volatile to make the counter variable "ISR safe". The dislike for volatile coming from people in higher systems is pretty tiring and unwarranted. Volatile is a perfectly fine tool on low level mcus. |
|
It can be argued that the only kind of variable that can be shared safely between an ISR and the rest of the code is a volatile sig_atomic_t, but that is an argument from analogy and not from first principles, as the C abstract machine has no concept of ISR. The same goes for the argument that you should use atomic intrinsics, plausible, but still just an analogy.
(Just in case anyone was wondering if C as a language is close to the metal: no, it is not.)