关于write-only register的处理
Programming Embedded Systems with C and GNU Development Tools
7.1.1.7. Bitfields有以下叙述
Unique Registers
Some registers (or bits within a register) can be read-only or write-only. For write-only registers, read-modify-write operations (such as |=, &=, and ^=) cannot be used. In this case, a shadow copy of the register's contents should be held in a variable in RAM to maintain the current state of the write-only register. An example of a write-only register using a shadow copy timerRegValue follows:
/* Initialize timer write-only register. */ timerRegValue = TIMER_INTERRUPT; *pTimerReg = timerRegValue;
After the shadow copy and timer register have been initialized, subsequent writes to the register are performed by first modifying the shadow copy timerRegValue and then writing the new value to the register. For example:
timerRegValue |= TIMER_ENABLE; *pTimerReg = timerRegVal
其实是我自己开始的时候没有读懂:*pTimerReg 才是指向write-only register的指针,timerRegValue才是一个shadow copy