28 lines
763 B
C++
28 lines
763 B
C++
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
#define PACKED(x, s) \
|
|
union { \
|
|
s value; \
|
|
x __attribute__((packed, aligned(sizeof(s)))) fields; \
|
|
} __attribute__((packed, aligned(sizeof(s))))
|
|
|
|
typedef PACKED(struct {
|
|
uint16_t PartNumber : 16;
|
|
uint16_t _reserved: 16;
|
|
}, uint32_t) VITAL_PRODUCT_DATA;
|
|
|
|
static volatile uint32_t v = 0x0000ae21;
|
|
static volatile uint32_t* vpd = &v;
|
|
|
|
template<typename T> volatile T* mapType() {
|
|
return reinterpret_cast<volatile T*>(vpd);
|
|
}
|
|
|
|
int main(){
|
|
auto tt = mapType<VITAL_PRODUCT_DATA>();
|
|
uint16_t t = tt->fields.PartNumber;
|
|
|
|
printf("%d\n", tt->value);
|
|
printf("%d\n", t);
|
|
} |