Skip to content

Commit 24db90b

Browse files
committed
[roc] Consistent S/N parsing between CRU and CRORC
1 parent 1d8595f commit 24db90b

File tree

8 files changed

+81
-32
lines changed

8 files changed

+81
-32
lines changed

src/CommandLineUtilities/ProgramListCards.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ class ProgramListCards : public Program
8787
}
8888
}
8989

90-
std::string serial = std::to_string(card.serialId.getSerial());
90+
// Pad the serial with 0s if necessary
91+
// It should always be used as 3 chars to avoid conflicts with the sequence id
92+
boost::format serialFormat("%03d");
93+
serialFormat % std::to_string(card.serialId.getSerial());
94+
95+
std::string serial = serialFormat.str();
9196
std::string endpoint = std::to_string(card.serialId.getEndpoint());
9297

9398
if (!mOptions.jsonOut) {

src/Crorc/Constants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,12 @@ static constexpr uint32_t DTSW(0x00000082);
412412

413413
// Register to configure the Data Generator
414414
static constexpr Register DATA_GENERATOR_CFG(0x00000020);
415+
416+
// Registers used to read the Serial Number
417+
static constexpr Register SERIAL_NUMBER_CTRL(0x000000F0);
418+
static constexpr uint32_t SERIAL_NUMBER_TRG(0xC0000000);
419+
static constexpr Register SERIAL_NUMBER(0x000000FC);
420+
415421
} // namespace Registers
416422
} //namespace Crorc
417423

src/Crorc/CrorcBar.cxx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
#include "boost/format.hpp"
2828

29+
using namespace std::literals;
30+
2931
namespace AliceO2
3032
{
3133
namespace roc
@@ -40,6 +42,11 @@ CrorcBar::CrorcBar(const Parameters& parameters, std::unique_ptr<RocPciDevice> r
4042
{
4143
}
4244

45+
CrorcBar::CrorcBar(std::shared_ptr<Pda::PdaBar> bar)
46+
: BarInterfaceBase(bar)
47+
{
48+
}
49+
4350
CrorcBar::~CrorcBar()
4451
{
4552
}
@@ -52,14 +59,43 @@ boost::optional<std::string> CrorcBar::getFirmwareInfo()
5259

5360
boost::optional<int32_t> CrorcBar::getSerial()
5461
{
55-
return Crorc::getSerial(*(mPdaBar.get()));
62+
return getSerialNumber();
5663
}
5764

5865
void CrorcBar::setSerial(int serial)
5966
{
6067
Crorc::setSerial(*(mPdaBar.get()), serial);
6168
}
6269

70+
boost::optional<int32_t> CrorcBar::getSerialNumber()
71+
{
72+
// mPdaBar->assertBarIndex(0, "Can only get serial from Bar 0");
73+
uint32_t serial = readRegister(Crorc::Registers::SERIAL_NUMBER.index);
74+
if (serial == 0x0 || true) {
75+
writeRegister(Crorc::Registers::SERIAL_NUMBER_CTRL.index, Crorc::Registers::SERIAL_NUMBER_TRG);
76+
std::this_thread::sleep_for(500ms);
77+
serial = readRegister(Crorc::Registers::SERIAL_NUMBER.index);
78+
}
79+
80+
if (serial == 0x0) { // Previous S/N scheme
81+
return Crorc::getSerial(*(mPdaBar.get()));
82+
} else {
83+
// Register format e.g. 0x32343932
84+
// transltes to -> 2942 -> 942 (keep 3)
85+
std::stringstream serialString;
86+
87+
serialString << char(serial & 0xff)
88+
<< char((serial & 0xff00) >> 8)
89+
<< char((serial & 0xff0000) >> 16);
90+
91+
try {
92+
return std::stoi(serialString.str());
93+
} catch (...) {
94+
return {};
95+
}
96+
}
97+
}
98+
6399
int CrorcBar::getEndpointNumber()
64100
{
65101
return 0;

src/Crorc/CrorcBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class CrorcBar final : public BarInterfaceBase
3131
{
3232
public:
3333
CrorcBar(const Parameters& parameters, std::unique_ptr<RocPciDevice> rocPciDevice);
34+
CrorcBar(std::shared_ptr<Pda::PdaBar> bar);
3435
virtual ~CrorcBar();
3536
//virtual void checkReadSafe(int index) override;
3637
//virtual void checkWriteSafe(int index, uint32_t value) override;
@@ -44,6 +45,7 @@ class CrorcBar final : public BarInterfaceBase
4445
virtual boost::optional<std::string> getFirmwareInfo() override;
4546
virtual int getEndpointNumber() override;
4647

48+
boost::optional<int32_t> getSerialNumber();
4749
void setSerial(int serial);
4850

4951
void configure(bool force = false) override;

src/Cru/CruBar.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ int32_t CruBar::getLinksPerWrapper(int wrapper)
267267
/// calling this function, or the card may crash. See parseFirmwareFeatures().
268268
boost::optional<int32_t> CruBar::getSerialNumber()
269269
{
270-
assertBarIndex(2, "Can only get serial number from BAR 2");
270+
mPdaBar->assertBarIndex(2, "Can only get serial number from BAR 2");
271271
uint32_t serial = readRegister(Cru::Registers::SERIAL_NUMBER.index);
272272
if (serial == 0x0) { // Try to populate the serial register in case it's empty
273273
writeRegister(Cru::Registers::SERIAL_NUMBER_CTRL.index, Cru::Registers::SERIAL_NUMBER_TRG);
@@ -280,16 +280,16 @@ boost::optional<int32_t> CruBar::getSerialNumber()
280280
boost::optional<int32_t> serial = eeprom.getSerial();
281281
return serial;
282282
} else { // v3.6.3+
283+
// Register format e.g. 0x343230
284+
// translates to -> 024
285+
std::stringstream serialString;
283286

284-
std::string serialString;
285-
286-
for (int i = 0; i < 3; i++) { // The serial number consists of 3 digits
287-
serialString += char(serial & 0xff);
288-
serial = serial >> 8;
289-
}
287+
serialString << char(serial & 0xff)
288+
<< char((serial & 0xff00) >> 8)
289+
<< char((serial & 0xff0000) >> 16);
290290

291291
try {
292-
return std::stol(serialString, NULL, 0);
292+
return std::stoi(serialString.str());
293293
} catch (...) {
294294
return {};
295295
}
@@ -299,7 +299,7 @@ boost::optional<int32_t> CruBar::getSerialNumber()
299299
/// Get raw data from the temperature register
300300
uint32_t CruBar::getTemperatureRaw()
301301
{
302-
assertBarIndex(2, "Can only get temperature from BAR 2");
302+
mPdaBar->assertBarIndex(2, "Can only get temperature from BAR 2");
303303
// Only use lower 10 bits
304304
return readRegister(Cru::Registers::TEMPERATURE.index) & 0x3ff;
305305
}
@@ -332,55 +332,55 @@ boost::optional<float> CruBar::getTemperatureCelsius()
332332

333333
uint32_t CruBar::getFirmwareCompileInfo()
334334
{
335-
assertBarIndex(0, "Can only get firmware compile info from BAR 0");
335+
mPdaBar->assertBarIndex(0, "Can only get firmware compile info from BAR 0");
336336
return readRegister(Cru::Registers::FIRMWARE_COMPILE_INFO.index);
337337
}
338338

339339
uint32_t CruBar::getFirmwareGitHash()
340340
{
341-
assertBarIndex(2, "Can only get git hash from BAR 2");
341+
mPdaBar->assertBarIndex(2, "Can only get git hash from BAR 2");
342342
return readRegister(Cru::Registers::FIRMWARE_GIT_HASH.index);
343343
}
344344

345345
uint32_t CruBar::getFirmwareDateEpoch()
346346
{
347-
assertBarIndex(2, "Can only get firmware epoch from BAR 2");
347+
mPdaBar->assertBarIndex(2, "Can only get firmware epoch from BAR 2");
348348
return readRegister(Cru::Registers::FIRMWARE_EPOCH.index);
349349
}
350350

351351
uint32_t CruBar::getFirmwareDate()
352352
{
353-
assertBarIndex(2, "Can only get firmware date from BAR 2");
353+
mPdaBar->assertBarIndex(2, "Can only get firmware date from BAR 2");
354354
return readRegister(Cru::Registers::FIRMWARE_DATE.index);
355355
}
356356

357357
uint32_t CruBar::getFirmwareTime()
358358
{
359-
assertBarIndex(2, "Can only get firmware time from BAR 2");
359+
mPdaBar->assertBarIndex(2, "Can only get firmware time from BAR 2");
360360
return readRegister(Cru::Registers::FIRMWARE_TIME.index);
361361
}
362362

363363
uint32_t CruBar::getFpgaChipHigh()
364364
{
365-
assertBarIndex(2, "Can only get FPGA chip ID from BAR 2");
365+
mPdaBar->assertBarIndex(2, "Can only get FPGA chip ID from BAR 2");
366366
return readRegister(Cru::Registers::FPGA_CHIP_HIGH.index);
367367
}
368368

369369
uint32_t CruBar::getFpgaChipLow()
370370
{
371-
assertBarIndex(2, "Can only get FPGA chip ID from BAR 2");
371+
mPdaBar->assertBarIndex(2, "Can only get FPGA chip ID from BAR 2");
372372
return readRegister(Cru::Registers::FPGA_CHIP_LOW.index);
373373
}
374374

375375
uint32_t CruBar::getPonStatusRegister()
376376
{
377-
assertBarIndex(2, "Can only get PON status register from BAR 2");
377+
mPdaBar->assertBarIndex(2, "Can only get PON status register from BAR 2");
378378
return readRegister((Cru::Registers::ONU_USER_LOGIC.address + 0x0c) / 4);
379379
}
380380

381381
uint32_t CruBar::getOnuAddress()
382382
{
383-
assertBarIndex(2, "Can only get PON status register from BAR 2");
383+
mPdaBar->assertBarIndex(2, "Can only get PON status register from BAR 2");
384384
return readRegister(Cru::Registers::ONU_USER_LOGIC.index) >> 1;
385385
}
386386

@@ -399,7 +399,7 @@ bool CruBar::checkPonUpstreamStatusExpected(uint32_t ponUpstreamRegister, uint32
399399
/// Get the enabled features for the card's firmware.
400400
FirmwareFeatures CruBar::parseFirmwareFeatures()
401401
{
402-
assertBarIndex(0, "Can only get firmware features from BAR 0");
402+
mPdaBar->assertBarIndex(0, "Can only get firmware features from BAR 0");
403403
return convertToFirmwareFeatures(readRegister(Cru::Registers::FIRMWARE_FEATURES.index));
404404
}
405405

src/Cru/CruBar.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ class CruBar final : public BarInterfaceBase
151151

152152
/// Per-link counter to verify superpage sizes received are valid
153153
uint32_t mSuperpageSizeIndexCounter[Cru::MAX_LINKS] = { 0 };
154-
155-
/// Checks if this is the correct BAR. Used to check for BAR 2 for special functions.
156-
void assertBarIndex(int index, std::string message) const
157-
{
158-
if (mPdaBar->getIndex() != index) {
159-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message(message) << ErrorInfo::BarIndex(mPdaBar->getIndex()));
160-
}
161-
}
162154
};
163155

164156
} // namespace roc

src/Pda/PdaBar.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ class PdaBar : public BarInterface
113113
return mBarLength;
114114
}
115115

116+
/// Checks if this is the correct BAR. Used to check for BAR 2 for special functions.
117+
void assertBarIndex(int index, std::string message) const
118+
{
119+
if (getIndex() != index) {
120+
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message(message) << ErrorInfo::BarIndex(getIndex()));
121+
}
122+
}
123+
116124
virtual boost::optional<int32_t> getSerial() override
117125
{
118126
return {};
@@ -195,7 +203,6 @@ class PdaBar : public BarInterface
195203
{
196204
return reinterpret_cast<void*>(mUserspaceAddress + byteOffset);
197205
}
198-
199206
/// PDA object for the PCI BAR
200207
Bar* mPdaBar;
201208

src/RocPciDevice.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <boost/format.hpp>
2323
#include <functional>
2424
#include <iostream>
25-
#include "Crorc/Crorc.h"
25+
#include "Crorc/CrorcBar.h"
2626
#include "Cru/CruBar.h"
2727
#include "Pda/PdaDevice.h"
2828
#include "ReadoutCard/ChannelFactory.h"
@@ -256,7 +256,8 @@ int cruGetSerial(std::shared_ptr<Pda::PdaBar> pdaBar2)
256256

257257
int crorcGetSerial(std::shared_ptr<Pda::PdaBar> pdaBar0)
258258
{
259-
return Crorc::getSerial(*pdaBar0.get()).get();
259+
int serial = CrorcBar(pdaBar0).getSerial().get();
260+
return serial;
260261
}
261262

262263
int cruGetEndpoint(std::shared_ptr<Pda::PdaBar> pdaBar0)

0 commit comments

Comments
 (0)