[ion/device/n0110] Methods to read and write PCB version in OTP

This commit is contained in:
Gabriel Ozouf
2021-03-12 13:59:42 +01:00
committed by Gabriel
parent 524a7d9619
commit c4ef2016ba
3 changed files with 34 additions and 0 deletions

View File

@@ -230,6 +230,12 @@ void shutdownClocks(bool keepLEDAwake) {
RCC.AHB1ENR()->set(ahb1enr);
}
PCBVersion readPCBVersion() {
return PCB_LATEST;
}
void writePCBVersion(PCBVersion) {}
}
}
}

View File

@@ -1,6 +1,8 @@
#include <drivers/board.h>
#include <drivers/cache.h>
#include <drivers/internal_flash.h>
#include <drivers/config/clocks.h>
#include <drivers/config/internal_flash.h>
#include <drivers/external_flash.h>
#include <regs/regs.h>
#include <ion.h>
@@ -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<const PCBVersion *>(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<uint8_t *>(InternalFlash::Config::OTPAddresses[pcbVersionOTPIndex]);
PCBVersion formattedVersion = ~version;
InternalFlash::WriteMemory(destination, reinterpret_cast<uint8_t *>(&formattedVersion), sizeof(formattedVersion));
}
}
}
}

View File

@@ -1,6 +1,8 @@
#ifndef ION_DEVICE_SHARED_DRIVERS_BOARD_H
#define ION_DEVICE_SHARED_DRIVERS_BOARD_H
#include <stdint.h>
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);
}
}
}