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

前端 未结 4 1173
半阙折子戏
半阙折子戏 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-14 03:04

    Generally, the ldrex and strex need support from the memory systems. You may wish to refer to some answers by dwelch as well as his extext application. I would believe that you can not do this for memory mapped I/O. ldrex and strex are intended more for Lock Free algorithms, in normal memory.

    Generally only one driver should be in charge of a bank of I/O registers. Software will make requests to that driver via semaphores, etc which can be implement with ldrex and strex in normal SDRAM. So, you can inter-lock these I/O registers, but not in the direct sense.

    Often, the I/O registers will support atomic access through write one to clear, multiplexed access and other schemes.

    1. Write one to clear - typically use with hardware events. If code handles the event, then it writes only that bit. In this way, multiple routines can handle different bits in the same register.
    2. Multiplexed access - often an interrupt enable/disable will have a register bitmap. However, there are also alternate register that you can write the interrupt number to which enable or disable a particular register. For instance, intmask maybe two 32 bit registers. To enable int3, you could mask 1<<3 to the intmask or write only 3 to an intenable register. They intmask and intenable are hooked to the same bits via hardware.

    So, you can emulate an inter-lock with a driver or the hardware itself may support atomic operations through normal register writes. These schemes have served systems well for quiet some time before people even started to talk about lock free and wait free algorithms.

提交回复
热议问题