Anyone can explain in details what the following macro does?
#define write_XDATA(address,value) (((char *)0x010000) [address]=value)
thx!
Anyone can explain in details what the following macro does?
#define write_XDATA(address,value) (((char *)0x010000) [address]=value)
thx!
It assigns value
to the byte at memory location 0x10000 + address
. It's easier to grok if you separate it out a bit:
char* buf = (char *)0x010000;
buf[address]=value;
(Though of course you have no choice but to mash it all together in a macro.)
It maps addresses to real addresses using an offset and then writes to it. XDATA is probably a term taken over from the 8051-processor.
You use it:
write_XDATA( Address, Value );
and it is expanded:
((char*)0x010000)[Address]=Value;
which is equivalent to the following:
char* baseAddress = (char*)0x010000;
*(baseAddress + Address) = Value;
so basically it writes a byte stored in Value
at the address 0x010000 + Address
.
I don't know how much details you want to hear, but the macro expands itself to what you have just written -
macro parameters address and value are put into address and value placeholders in the macro expansion definition (((char *)0x010000) [address]=value)
That's most probably part of a program designed to run on an embedded platform. It's used to do memory mapped IO.
The base address of the register-map is 0x010000. It writes value
to the memory location 0x010000+address
.
The use of the square brackets []
works because of the equivalence of array-addressing and pointer arithmetic in C.