LPCOpen : Why we use '~' in the Reseved bits masks for registers ?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

LPCOpen : Why we use '~' in the Reseved bits masks for registers ?

1,127件の閲覧回数
karthikvenkates
Contributor II

Hi,

Below is the snapshot from "syscon_8xx.h" file of lpcopen library. If you see, everywhere they have used '~'.

pastedImage_1.png

For example, take SYSAHBCLKDIV register in LPC812.

pastedImage_2.png

Here Bits <31:8> are reserved bits. We could have defined

#define SYSCTL_SYSAHBCLKDIV_RESERVED    (0xffffff)

But why did LPCOpen use      #define SYSCTL_SYSAHBCLKDIV_RESERVED    (~0xff)       instead ?

ラベル(4)
0 件の賞賛
返信
1 返信

760件の閲覧回数
BlackNight
NXP Employee
NXP Employee

The '~' operator is a 'binary-negate' operator in C. The reserved bitmask would be 0xFFFFFF00 (and not 0xFFFFFF as you wrote). And ~0xFF will be exactly that 0xFFFFFF00. You could use both notations. I would prefer 0xFFFFFF00 too, but ~0xFF is shorter :-).

I hope this helps,

Erich

0 件の賞賛
返信