Why is Read-Modify-Write necessary for registers on embedded systems?

后端 未结 5 1910
伪装坚强ぢ
伪装坚强ぢ 2021-02-07 20:17

I was reading http://embeddedgurus.com/embedded-bridge/2010/03/different-bit-types-in-different-registers/, which said:

With read/write bits, firmware se

5条回答
  •  孤街浪徒
    2021-02-07 20:54

    When I want to set/clear a bit, I always just or/nand with a bitmask.

    For some registers that's good enough. In such a case the CPU's firmware is still going to do a read-modify-write.

    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.

    If you let the CPU's firmware do the read-modify-write for you, obviously it's going to include at least a read cycle and a write cycle. Now, most CPUs won't interrupt this instruction in the middle, so your thread will execute this entire instruction before your thread's CPU checks for interrupts, but if you haven't locked the bus then other CPUs can modify the same register. Your thread and other threads can still walk all over each other.

提交回复
热议问题