Read Data From flash or RAM

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

Read Data From flash or RAM

ソリューションへジャンプ
1,030件の閲覧回数
harshitha_chiga
Contributor II

I am using a define to read data from and write to flash or ram. 

#define REG_READ(address)             ((uint8_t)(*(vuint8_t *)(address)))

#define REG_WRITE(address, value)             (*(vuint8_t *)(address) = (value))

But I'm unable to understand ((uint8_t)(*(vuint8_t *)(address)))  and (*(vuint8_t *)(address) = (value)) this.

Could you please help me out on this? How it is typecasted and what this typecasting actually means.

Thanks in advance!!

Harshitha C B

0 件の賞賛
1 解決策
885件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Welcome to the C programming language :-)

#define REG_READ(address)             ((uint8_t)(*(vuint8_t *)(address)))

you can use it as this:

uint8_t val = REG_READ(0x1000);

The macro takes the address (0x1000 in this case) and casts it to a pointer to volatile unsigned 8bit int ((vuint8_t*).

Then it dereferenciates the pointer (* operator) and casts the result to an unsigned 8bit int (uint8_t).

Finally, it assigns it to the variable val.

The WRITE macro is doing the same thing, must with assigning the value to that constant pointer cast.

You might see other examples of this in “Volatile” can be harmful… | MCU on Eclipse 

I hope this helps,

Erich

元の投稿で解決策を見る

0 件の賞賛
1 返信
886件の閲覧回数
BlackNight
NXP Employee
NXP Employee

Welcome to the C programming language :-)

#define REG_READ(address)             ((uint8_t)(*(vuint8_t *)(address)))

you can use it as this:

uint8_t val = REG_READ(0x1000);

The macro takes the address (0x1000 in this case) and casts it to a pointer to volatile unsigned 8bit int ((vuint8_t*).

Then it dereferenciates the pointer (* operator) and casts the result to an unsigned 8bit int (uint8_t).

Finally, it assigns it to the variable val.

The WRITE macro is doing the same thing, must with assigning the value to that constant pointer cast.

You might see other examples of this in “Volatile” can be harmful… | MCU on Eclipse 

I hope this helps,

Erich

0 件の賞賛