关于write-only register

关于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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值