Skip to content

Commit 5f1a0ff

Browse files
committed
[cru] Update serial number parsing
1 parent 2c8ca65 commit 5f1a0ff

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Cru/Constants.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ static constexpr Register ENDPOINT_ID(0x00000500);
112112
///////////////////////////////////////////////////////////////////////////////////////////////////
113113
/// Board serial number
114114
/// Must be accessed on BAR 2
115-
static constexpr Register SERIAL_NUMBER(0x20002c);
115+
static constexpr Register SERIAL_NUMBER_CTRL(0x00030804);
116+
static constexpr uint32_t SERIAL_NUMBER_TRG(0x2);
117+
static constexpr Register SERIAL_NUMBER(0x00030818);
116118

117119
/// Register containing compilation info of the firmware
118120
/// Can be used as a sort of version number

src/Cru/CruBar.cxx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,31 @@ int32_t CruBar::getLinksPerWrapper(int wrapper)
266266
boost::optional<int32_t> CruBar::getSerialNumber()
267267
{
268268
assertBarIndex(2, "Can only get serial number from BAR 2");
269-
Eeprom eeprom = Eeprom(mPdaBar);
270-
boost::optional<int32_t> serial = eeprom.getSerial();
271-
return serial;
269+
uint32_t serial = readRegister(Cru::Registers::SERIAL_NUMBER.index);
270+
if (serial == 0x0) { // Try to populate the serial register in case it's empty
271+
writeRegister(Cru::Registers::SERIAL_NUMBER_CTRL.index, Cru::Registers::SERIAL_NUMBER_TRG);
272+
serial = readRegister(Cru::Registers::SERIAL_NUMBER.index);
273+
}
274+
275+
if (serial == 0x0) { // Pre v3.6.3 scheme; we need to support it for now
276+
Eeprom eeprom = Eeprom(mPdaBar);
277+
boost::optional<int32_t> serial = eeprom.getSerial();
278+
return serial;
279+
} else { // v3.6.3+
280+
281+
std::string serialString;
282+
283+
for (int i = 0; i < 3; i++) { // The serial number consists of 3 digits
284+
serialString += char(serial & 0xff);
285+
serial = serial >> 8;
286+
}
287+
288+
try {
289+
return std::stol(serialString, NULL, 0);
290+
} catch (...) {
291+
return {};
292+
}
293+
}
272294
}
273295

274296
/// Get raw data from the temperature register

0 commit comments

Comments
 (0)