本文介绍了与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?

推荐答案

这是一个典型的嵌入式世界中的问题,以什么用预留位做!首先,你应该不会随机写进去,免得你的code变得无法移植。当结构分配一个新的含义在未来保留位会发生什么?您code将打破。因此,有保留与寄存器打交道时最好的口头禅位的读 - 修改 - 写。即读寄存器的内容,只修改你想要位,然后写回值,以便预留位不变(不变,并不意味着我们不写放进去,但在这个意义上,我们写道,这是有前)

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 )

举例来说,说有其中仅拥有,所以LSb意义和所有其他被保留的寄存器。我会做这个

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芯片保留寄存器位处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 08:13