Atomic operations in ARM strex and ldrex - can they work on I/O registers?

前端 未结 4 1171
半阙折子戏
半阙折子戏 2021-01-14 02:17

Suppose I\'m modifying a few bits in a memory-mapped I/O register, and it\'s possible that another process or and ISR could be modifying other bits in the same register.

4条回答
  •  不知归路
    2021-01-14 02:52

    If the chip in question has a toggle register (which is essentially XORed with the output latch when written to) there is a work around.

    • load port latch
    • mask off unrelated bits
    • xor with desired output
    • write to toggle register

    as long as two processes do not modify the same pins (as opposed to "the same port") there is no race condition.

    In the case of the bcm2708 you could choose an output pin whose neighbors are either unused or are never changed and write to GPFSELn in byte mode. This will however only ensure that you will not corrupt others. If others are writing in 32 bit mode and you interrupt them they will still corrupt you. So its kind of a hack.

    Hope this helps

提交回复
热议问题