Read Data From flash or RAM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read Data From flash or RAM

Jump to solution
1,019 Views
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 Kudos
1 Solution
874 Views
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

View solution in original post

0 Kudos
1 Reply
875 Views
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 Kudos