Skip to content

Commit 90129c2

Browse files
kostorrpippohub
authored andcommitted
Separate BAR functionality from DMA Channels
1 parent 482d097 commit 90129c2

21 files changed

+685
-506
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ add_subdirectory(doc)
200200
enable_testing()
201201

202202
set(TEST_SRCS
203-
test/TestBarAccessor.cxx
204203
test/TestChannelFactoryUtils.cxx
205204
test/TestChannelPaths.cxx
205+
test/TestCruBar.cxx
206206
test/TestCruDataFormat.cxx
207207
test/TestEnums.cxx
208208
test/TestInterprocessLock.cxx

include/ReadoutCard/BarInterface.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "ReadoutCard/CardType.h"
1111
#include "ReadoutCard/RegisterReadWriteInterface.h"
1212
#include "ReadoutCard/Parameters.h"
13+
#include "boost/optional.hpp"
1314

1415
namespace AliceO2 {
1516
namespace roc {
@@ -38,6 +39,15 @@ class BarInterface: public virtual RegisterReadWriteInterface
3839
/// Returns the type of the card
3940
/// \return The card type
4041
virtual CardType::type getCardType() = 0;
42+
43+
virtual boost::optional<int32_t> getSerial() = 0;
44+
45+
virtual boost::optional<float> getTemperature() = 0;
46+
47+
virtual boost::optional<std::string> getFirmwareInfo() = 0;
48+
49+
virtual boost::optional<std::string> getCardId() = 0;
50+
4151
};
4252

4353
} // namespace roc

src/BarInterfaceBase.cxx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Implementation of the BarInterfaceBase class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#include "BarInterfaceBase.h"
78
#include "Utilities/SmartPointer.h"
@@ -21,6 +22,12 @@ BarInterfaceBase::BarInterfaceBase(const Parameters& parameters)
2122
Utilities::resetSmartPtr(mPdaBar, mRocPciDevice->getPciDevice(), mBarIndex);
2223
}
2324

25+
BarInterfaceBase::BarInterfaceBase(std::shared_ptr<Pda::PdaBar> bar)
26+
{
27+
mPdaBar = std::move(bar);
28+
}
29+
30+
2431
BarInterfaceBase::~BarInterfaceBase()
2532
{
2633
}

src/BarInterfaceBase.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Definition of the BarInterfaceBase class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#ifndef ALICEO2_SRC_READOUTCARD_BARINTERFACEBASE_H_
78
#define ALICEO2_SRC_READOUTCARD_BARINTERFACEBASE_H_
@@ -21,6 +22,7 @@ class BarInterfaceBase: public BarInterface
2122
public:
2223

2324
BarInterfaceBase(const Parameters& parameters);
25+
BarInterfaceBase(std::shared_ptr<Pda::PdaBar> bar);
2426
virtual ~BarInterfaceBase();
2527

2628
virtual uint32_t readRegister(int index) override;
@@ -36,15 +38,37 @@ class BarInterfaceBase: public BarInterface
3638
return mPdaBar->getSize();
3739
}
3840

41+
/// Default implementation for optional function
42+
virtual boost::optional<float> getTemperature() override
43+
{
44+
return {};
45+
}
46+
47+
/// Default implementation for optional function
48+
virtual boost::optional<std::string> getFirmwareInfo() override
49+
{
50+
return {};
51+
}
52+
53+
/// Default implementation for optional function
54+
virtual boost::optional<std::string> getCardId() override
55+
{
56+
return {};
57+
}
58+
59+
3960
protected:
4061
/// BAR index
4162
int mBarIndex;
4263

4364
/// PDA device objects
4465
std::unique_ptr<RocPciDevice> mRocPciDevice;
4566

46-
/// PDA BAR object
47-
std::unique_ptr<Pda::PdaBar> mPdaBar;
67+
/// PDA BAR object ptr
68+
std::shared_ptr<Pda::PdaBar> mPdaBar;
69+
70+
// PDA BAR object
71+
Pda::PdaBar mlPdaBar;
4872

4973
private:
5074
/// Inheriting classes must implement this to check whether a given read is safe.
@@ -58,4 +82,4 @@ class BarInterfaceBase: public BarInterface
5882
} // namespace roc
5983
} // namespace AliceO2
6084

61-
#endif // ALICEO2_SRC_READOUTCARD_BARINTERFACEBASE_H_
85+
#endif // ALICEO2_SRC_READOUTCARD_BARINTERFACEBASE_H_

src/CommandLineUtilities/ProgramListCards.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Utility that lists the ReadoutCard devices on the system
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#include <iostream>
78
#include <sstream>
@@ -37,8 +38,8 @@ class ProgramListCards: public Program
3738

3839
std::ostringstream table;
3940

40-
auto formatHeader = " %-3s %-6s %-10s %-11s %-11s %-8s %-15s %-17s\n";
41-
auto formatRow = " %-3s %-6s %-10s 0x%-9s 0x%-9s %-8s %-15s %-17s\n";
41+
auto formatHeader = " %-3s %-6s %-10s %-11s %-11s %-8s %-25s %-17s\n";
42+
auto formatRow = " %-3s %-6s %-10s 0x%-9s 0x%-9s %-8s %-25s %-17s\n";
4243
auto header = (boost::format(formatHeader)
4344
% "#" % "Type" % "PCI Addr" % "Vendor ID" % "Device ID" % "Serial" % "FW Version" % "Card ID").str();
4445
auto lineFat = std::string(header.length(), '=') + '\n';
@@ -53,10 +54,10 @@ class ProgramListCards: public Program
5354
std::string firmware = na;
5455
std::string cardId = na;
5556
try {
56-
Parameters params = Parameters::makeParameters(card.pciAddress, 0);
57+
Parameters params = Parameters::makeParameters(card.pciAddress, 2);
5758
params.setBufferParameters(buffer_parameters::Null());
58-
firmware = ChannelFactory().getDmaChannel(params)->getFirmwareInfo().value_or(na);
59-
cardId = ChannelFactory().getDmaChannel(params)->getCardId().value_or(na);
59+
firmware = ChannelFactory().getBar(params)->getFirmwareInfo().value_or(na);
60+
cardId = ChannelFactory().getBar(params)->getCardId().value_or(na);
6061
}
6162
catch (const Exception& e) {
6263
if (isVerbose()) {

src/Crorc/CrorcBar.cxx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Implementation of the CrorcBar class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#include "Crorc/CrorcBar.h"
78

@@ -25,5 +26,45 @@ void CrorcBar::checkWriteSafe(int, uint32_t)
2526
{
2627
}
2728

29+
boost::optional<int32_t> CrorcBar::getSerial()
30+
{
31+
return Crorc::getSerial(*(mPdaBar.get()));
32+
}
33+
34+
35+
boost::optional<float> CrorcBar::getTemperature()
36+
{
37+
return {};
38+
}
39+
40+
boost::optional<std::string> CrorcBar::getFirmwareInfo()
41+
{
42+
uint32_t version = mPdaBar->readRegister(Rorc::RFID);
43+
auto bits = [&](int lsb, int msb) { return Utilities::getBits(version, lsb, msb); };
44+
45+
uint32_t reserved = bits(24, 31);
46+
uint32_t major = bits(20, 23);
47+
uint32_t minor = bits(13, 19);
48+
uint32_t year = bits(9, 12) + 2000;
49+
uint32_t month = bits(5, 8);
50+
uint32_t day = bits(0, 4);
51+
52+
if (reserved != 0x2) {
53+
BOOST_THROW_EXCEPTION(CrorcException()
54+
<< ErrorInfo::Message("Static field of version register did not equal 0x2"));
55+
}
56+
57+
std::ostringstream stream;
58+
stream << major << '.' << minor << ':' << year << '-' << month << '-' << day;
59+
return stream.str();
60+
}
61+
62+
boost::optional<std::string> CrorcBar::getCardId()
63+
{
64+
return {};
65+
}
66+
67+
68+
2869
} // namespace roc
2970
} // namespace AliceO2

src/Crorc/CrorcBar.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
/// \brief Definition of the CrorcBar class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#ifndef ALICEO2_SRC_READOUTCARD_CRORC_CRORCBAR_H_
78
#define ALICEO2_SRC_READOUTCARD_CRORC_CRORCBAR_H_
89

910
#include "BarInterfaceBase.h"
11+
#include "Crorc.h"
12+
#include "Crorc/Constants.h"
13+
#include "Utilities/Util.h"
1014

1115
namespace AliceO2 {
1216
namespace roc {
1317

14-
/// TODO Currently a placeholder
1518
class CrorcBar final : public BarInterfaceBase
1619
{
1720
public:
@@ -24,9 +27,14 @@ class CrorcBar final : public BarInterfaceBase
2427
{
2528
return CardType::Crorc;
2629
}
30+
31+
virtual boost::optional<int32_t> getSerial() override;
32+
virtual boost::optional<float> getTemperature() override;
33+
virtual boost::optional<std::string> getFirmwareInfo() override;
34+
virtual boost::optional<std::string> getCardId() override;
2735
};
2836

2937
} // namespace roc
3038
} // namespace AliceO2
3139

32-
#endif // ALICEO2_SRC_READOUTCARD_CRORC_CRORCBAR_H_
40+
#endif // ALICEO2_SRC_READOUTCARD_CRORC_CRORCBAR_H_

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Implementation of the CrorcDmaChannel class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#include "CrorcDmaChannel.h"
78
#include <iostream>
@@ -13,6 +14,7 @@
1314
#include <boost/format.hpp>
1415
#include "ChannelPaths.h"
1516
#include "Crorc/Constants.h"
17+
#include "ReadoutCard/ChannelFactory.h"
1618
#include "Utilities/SmartPointer.h"
1719

1820
namespace b = boost;
@@ -27,8 +29,8 @@ namespace roc {
2729

2830
CrorcDmaChannel::CrorcDmaChannel(const Parameters& parameters)
2931
: DmaChannelPdaBase(parameters, allowedChannels()), //
30-
mPdaBar(getRocPciDevice().getPciDevice(), getChannelNumber()), // Initialize main DMA channel BAR
31-
mPdaBar2(getRocPciDevice().getPciDevice(), 2), // Initialize BAR 2
32+
//mPdaBar(getRocPciDevice().getPciDevice(), getChannelNumber()), // Initialize main DMA channel BAR
33+
//mPdaBar2(getRocPciDevice().getPciDevice(), 2), // Initialize BAR 2
3234
mPageSize(parameters.getDmaPageSize().get_value_or(8*1024)), // 8 kB default for uniformity with CRU
3335
mInitialResetLevel(ResetLevel::Internal), // It's good to reset at least the card channel in general
3436
mNoRDYRX(true), // Not sure
@@ -44,6 +46,14 @@ CrorcDmaChannel::CrorcDmaChannel(const Parameters& parameters)
4446
mUseContinuousReadout(parameters.getReadoutMode().is_initialized() ?
4547
parameters.getReadoutModeRequired() == ReadoutMode::Continuous : false)
4648
{
49+
// Prep for BARs
50+
auto parameters2 = parameters;
51+
parameters2.setChannelNumber(2);
52+
auto bar = ChannelFactory().getBar(parameters);
53+
auto bar2 = ChannelFactory().getBar(parameters2);
54+
crorcBar = std::move(std::dynamic_pointer_cast<CrorcBar> (bar)); // Initialize bar0
55+
crorcBar2 = std::move(std::dynamic_pointer_cast<CrorcBar> (bar2)); // Initalize bar2
56+
4757
// Create and register our ReadyFIFO buffer
4858
log("Initializing ReadyFIFO DMA buffer", InfoLogger::InfoLogger::Debug);
4959
{
@@ -101,7 +111,7 @@ void CrorcDmaChannel::startPendingDma(SuperpageQueueEntry& entry)
101111

102112
if (mUseContinuousReadout) {
103113
log("Initializing continuous readout");
104-
Crorc::Crorc::initReadoutContinuous(mPdaBar2);
114+
Crorc::Crorc::initReadoutContinuous(*(getBar2()));
105115
}
106116

107117
// Find DIU version, required for armDdl()
@@ -165,7 +175,7 @@ void CrorcDmaChannel::startPendingDma(SuperpageQueueEntry& entry)
165175

166176
if (mUseContinuousReadout) {
167177
log("Starting continuous readout");
168-
Crorc::Crorc::startReadoutContinuous(mPdaBar2);
178+
Crorc::Crorc::startReadoutContinuous(*(getBar2()));
169179
}
170180
}
171181

@@ -437,29 +447,12 @@ CardType::type CrorcDmaChannel::getCardType()
437447

438448
boost::optional<int32_t> CrorcDmaChannel::getSerial()
439449
{
440-
return Crorc::getSerial(mPdaBar);
450+
return getBar2()->getSerial();
441451
}
442452

443453
boost::optional<std::string> CrorcDmaChannel::getFirmwareInfo()
444454
{
445-
uint32_t version = mPdaBar.readRegister(Rorc::RFID);
446-
auto bits = [&](int lsb, int msb) { return Utilities::getBits(version, lsb, msb); };
447-
448-
uint32_t reserved = bits(24, 31);
449-
uint32_t major = bits(20, 23);
450-
uint32_t minor = bits(13, 19);
451-
uint32_t year = bits(9, 12) + 2000;
452-
uint32_t month = bits(5, 8);
453-
uint32_t day = bits(0, 4);
454-
455-
if (reserved != 0x2) {
456-
BOOST_THROW_EXCEPTION(CrorcException()
457-
<< ErrorInfo::Message("Static field of version register did not equal 0x2"));
458-
}
459-
460-
std::ostringstream stream;
461-
stream << major << '.' << minor << ':' << year << '-' << month << '-' << day;
462-
return stream.str();
455+
return getBar2()->getFirmwareInfo();
463456
}
464457

465458
} // namespace roc

src/Crorc/CrorcDmaChannel.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// \brief Definition of the CrorcDmaChannel class.
33
///
44
/// \author Pascal Boeschoten ([email protected])
5+
/// \author Kostas Alexopoulos ([email protected])
56

67
#ifndef ALICEO2_SRC_READOUTCARD_CRORC_CRORCDMACHANNEL_H_
78
#define ALICEO2_SRC_READOUTCARD_CRORC_CRORCDMACHANNEL_H_
@@ -12,6 +13,7 @@
1213
#include <boost/scoped_ptr.hpp>
1314
#include "DmaChannelPdaBase.h"
1415
#include "Crorc.h"
16+
#include "CrorcBar.h"
1517
#include "ReadoutCard/Parameters.h"
1618
#include "ReadyFifo.h"
1719
#include "SuperpageQueue.h"
@@ -80,7 +82,7 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
8082
/// C-RORC function helper
8183
Crorc::Crorc getCrorc()
8284
{
83-
return {mPdaBar};
85+
return {*(getBar())};
8486
}
8587

8688
ReadyFifo* getReadyFifoUser()
@@ -119,11 +121,21 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
119121
return (mFifoBack + mFifoSize) % READYFIFO_ENTRIES;
120122
};
121123

124+
CrorcBar* getBar()
125+
{
126+
return crorcBar.get();
127+
}
128+
129+
CrorcBar* getBar2()
130+
{
131+
return crorcBar2.get();
132+
}
133+
122134
/// BAR 0 is needed for DMA engine interaction and various other functions
123-
Pda::PdaBar mPdaBar;
135+
std::shared_ptr<CrorcBar> crorcBar;
124136

125137
/// BAR 2 is needed for configuration
126-
Pda::PdaBar mPdaBar2;
138+
std::shared_ptr<CrorcBar> crorcBar2;
127139

128140
/// Memory mapped file for the ReadyFIFO
129141
boost::scoped_ptr<MemoryMappedFile> mBufferFifoFile;
@@ -203,4 +215,4 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
203215
} // namespace roc
204216
} // namespace AliceO2
205217

206-
#endif // ALICEO2_SRC_READOUTCARD_CRORC_CRORCDMACHANNEL_H_
218+
#endif // ALICEO2_SRC_READOUTCARD_CRORC_CRORCDMACHANNEL_H_

0 commit comments

Comments
 (0)