Skip to content

Commit 01bc156

Browse files
committed
[cru] Parse the card's serial from the EEPROM
1 parent 0e2d582 commit 01bc156

File tree

11 files changed

+119
-13
lines changed

11 files changed

+119
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ if(PDA_FOUND)
127127
src/Cru/CruDmaChannel.cxx
128128
src/Cru/CruBar.cxx
129129
src/Cru/DatapathWrapper.cxx
130+
src/Cru/Eeprom.cxx
130131
src/Cru/Gbt.cxx
131132
src/Cru/I2c.cxx
132133
src/Cru/Ttc.cxx

src/CardConfigurator.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ CardConfigurator::CardConfigurator(Parameters::CardIdType cardId, std::string pa
3030
bar2->reconfigure();
3131
}
3232
} catch (const Exception& e) {
33-
throw std::runtime_error(boost::diagnostic_information(e));
33+
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message(boost::diagnostic_information(e)));
3434
}
3535
}
3636

@@ -44,7 +44,7 @@ CardConfigurator::CardConfigurator(Parameters& parameters, bool forceConfigure)
4444
bar2->reconfigure();
4545
}
4646
} catch (const Exception& e) {
47-
throw std::runtime_error(boost::diagnostic_information(e));
47+
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message(boost::diagnostic_information(e)));
4848
}
4949
}
5050

src/Cru/Constants.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ static constexpr Register BSP_USER_CONTROL(0x00000018);
166166
/// Register to access I2C minipod information
167167
static constexpr Register BSP_I2C_MINIPODS(0x00030300);
168168

169+
/// Register to access the EEPROM flash
170+
static constexpr Register BSP_I2C_EEPROM(0x00030800);
171+
169172
//** TTC **//
170173
/// Register for setting the Clock
171174
static constexpr Register CLOCK_CONTROL(0x00240010);

src/Cru/CruBar.cxx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <map>
2222
#include <thread>
2323
#include "CruBar.h"
24+
#include "Eeprom.h"
2425
#include "Gbt.h"
2526
#include "I2c.h"
2627
#include "Ttc.h"
@@ -220,14 +221,11 @@ int32_t CruBar::getLinksPerWrapper(int wrapper)
220221
/// Gets the serial number from the card.
221222
/// Note that not all firmwares have a serial number. You should make sure this firmware feature is enabled before
222223
/// calling this function, or the card may crash. See parseFirmwareFeatures().
223-
uint32_t CruBar::getSerialNumber()
224+
boost::optional<int32_t> CruBar::getSerialNumber()
224225
{
225226
assertBarIndex(2, "Can only get serial number from BAR 2");
226-
auto serial = readRegister(Cru::Registers::SERIAL_NUMBER.index);
227-
if (serial == 0xFfffFfff) {
228-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("CRU reported invalid serial number 0xffffffff, "
229-
"a fatal error may have occurred"));
230-
}
227+
Eeprom eeprom = Eeprom(mPdaBar);
228+
boost::optional<int32_t> serial = eeprom.getSerial();
231229
return serial;
232230
}
233231

src/Cru/CruBar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class CruBar final : public BarInterfaceBase
8888
bool getDebugModeEnabled();
8989

9090
private:
91-
uint32_t getSerialNumber();
91+
boost::optional<int32_t> getSerialNumber();
9292
uint32_t getTemperatureRaw();
9393
boost::optional<float> convertTemperatureRaw(uint32_t registerValue);
9494
boost::optional<float> getTemperatureCelsius();

src/Cru/Eeprom.cxx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file Eeprom.cxx
12+
/// \brief Implementation of the Eeprom class
13+
///
14+
/// \author Kostas Alexopoulos ([email protected])
15+
16+
#include <regex>
17+
#include "Constants.h"
18+
#include "I2c.h"
19+
#include "Eeprom.h"
20+
21+
namespace AliceO2
22+
{
23+
namespace roc
24+
{
25+
26+
Eeprom::Eeprom(std::shared_ptr<Pda::PdaBar> pdaBar) : mPdaBar(pdaBar)
27+
{
28+
}
29+
30+
std::string Eeprom::readContent()
31+
{
32+
uint32_t chipAddress = 0x50; // fixed address
33+
I2c i2c = I2c(Cru::Registers::BSP_I2C_EEPROM.address, chipAddress, mPdaBar);
34+
35+
i2c.resetI2c();
36+
37+
std::string content;
38+
for (int i = 0; i < 1000/8; i++) { // EEPROM size is 1KB
39+
uint32_t res = i2c.readI2c(i);
40+
content += (char)res;
41+
if ((char)res == '}') {
42+
break;
43+
}
44+
}
45+
46+
return content;
47+
}
48+
49+
boost::optional<int32_t> Eeprom::getSerial()
50+
{
51+
// parse the serial from the content
52+
const std::string content = readContent();
53+
54+
// Example content:
55+
// {"cn": "FEDD", "dt": "2019-06-17", "io": "24/24", "pn": "p40_fv22b10241", "serial_number_p40": "18-02409 - 0136"}
56+
// p40_fv22b -> production CRUs
57+
// p40_tv20pr -> testing CRUs
58+
59+
std::string startDelimiter = "\"pn\": \"p40_(?:fv22b|tv20pr)";
60+
std::string endDelimiter = "\", \"serial_number_p40\":";
61+
62+
std::regex expression(startDelimiter + "(.*)" + endDelimiter);
63+
std::smatch match;
64+
65+
if (std::regex_search(content.begin(), content.end(), match, expression)) {
66+
return std::stol(match[1], NULL, 0);
67+
}
68+
69+
return {};
70+
}
71+
72+
} // namespace roc
73+
} // namespace AliceO2

src/Cru/Eeprom.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// \file Eeprom.h
2+
/// \brief Definition of the Eeprom class
3+
///
4+
/// \author Kostas Alexopoulos ([email protected])
5+
6+
#ifndef ALICEO2_READOUTCARD_CRU_EEPROM_H_
7+
#define ALICEO2_READOUTCARD_CRU_EEPROM_H_
8+
9+
#include "Pda/PdaBar.h"
10+
11+
namespace AliceO2
12+
{
13+
namespace roc
14+
{
15+
16+
class Eeprom
17+
{
18+
public:
19+
Eeprom(std::shared_ptr<Pda::PdaBar> pdaBar);
20+
21+
boost::optional<int32_t> getSerial();
22+
23+
private:
24+
std::string readContent();
25+
std::shared_ptr<Pda::PdaBar> mPdaBar;
26+
};
27+
} // namespace roc
28+
} // namespace AliceO2
29+
30+
#endif // ALICEO2_READOUTCARD_CRU_EEPROM_H_

src/Cru/Gbt.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ void Gbt::getGbtModes()
8484
for (auto& el : mLinkMap) {
8585
auto& link = el.second;
8686
uint32_t rxControl = mPdaBar->readRegister(getRxControlAddress(link) / 4);
87-
if (((rxControl >> 8) & 0x1) == Cru::GBT_MODE_WB) { //TODO: Change with Constants
87+
if (((rxControl >> 8) & 0x1) == Cru::GBT_MODE_WB) {
8888
link.gbtRxMode = GbtMode::type::Wb;
8989
} else {
9090
link.gbtRxMode = GbtMode::type::Gbt;
9191
}
9292

9393
uint32_t txControl = mPdaBar->readRegister(getTxControlAddress(link) / 4);
94-
if (((txControl >> 8) & 0x1) == Cru::GBT_MODE_WB) { //TODO: Change with Constants
94+
if (((txControl >> 8) & 0x1) == Cru::GBT_MODE_WB) {
9595
link.gbtTxMode = GbtMode::type::Wb;
9696
} else {
9797
link.gbtTxMode = GbtMode::type::Gbt;

src/Cru/I2c.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class I2c
4040
void configurePll();
4141
uint32_t getSelectedClock();
4242
void getOpticalPower(std::map<int, Link>& linkMap);
43+
uint32_t readI2c(uint32_t address);
4344

4445
private:
4546
//std::map<uint32_t, uint32_t> readRegisterMap(std::string file);
4647
void writeI2c(uint32_t address, uint32_t data);
47-
uint32_t readI2c(uint32_t address);
4848
void waitForI2cReady();
4949
std::vector<uint32_t> getChipAddresses();
5050

src/Cru/cru_constants_populate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
'add_flowctrl_ctrlreg':'FLOW_CONTROL_REGISTER',
6868
'add_gbt_wrapper_atx_pll':'GBT_WRAPPER_ATX_PLL',
6969
'add_gbt_bank_fpll':'GBT_BANK_FPLL',
70+
'add_bsp_i2c_eeprom':"BSP_I2C_EEPROM",
7071
'add_bsp_i2c_minipods':"BSP_I2C_MINIPODS",
7172
'add_bsp_i2c_si5345_1':'SI5345_1',
7273
'add_bsp_i2c_si5345_2':'SI5345_2',

0 commit comments

Comments
 (0)