Read Data From flash or RAM

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Read Data From flash or RAM

跳至解决方案
1,050 次查看
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 解答
905 次查看
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 回复
906 次查看
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 项奖励