-
The docs state the following:
I interpret this to mean that it isn't atomic as there is one read operation and one write operation. Side note, I apologize if this isn't the right repo for this question — it's not immediately clear to me what repos related to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Well, the answer is actually not that straight forward :)
Basically, this is correct. The calls to So the resulting update of the register is not atomic. If you need it to be, you have to wrap the But there is some more nuance. For certain kinds of |
Beta Was this translation helpful? Give feedback.
Well, the answer is actually not that straight forward :)
Basically, this is correct. The calls to
.modify()
get lowered into instructions to first read the register, modify the value, and then write it back. Similar to the instructions that the typical|=
or&=
statements in AVR C code generate.So the resulting update of the register is not atomic. If you need it to be, you have to wrap the
.modify()
call in a critical section usingavr_device::interrupt::free()
. Or in certain cases use.write()
instead which is atomic by writing a whole new value in a single instruction (but only for…