diff --git a/ion/src/device/n0100/drivers/board.cpp b/ion/src/device/n0100/drivers/board.cpp index 9e0574d98..921d872dc 100644 --- a/ion/src/device/n0100/drivers/board.cpp +++ b/ion/src/device/n0100/drivers/board.cpp @@ -230,6 +230,12 @@ void shutdownClocks(bool keepLEDAwake) { RCC.AHB1ENR()->set(ahb1enr); } +PCBVersion readPCBVersion() { + return PCB_LATEST; +} + +void writePCBVersion(PCBVersion) {} + } } } diff --git a/ion/src/device/n0110/drivers/board.cpp b/ion/src/device/n0110/drivers/board.cpp index 55fe11131..4bf47f820 100644 --- a/ion/src/device/n0110/drivers/board.cpp +++ b/ion/src/device/n0110/drivers/board.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -370,6 +372,25 @@ void shutdownClocks(bool keepLEDAwake) { RCC.AHB1ENR()->set(ahb1enr); } +constexpr int pcbVersionOTPIndex = 0; + +/* As we want the PCB versions to be in ascending order chronologically, and + * because the OTP are initialized with 1s, we store the bitwise-not of the + * version number. This way, devices with blank OTP are considered version 0. */ + +PCBVersion readPCBVersion() { + /* FIXME: When flashing for the first time after assembling the device, this + * should return PCB_LATEST. */ + return ~*reinterpret_cast(InternalFlash::Config::OTPAddresses[pcbVersionOTPIndex]); +} + +void writePCBVersion(PCBVersion version) { + /* TODO: We also need to lock the OTP in which the version has been written. */ + uint8_t * destination = reinterpret_cast(InternalFlash::Config::OTPAddresses[pcbVersionOTPIndex]); + PCBVersion formattedVersion = ~version; + InternalFlash::WriteMemory(destination, reinterpret_cast(&formattedVersion), sizeof(formattedVersion)); +} + } } } diff --git a/ion/src/device/shared/drivers/board.h b/ion/src/device/shared/drivers/board.h index a643c35b7..9c3370a84 100644 --- a/ion/src/device/shared/drivers/board.h +++ b/ion/src/device/shared/drivers/board.h @@ -1,6 +1,8 @@ #ifndef ION_DEVICE_SHARED_DRIVERS_BOARD_H #define ION_DEVICE_SHARED_DRIVERS_BOARD_H +#include + namespace Ion { namespace Device { namespace Board { @@ -23,6 +25,11 @@ Frequency standardFrequency(); void setStandardFrequency(Frequency f); void setClockFrequency(Frequency f); +typedef uint32_t PCBVersion; + +PCBVersion readPCBVersion(); +void writePCBVersion(PCBVersion version); + } } }