Пусть будет встроенная система такая, что:
Он имеет датчик температуры, расположенный по адресу 0x8000000, что обеспечивает 32-битное значение только для чтения.
Как лучше всего записать буквальный адрес для этого датчика? >
Это:
Код: Выделить всё
volatile const uint32_t *const temperature_sensor = reinterpret_cast (0x80000000);
// volatile .. because the value that of at this address could change every time this address is read from (tells the compiler to read every single time. No clever optimizations).
// const ... because it is readonly, it is a sensor, writing to it doesn't do anything bad (no magic smoke) but is most likely a programming error. Save some headaches troubleshooting, attempts to write to it should throw a compilation error.
// *const because it is a constant pointer, attempts to change what memory address this points to should throw a compilation error.
...
uint32_t current_temperature = *temperature_sensor; // Reading from the temperature_sensor.
Разговор:
Есть ли лучший способ?
Подробнее здесь: https://stackoverflow.com/questions/786 ... eripherals
Мобильная версия