Why is Read-Modify-Write necessary for registers on embedded systems?
Posted
by Adam Shiemke
on Stack Overflow
See other posts from Stack Overflow
or by Adam Shiemke
Published on 2010-03-31T01:55:48Z
Indexed on
2010/03/31
2:03 UTC
Read the original article
Hit count: 320
I was reading http://embeddedgurus.com/embedded-bridge/2010/03/different-bit-types-in-different-registers/, which said:
With read/write bits, firmware sets and clears bits when needed. It typically first reads the register, modifies the desired bit, then writes the modified value back out
and I have run into that consrtuct while maintaining some production code coded by old salt embedded guys here. I don't understand why this is necessary.
When I want to set/clear a bit, I always just or/nand with a bitmask. To my mind, this solves any threadsafe problems, since I assume setting (either by assignment or oring with a mask) a register only takes one cycle. On the other hand, if you first read the register, then modify, then write, an interrupt happening between the read and write may result in writing an old value to the register.
So why read-modify-write? Is it still necessary?
© Stack Overflow or respective owner