I'm trying to improve my coding practice for embedded. The code below writes the value 0 to the memory location 0x80001000.
#define MemoryWrite(A,V) *(volatile unsigned long*)(A)=(V)
#define FLAG 2147487744 //0x80001000
uint32_t reset_value = 0;
int main(void)
{
MemoryWrite(FLAG, reset_value);
return 0;
}
I have two questions:
In order to use the
MemoryWritemacro I had to convert0x80001000to2147487744. I think this makes the code unclear. Is there a way that I could do this just using the hex value?I defined
reset_valueas auint32_t. What would it change if I used#defineinstead ?
MemoryWriteexpects anunsigned long, not auint32_t. I don't know which of the two is correct, I have no idea what your embedded system has at offset0x800010002147487744instead of0x80001000. Why? What happened when you used0x80001000?