static const int REG_BLOCK_ADDR = 0x10000000;
static const int REGISTER_CTRL0_OFFSET = 384; // 32 bit reg offset !!!
static const int REGISTER_CTRL1_OFFSET = 385; // 32 bit reg offset !!!
static const int REGISTER_CTRL2_OFFSET = 386; // 32 bit reg offset !!!
static const int REGISTER_DATA0_OFFSET = 392; // 32 bit reg offset !!!
static const int REGISTER_DATA1_OFFSET = 393; // 32 bit reg offset !!!
static const int REGISTER_DATA2_OFFSET = 394; // 32 bit reg offset !!!
static const int REGISTER_DSET0_OFFSET = 396; // 32 bit reg offset !!!
static const int REGISTER_DSET1_OFFSET = 397; // 32 bit reg offset !!!
static const int REGISTER_DSET2_OFFSET = 398; // 32 bit reg offset !!!
static const int REGISTER_DCLR0_OFFSET = 400; // 32 bit reg offset !!!
static const int REGISTER_DCLR1_OFFSET = 401; // 32 bit reg offset !!!
static const int REGISTER_DCLR2_OFFSET = 402; // 32 bit reg offset !!!
and then
Gpio::baseAddress = (uint32_t *) mmap(0, 1024, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, memHandle,
Gpio::REG_BLOCK_ADDR);
and then
void Gpio::writeToRegister(uint16_t registerOffset, uint32_t value) {
*(Gpio::baseAddress + registerOffset) = value;}
you are basically mapping to a 32 bit pointer...
so your offsets are in fact equivalent to the following address:
REGISTER_CTRL0_OFFSET = 384 (32 bit offset) -> hex(4384) = 0x600
REGISTER_CTRL1_OFFSET = 385 (32 bit offset) -> hex(4385) = 0x604
REGISTER_CTRL2_OFFSET = 386 (32 bit offset) -> hex(4*386) = 0x608
So the documentation is correct...
Be careful with pointer arithmetic...