Skip to content

Commit 3c95dbc

Browse files
committed
[fw] Changes for v3.2.0
1 parent f95daf1 commit 3c95dbc

File tree

13 files changed

+197
-142
lines changed

13 files changed

+197
-142
lines changed

src/CardConfigurator.cxx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,28 @@ CardConfigurator::CardConfigurator(Parameters::CardIdType cardId, std::string pa
2323
}
2424

2525
auto bar2 = ChannelFactory().getBar(parameters);
26-
if (forceConfigure) {
27-
bar2->configure();
28-
} else {
29-
bar2->reconfigure();
26+
try {
27+
if (forceConfigure) {
28+
bar2->configure();
29+
} else {
30+
bar2->reconfigure();
31+
}
32+
} catch (const Exception& e) {
33+
throw std::runtime_error(boost::diagnostic_information(e));
3034
}
3135
}
3236

3337
CardConfigurator::CardConfigurator(Parameters& parameters, bool forceConfigure)
3438
{
3539
auto bar2 = ChannelFactory().getBar(parameters);
36-
if (forceConfigure) {
37-
bar2->configure();
38-
} else {
39-
bar2->reconfigure();
40+
try {
41+
if (forceConfigure) {
42+
bar2->configure();
43+
} else {
44+
bar2->reconfigure();
45+
}
46+
} catch (const Exception& e) {
47+
throw std::runtime_error(boost::diagnostic_information(e));
4048
}
4149
}
4250

src/CommandLineUtilities/ProgramConfig.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Cru/CruBar.h"
2020
#include "ReadoutCard/CardConfigurator.h"
2121
#include "ReadoutCard/ChannelFactory.h"
22+
#include "ReadoutCard/Exception.h"
2223
#include "RocPciDevice.h"
2324

2425
using namespace AliceO2::roc::CommandLineUtilities;
@@ -101,8 +102,8 @@ class ProgramConfig : public Program
101102
auto params = Parameters::makeParameters(card.pciAddress, 2);
102103
try {
103104
CardConfigurator(card.pciAddress, mOptions.configFile, mOptions.forceConfig);
104-
} catch (...) {
105-
std::cout << "Something went badly reading the configuration file..." << std::endl;
105+
} catch (const Exception& e) {
106+
std::cout << boost::diagnostic_information(e) << std::endl;
106107
}
107108
}
108109
return;
@@ -126,7 +127,11 @@ class ProgramConfig : public Program
126127
params.setPonUpstreamEnabled(mOptions.ponUpstreamEnabled);
127128
params.setOnuAddress(mOptions.onuAddress);
128129

129-
CardConfigurator(params, mOptions.forceConfig);
130+
try {
131+
CardConfigurator(params, mOptions.forceConfig);
132+
} catch (const Exception& e) {
133+
std::cout << boost::diagnostic_information(e) << std::endl;
134+
}
130135
} else if (!strncmp(mOptions.configFile.c_str(), "file:", 5)) {
131136
std::cout << "Configuring with config file" << std::endl;
132137
try {

src/Cru/Common.cxx

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ void atxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
5959
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x02); //...
6060

6161
// b. Validate that user has control
62-
// TODO(cru-sw): There should be a check here...
63-
uint32_t bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
64-
if (bit != 0) {
65-
std::cout << "atxcal0 0" << std::endl;
66-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("atxcal0: User does not have control"));
67-
}
62+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
6863

6964
// c. Enable ATX PLL alibration
7065
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 0, 1, 0x1);
@@ -73,11 +68,7 @@ void atxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
7368
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
7469

7570
//e. Wait...
76-
bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
77-
if (bit != 0) {
78-
std::cout << "atxcal0 1" << std::endl;
79-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("atxcal0: User does not have control"));
80-
}
71+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
8172

8273
//f. Calibration complete...
8374
}
@@ -90,11 +81,7 @@ void txcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
9081
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
9182

9283
//b. Validate that user has control
93-
uint32_t bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
94-
if (bit != 0) {
95-
std::cout << "txcal0 0" << std::endl;
96-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("txcal0: User does not have control"));
97-
}
84+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
9885

9986
//c. Mask out rx_cal_busy...
10087
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 5, 1, 0x0);
@@ -107,11 +94,7 @@ void txcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
10794
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
10895

10996
//f. Wait..
110-
bit = waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
111-
if (bit != 0) {
112-
std::cout << "txcal0 1" << std::endl;
113-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("txcal0: User does not have control"));
114-
}
97+
waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
11598

11699
//g. Calibration is complete
117100

@@ -126,11 +109,7 @@ void rxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
126109
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
127110

128111
//b. Validate that user has control
129-
uint32_t bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
130-
if (bit != 0) {
131-
std::cout << "rxcal0 0" << std::endl;
132-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("rxcal0: User does not have control"));
133-
}
112+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
134113

135114
//c. Mask out tx_cal_busy...
136115
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 4, 1, 0x0);
@@ -145,11 +124,7 @@ void rxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
145124
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
146125

147126
//g. Wait..
148-
bit = waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
149-
if (bit != 0) {
150-
std::cout << "rxcal0 1" << std::endl;
151-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("rxcal0: User does not have control"));
152-
}
127+
waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
153128

154129
//h. Calibration is complete
155130

@@ -183,10 +158,7 @@ void fpllcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, bool co
183158
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x02);
184159

185160
//b. Validate that user has control
186-
uint32_t bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
187-
if (bit != 0) {
188-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("fpllcal0: User does not have control"));
189-
}
161+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
190162

191163
//c. Enable fPLL calibration
192164
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 1, 1, 0x1);
@@ -195,10 +167,7 @@ void fpllcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, bool co
195167
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
196168

197169
//e. Wait...
198-
bit = waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
199-
if (bit != 0) {
200-
BOOST_THROW_EXCEPTION(Exception() << ErrorInfo::Message("fpllcal0: User does not have control"));
201-
}
170+
waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
202171

203172
//f. Calibration is complete
204173

@@ -217,7 +186,7 @@ uint32_t waitForBit(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t address, uint3
217186
uint32_t readValue = pdaBar->readRegister(address / 4);
218187
uint32_t bit = Utilities::getBit(readValue, position);
219188

220-
while ((elapsed <= std::chrono::milliseconds(800)) && bit != value) {
189+
while ((elapsed <= std::chrono::milliseconds(500)) && bit != value) {
221190
readValue = pdaBar->readRegister(address / 4);
222191
bit = Utilities::getBit(readValue, position);
223192
curr = std::chrono::system_clock::now();

src/Cru/Constants.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static constexpr Register DDG_CTRL2(0x00d00004);
164164
static constexpr Register BSP_USER_CONTROL(0x00000018);
165165

166166
/// Register to access I2C minipod information
167-
static constexpr Register BSP_I2C_MINIPODS(0x00030600);
167+
static constexpr Register BSP_I2C_MINIPODS(0x00030300);
168168

169169
//** TTC **//
170170
/// Register for setting the Clock
@@ -186,6 +186,7 @@ static constexpr uint32_t DATA_MIDTRG(0x2);*/
186186
/// Registers used for TTC calibration
187187
static constexpr Register PON_WRAPPER_PLL(0x00224000);
188188
static constexpr Register PON_WRAPPER_TX(0x00226000);
189+
static constexpr Register PON_WRAPPER_REG(0x00222000);
189190

190191
/// Register for configuring PON TX
191192
static constexpr Register CLOCK_ONU_FPLL(0x00248000);
@@ -249,6 +250,9 @@ static constexpr Register DWRAPPER_BASE0(0x00600000);
249250
/// Datapath Wrapper 1 base address
250251
static constexpr Register DWRAPPER_BASE1(0x00700000);
251252

253+
/// DATAPATH Data Generator Control Register
254+
static constexpr Register DWRAPPER_DATAGEN_CONTROL(0x00000004);
255+
252256
/// Datapath Wrapper offset for "Global Registers"
253257
static constexpr Register DWRAPPER_GREGS(0x00000000);
254258

@@ -271,9 +275,9 @@ static constexpr Register FLOW_CONTROL_REGISTER(0x00000000);
271275

272276
//** I2C **//
273277
/// I2C base addresses
274-
static constexpr Register SI5345_1(0x00030a00);
275-
static constexpr Register SI5345_2(0x00030c00);
276-
static constexpr Register SI5344(0x00030800);
278+
static constexpr Register SI5345_1(0x00030500);
279+
static constexpr Register SI5345_2(0x00030600);
280+
static constexpr Register SI5344(0x00030400);
277281

278282
} // namespace Registers
279283
} // namespace Cru

src/Cru/CruBar.cxx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ void CruBar::configure()
521521
ttc.setClock(mClock);
522522

523523
log("Calibrating TTC");
524-
ttc.calibrateTtc();
524+
if (mClock == Clock::Ttc) {
525+
ttc.calibrateTtc();
526+
}
525527

526528
if (mPonUpstream) {
527529
ttc.resetFpll();
@@ -544,6 +546,11 @@ void CruBar::configure()
544546
disableDataTaking();
545547

546548
DatapathWrapper datapathWrapper = DatapathWrapper(mPdaBar);
549+
550+
// Disable DWRAPPER datagenerator (in case of restart)
551+
datapathWrapper.resetDataGeneratorPulse();
552+
datapathWrapper.useDataGeneratorSource(false);
553+
datapathWrapper.enableDataGenerator(false);
547554
// Disable all links
548555
datapathWrapper.setLinksEnabled(0, 0x0);
549556
datapathWrapper.setLinksEnabled(1, 0x0);
@@ -677,10 +684,10 @@ void CruBar::populateLinkMap(std::map<int, Link>& linkMap)
677684
}
678685
}
679686

680-
int CruBar::getDdgBurstLength()
687+
uint32_t CruBar::getDdgBurstLength()
681688
{
682689
uint32_t burst = (((readRegister(Cru::Registers::DDG_CTRL0.address)) >> 20) / 4) & 0xff;
683-
return Utilities::getWidth(burst);
690+
return burst;
684691
}
685692

686693
void CruBar::enableDataTaking()

src/Cru/CruBar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class CruBar final : public BarInterfaceBase
109109
std::map<int, Link> initializeLinkMap();
110110
void populateLinkMap(std::map<int, Link>& linkMap);
111111

112-
int getDdgBurstLength();
112+
uint32_t getDdgBurstLength();
113113
//void checkParameters();
114114

115115
void setCruId(uint16_t cruId);

src/Cru/DatapathWrapper.cxx

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ void DatapathWrapper::setDatapathMode(Link link, uint32_t mode)
6262
Cru::Registers::DATALINK_CONTROL.address;
6363

6464
uint32_t val = 0;
65-
val |= 0x1FC; //=RAWMAXLEN
66-
val |= (1 << 24); //=RAWBYID
65+
val |= 0x1FC; //=RAWMAXLEN
6766
val |= (mode << 31);
6867

6968
mPdaBar->writeRegister(address / 4, val);
@@ -135,5 +134,47 @@ uint32_t DatapathWrapper::getDatapathWrapperBaseAddress(int wrapper)
135134
return 0x0;
136135
}
137136

137+
void DatapathWrapper::resetDataGeneratorPulse()
138+
{
139+
// Resets data generator
140+
for (int wrapper = 0; wrapper <= 1; wrapper++) {
141+
uint32_t address = getDatapathWrapperBaseAddress(wrapper) +
142+
Cru::Registers::DWRAPPER_GREGS.address +
143+
Cru::Registers::DWRAPPER_DATAGEN_CONTROL.address;
144+
mPdaBar->modifyRegister(address / 4, 0, 1, 0x1);
145+
mPdaBar->modifyRegister(address / 4, 0, 1, 0x0);
146+
}
147+
}
148+
149+
void DatapathWrapper::useDataGeneratorSource(bool enable)
150+
{
151+
// Sets datagenerator as bigfifo input source
152+
for (int wrapper = 0; wrapper <= 1; wrapper++) {
153+
uint32_t address = getDatapathWrapperBaseAddress(wrapper) +
154+
Cru::Registers::DWRAPPER_GREGS.address +
155+
Cru::Registers::DWRAPPER_DATAGEN_CONTROL.address;
156+
if (enable) {
157+
mPdaBar->modifyRegister(address / 4, 31, 1, 0x1);
158+
} else {
159+
mPdaBar->modifyRegister(address / 4, 31, 1, 0x0);
160+
}
161+
}
162+
}
163+
164+
void DatapathWrapper::enableDataGenerator(bool enable)
165+
{
166+
// Enables data generation
167+
for (int wrapper = 0; wrapper <= 1; wrapper++) {
168+
uint32_t address = getDatapathWrapperBaseAddress(wrapper) +
169+
Cru::Registers::DWRAPPER_GREGS.address +
170+
Cru::Registers::DWRAPPER_DATAGEN_CONTROL.address;
171+
if (enable) {
172+
mPdaBar->modifyRegister(address / 4, 1, 1, 0x1);
173+
} else {
174+
mPdaBar->modifyRegister(address / 4, 1, 1, 0x0);
175+
}
176+
}
177+
}
178+
138179
} // namespace roc
139180
} // namespace AliceO2

src/Cru/DatapathWrapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class DatapathWrapper
4141
void setPacketArbitration(int wrapperCount, int arbitrationMode = 0);
4242
void setFlowControl(int wrapper, int allowReject = 0);
4343
uint32_t getFlowControl(int wrapper);
44+
void resetDataGeneratorPulse();
45+
void useDataGeneratorSource(bool enable);
46+
void enableDataGenerator(bool enable);
4447

4548
private:
4649
uint32_t getDatapathWrapperBaseAddress(int wrapper);

src/Cru/I2c.cxx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ void I2c::writeI2c(uint32_t address, uint32_t data)
130130
mPdaBar->writeRegister(mI2cConfig / 4, value);
131131

132132
mPdaBar->writeRegister(mI2cCommand / 4, 0x1);
133-
std::this_thread::sleep_for(std::chrono::nanoseconds(100));
134133
mPdaBar->writeRegister(mI2cCommand / 4, 0x0);
135134

136135
waitForI2cReady();
@@ -158,8 +157,7 @@ void I2c::waitForI2cReady()
158157
while (readValue == 0 && done < 10) {
159158
readValue = mPdaBar->readRegister(mI2cData / 4);
160159
readValue = Utilities::getBit(readValue, 31);
161-
std::this_thread::sleep_for(std::chrono::nanoseconds(100));
162-
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
160+
std::this_thread::sleep_for(std::chrono::microseconds(100));
163161
done++;
164162
}
165163
}
@@ -180,7 +178,7 @@ std::vector<uint32_t> I2c::getChipAddresses()
180178

181179
uint32_t addrValue = mPdaBar->readRegister(mI2cData / 4);
182180
//addrValue = addrValue < 0 ? addrValue + pow(2, 32) : addrValue; //unsigned is never negative : what was the idea here?
183-
if (((addrValue >> 31) & 0x1) == 0x1) {
181+
if ((addrValue >> 31) == 0x1) {
184182
chipAddresses.push_back(addr);
185183
}
186184
}
@@ -231,11 +229,17 @@ void I2c::getOpticalPower(std::map<int, Link>& linkMap)
231229
int chipIndex = 11;
232230
for (auto& el : linkMap) {
233231
auto& link = el.second;
234-
link.opticalPower = opticalPowers[chipIndex--];
235-
if (chipIndex == -1) {
236-
chipIndex = 23; //move to second chip
232+
if (opticalPowers.empty()) { //Means no chip found
233+
link.opticalPower = 0.0;
234+
} else {
235+
link.opticalPower = opticalPowers[chipIndex--];
236+
237+
if (chipIndex == -1) {
238+
chipIndex = 23; //move to second chip
239+
}
237240
}
238241
}
242+
239243
return;
240244
}
241245

0 commit comments

Comments
 (0)