#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define __SFR_OFFSET 0
#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(&buffer[0] + mem_addr))
#define _SFR_IO8(io_addr) _MMIO_BYTE((io_addr) + __SFR_OFFSET)
#define DDRD _SFR_IO8(0x0A)
uint8_t buffer[256];
int main(void) {
DDRD = 0x40;
printf("value: %x\n", (int)DDRD
); *(volatile uint8_t*)(&buffer[0] + (0x0A + 0)) = 0x41;
printf("value: %x\n", (int)DDRD
);
// now let's do what you are doing in your struct
unsigned int dataDirectionRegister = DDRD; // value of register is copied into variable
dataDirectionRegister = 0x80; // variable is changed but not real register
printf("register: %x, variable: %x\n", (int)DDRD
, dataDirectionRegister
);
// you must save an address to do what you need
volatile uint8_t* realDataDirectionRegister = &DDRD;
*realDataDirectionRegister = 0x80;
printf("register: %x, variable: %x\n", (int)DDRD
, (int)*realDataDirectionRegister
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRpbnQuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKI2RlZmluZSBfX1NGUl9PRkZTRVQgMAojZGVmaW5lIF9NTUlPX0JZVEUobWVtX2FkZHIpICgqKHZvbGF0aWxlIHVpbnQ4X3QgKikoJmJ1ZmZlclswXSArIG1lbV9hZGRyKSkKI2RlZmluZSBfU0ZSX0lPOChpb19hZGRyKSBfTU1JT19CWVRFKChpb19hZGRyKSArIF9fU0ZSX09GRlNFVCkKI2RlZmluZSBERFJEIF9TRlJfSU84KDB4MEEpIAoKdWludDhfdCBidWZmZXJbMjU2XTsKCmludCBtYWluKHZvaWQpIHsKCW1lbXNldCgmYnVmZmVyWzBdLCAwLCAyNTYpOwoJRERSRCA9IDB4NDA7CglwcmludGYoInZhbHVlOiAleFxuIiwgKGludClERFJEKTsKCSoodm9sYXRpbGUgdWludDhfdCopKCZidWZmZXJbMF0gKyAoMHgwQSArIDApKSA9IDB4NDE7CglwcmludGYoInZhbHVlOiA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