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>
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
1820namespace b = boost;
@@ -27,8 +29,8 @@ namespace roc {
2729
2830CrorcDmaChannel::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
438448boost::optional<int32_t > CrorcDmaChannel::getSerial ()
439449{
440- return Crorc:: getSerial (mPdaBar );
450+ return getBar2 ()-> getSerial ();
441451}
442452
443453boost::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
0 commit comments