处理ARM芯片的保留寄存器位 [英] Dealing with reserved register bits of an ARM chip

查看:45
本文介绍了处理ARM芯片的保留寄存器位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ARM Cortex M3 的寄存器.在文档中,某些位可能是保留的".我不清楚在寄存器上写入时应该如何处理这些保留位.

I am working with the registers of an ARM Cortex M3. In the documentation, some of the bits may be "reserved". It is unclear to me how I should deal with these reserved bits when writing on the registers.

这些保留位甚至可写吗?我应该小心不要碰它们吗?如果我碰它们会发生什么不好的事情吗?

Are these reserved bits even writeable? Should I be cautious to not touch them? Will something bad happen if I touch them?

推荐答案

这是一个关于如何处理保留位的经典嵌入式世界问题!首先,您应该不要随意写入,以免您的代码变得不可移植.当架构将来为保留位分配新的含义时会发生什么?你的代码会崩溃.因此,处理具有保留位的寄存器时最好的口头禅是Read-Modify-Write.即读取寄存器内容,只修改您想要的位,然后写回值,以便保留位不变(不变,并不意味着我们不写入它们,但从某种意义上说,我们写了之前有的)

This is a classic embedded world problem as to what to do with reserved bits! First, you should NOT write randomly into it lest your code becomes un-portable. What happens when the architecture assigns a new meaning to the reserved bits in future? Your code will break. So the best mantra when dealing with registers having reserved bits is Read-Modify-Write. i.e read the register contents, modify only the bits you want and then write back the value so that reserved bits are untouched ( untouched, does not mean we dont write into them, but in the sense, that we wrote that which was there before )

例如,假设有一个寄存器,其中只有 LSBit 有意义,所有其他都保留.我会这样做

For example, say there is a register in which only the LSBit has meaning and all others are reserved. I would do this

ldr r0,=memoryAddress
ldr r1,[r0]
orr r1,r1,#1
str r1,[r0]

这篇关于处理ARM芯片的保留寄存器位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆