Skip to content

Commit 58fb3a0

Browse files
committed
[roc-config] Modularize roc-config operations
1 parent 5832720 commit 58fb3a0

File tree

14 files changed

+144
-129
lines changed

14 files changed

+144
-129
lines changed

include/ReadoutCard/BarInterface.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ class BarInterface : public virtual RegisterReadWriteInterface
7474

7575
virtual int getEndpointNumber() = 0;
7676

77-
virtual void configure() = 0;
78-
79-
virtual void reconfigure() = 0;
77+
virtual void configure(bool force) = 0;
8078
};
8179

8280
} // namespace roc

src/BarInterfaceBase.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,10 @@ class BarInterfaceBase : public BarInterface
118118
}
119119

120120
/// Default implementation for optional function
121-
void configure() override
121+
void configure(bool /*force*/) override
122122
{
123123
log("Configure unavailable for this interface", InfoLogger::InfoLogger::Error);
124124
}
125-
/// Default implementation for optional function
126-
void reconfigure() override
127-
{
128-
log("Reconfigure unavailable for this interface", InfoLogger::InfoLogger::Error);
129-
}
130125

131126
protected:
132127
/// BAR index

src/CardConfigurator.cxx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ CardConfigurator::CardConfigurator(Parameters::CardIdType cardId, std::string co
2525

2626
auto bar2 = ChannelFactory().getBar(parameters);
2727
try {
28-
if (forceConfigure) {
29-
bar2->configure();
30-
} else {
31-
bar2->reconfigure();
32-
}
28+
bar2->configure(forceConfigure);
3329
} catch (const Exception& e) {
3430
BOOST_THROW_EXCEPTION(e);
3531
}
@@ -39,11 +35,7 @@ CardConfigurator::CardConfigurator(Parameters& parameters, bool forceConfigure)
3935
{
4036
auto bar2 = ChannelFactory().getBar(parameters);
4137
try {
42-
if (forceConfigure) {
43-
bar2->configure();
44-
} else {
45-
bar2->reconfigure();
46-
}
38+
bar2->configure(forceConfigure);
4739
} catch (const Exception& e) {
4840
BOOST_THROW_EXCEPTION(e);
4941
}

src/Cru/Common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ struct Link {
7676
allowRejection == dlink.allowRejection);
7777
}
7878
}
79+
80+
bool operator!=(const Link& dlink) const
81+
{
82+
return !operator==(dlink);
83+
}
7984
};
8085

8186
struct ReportInfo {

src/Cru/CruBar.cxx

Lines changed: 76 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,8 @@ Cru::ReportInfo CruBar::report()
436436
uint32_t ponStatusRegister = getPonStatusRegister();
437437
uint32_t onuAddress = getOnuAddress();
438438
uint16_t cruId = getCruId();
439-
bool dynamicOffset = datapathWrapper.getDynamicOffsetEnabled(0) && datapathWrapper.getDynamicOffsetEnabled(1); // should be enabled for both wrappers
440-
uint32_t triggerWindowSize = datapathWrapper.getTriggerWindowSize(0);
441-
if (triggerWindowSize != datapathWrapper.getTriggerWindowSize(1)) { // in case trigger window size is different between wrappers
442-
triggerWindowSize = 4096; //invalid trigger window size to force reconfigure
443-
}
439+
bool dynamicOffset = datapathWrapper.getDynamicOffsetEnabled(mEndpoint);
440+
uint32_t triggerWindowSize = datapathWrapper.getTriggerWindowSize(mEndpoint);
444441

445442
Cru::ReportInfo reportInfo = {
446443
linkMap,
@@ -488,11 +485,11 @@ Cru::PacketMonitoringInfo CruBar::monitorPackets()
488485
return { linkPacketInfoMap, wrapperPacketInfoMap };
489486
}
490487

491-
void CruBar::reconfigure()
488+
/// Configures the CRU according to the parameters passed on init
489+
void CruBar::configure(bool force)
492490
{
493491
// Get current info
494492
Cru::ReportInfo reportInfo = report();
495-
496493
populateLinkMap(mLinkMap);
497494

498495
if (static_cast<uint32_t>(mClock) == reportInfo.ttcClock &&
@@ -501,86 +498,95 @@ void CruBar::reconfigure()
501498
checkPonUpstreamStatusExpected(reportInfo.ponStatusRegister, reportInfo.onuAddress) &&
502499
mCruId == reportInfo.cruId &&
503500
mDynamicOffset == reportInfo.dynamicOffset &&
504-
mTriggerWindowSize == reportInfo.triggerWindowSize) {
501+
mTriggerWindowSize == reportInfo.triggerWindowSize &&
502+
!force) {
505503
log("No need to reconfigure further");
506-
} else {
507-
log("Reconfiguring");
508-
configure();
504+
return;
509505
}
510-
}
511506

512-
/// Configures the CRU according to the parameters passed on init
513-
void CruBar::configure()
514-
{
515-
if (mLinkMap.empty()) {
516-
populateLinkMap(mLinkMap);
517-
}
507+
log("Reconfiguring");
518508

519-
/* TTC */
520509
Ttc ttc = Ttc(mPdaBar);
510+
DatapathWrapper datapathWrapper = DatapathWrapper(mPdaBar);
521511

522-
log("Setting the clock");
523-
ttc.setClock(mClock);
512+
/* TTC */
513+
if (static_cast<uint32_t>(mClock) != reportInfo.ttcClock || force) {
514+
log("Setting the clock");
515+
ttc.setClock(mClock);
516+
517+
log("Calibrating TTC");
518+
if (mClock == Clock::Ttc) {
519+
ttc.calibrateTtc();
520+
521+
if (!checkPonUpstreamStatusExpected(reportInfo.ponStatusRegister, reportInfo.onuAddress) || force) {
522+
ttc.resetFpll();
523+
if (!ttc.configurePonTx(mOnuAddress)) {
524+
log("PON TX fPLL phase scan failed", InfoLogger::InfoLogger::Error);
525+
}
526+
}
527+
}
524528

525-
log("Calibrating TTC");
526-
if (mClock == Clock::Ttc) {
527-
ttc.calibrateTtc();
529+
log("Calibrating the fPLLs");
530+
Cru::fpllref(mLinkMap, mPdaBar, 2);
531+
Cru::fpllcal(mLinkMap, mPdaBar);
528532
}
529533

530-
if (mPonUpstream) {
531-
ttc.resetFpll();
532-
if (!ttc.configurePonTx(mOnuAddress)) {
533-
log("PON TX fPLL phase scan failed", InfoLogger::InfoLogger::Error);
534-
}
534+
if (static_cast<uint32_t>(mDownstreamData) != reportInfo.downstreamData || force) {
535+
log("Setting downstream data");
536+
ttc.selectDownstreamData(mDownstreamData);
535537
}
536538

537-
log("Setting downstream data");
538-
ttc.selectDownstreamData(mDownstreamData);
539-
540539
/* GBT */
541-
log("Calibrating GBT");
542-
Gbt gbt = Gbt(mPdaBar, mLinkMap, mWrapperCount);
543-
gbt.calibrateGbt();
544-
545-
/* BSP */
546-
setCruId(mCruId);
547-
548-
disableDataTaking();
549-
550-
DatapathWrapper datapathWrapper = DatapathWrapper(mPdaBar);
551-
552-
// Disable DWRAPPER datagenerator (in case of restart)
553-
datapathWrapper.resetDataGeneratorPulse();
554-
datapathWrapper.useDataGeneratorSource(false);
555-
datapathWrapper.enableDataGenerator(false);
556-
// Disable all links
557-
datapathWrapper.setLinksEnabled(0, 0x0);
558-
datapathWrapper.setLinksEnabled(1, 0x0);
559-
560-
log("Enabling links and setting datapath mode and flow control");
561-
for (auto const& el : mLinkMap) {
562-
auto& link = el.second;
563-
if (link.enabled) {
564-
datapathWrapper.setLinkEnabled(link);
565-
datapathWrapper.setDatapathMode(link, mDatapathMode);
540+
if (!std::equal(mLinkMap.begin(), mLinkMap.end(), reportInfo.linkMap.begin()) || force) {
541+
log("Calibrating GBT");
542+
Gbt gbt = Gbt(mPdaBar, mLinkMap, mWrapperCount);
543+
544+
/* BSP */
545+
disableDataTaking();
546+
547+
// Disable DWRAPPER datagenerator (in case of restart)
548+
datapathWrapper.resetDataGeneratorPulse();
549+
datapathWrapper.useDataGeneratorSource(false);
550+
datapathWrapper.enableDataGenerator(false);
551+
// Disable all links
552+
//datapathWrapper.setLinksEnabled(0, 0x0);
553+
//datapathWrapper.setLinksEnabled(1, 0x0);
554+
555+
log("Enabling links and setting datapath mode and flow control");
556+
for (auto const& el : mLinkMap) {
557+
auto& link = el.second;
558+
auto& linkPrevState = reportInfo.linkMap.at(el.first);
559+
if (linkPrevState != link || force) {
560+
// link mismatch
561+
// -> toggle enabled status
562+
if (link.enabled != linkPrevState.enabled || force) {
563+
gbt.calibrateGbt({ std::pair<int, Link>(el.first, el.second) });
564+
// toggle enable/disable
565+
if (linkPrevState.enabled) {
566+
datapathWrapper.setLinkDisabled(link);
567+
} else {
568+
datapathWrapper.setLinkEnabled(link);
569+
}
570+
}
571+
datapathWrapper.setDatapathMode(link, mDatapathMode);
572+
}
573+
datapathWrapper.setFlowControl(link.dwrapper, mAllowRejection); //Set flow control anyway as it's per dwrapper
566574
}
567-
datapathWrapper.setFlowControl(link.dwrapper, mAllowRejection); //Set flow control anyway as it's per dwrapper
568575
}
569576

570-
log("Setting trigger window size");
571-
datapathWrapper.setTriggerWindowSize(0, mTriggerWindowSize);
572-
datapathWrapper.setTriggerWindowSize(1, mTriggerWindowSize);
577+
/* BSP */
578+
if (mCruId != reportInfo.cruId || force) {
579+
setCruId(mCruId);
580+
}
573581

574-
log("Setting packet arbitration");
575-
datapathWrapper.setPacketArbitration(mWrapperCount, 0);
582+
if (mTriggerWindowSize != reportInfo.triggerWindowSize || force) {
583+
log("Setting trigger window size");
584+
datapathWrapper.setTriggerWindowSize(mEndpoint, mTriggerWindowSize);
585+
}
576586

577-
if (mDynamicOffset) {
578-
log("Setting dynamic offset");
579-
datapathWrapper.setDynamicOffset(0, true);
580-
datapathWrapper.setDynamicOffset(1, true);
581-
} else {
582-
datapathWrapper.setDynamicOffset(0, false);
583-
datapathWrapper.setDynamicOffset(1, false);
587+
if (mDynamicOffset != reportInfo.dynamicOffset || force) {
588+
log("Toggling fixed/dynamic offset");
589+
datapathWrapper.setDynamicOffset(mEndpoint, mDynamicOffset);
584590
}
585591

586592
log("CRU configuration done.");
@@ -671,7 +677,6 @@ void CruBar::populateLinkMap(std::map<int, Link>& linkMap)
671677

672678
Gbt gbt = Gbt(mPdaBar, linkMap, mWrapperCount);
673679

674-
log("Configuring GBT");
675680
for (auto& el : linkMap) {
676681
auto& link = el.second;
677682

src/Cru/CruBar.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class CruBar final : public BarInterfaceBase
7878

7979
void resetInternalCounters();
8080
void setWrapperCount();
81-
void configure() override;
82-
void reconfigure() override;
81+
void configure(bool force = false) override;
8382
Cru::ReportInfo report();
8483
Cru::PacketMonitoringInfo monitorPackets();
8584
void emulateCtp(Cru::CtpInfo);

src/Cru/DatapathWrapper.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ void DatapathWrapper::setLinkEnabled(Link link)
4444
mPdaBar->modifyRegister(address / 4, link.dwrapperId, 1, 0x1);
4545
}
4646

47+
/// Set particular link's enabled bit
48+
void DatapathWrapper::setLinkDisabled(Link link)
49+
{
50+
uint32_t address = getDatapathWrapperBaseAddress(link.dwrapper) +
51+
Cru::Registers::DWRAPPER_GREGS.address +
52+
Cru::Registers::DWRAPPER_ENREG.address;
53+
mPdaBar->modifyRegister(address / 4, link.dwrapperId, 1, 0x0);
54+
}
55+
4756
/// Get particular link's enabled bit
4857
bool DatapathWrapper::getLinkEnabled(Link link)
4958
{
@@ -89,7 +98,7 @@ DatapathMode::type DatapathWrapper::getDatapathMode(Link link)
8998
}
9099

91100
/// Set Packet Arbitration
92-
void DatapathWrapper::setPacketArbitration(int wrapperCount, int arbitrationMode)
101+
/*void DatapathWrapper::setPacketArbitration(int wrapperCount, int arbitrationMode)
93102
{
94103
uint32_t value = 0x0;
95104
value |= (arbitrationMode << 15);
@@ -101,7 +110,7 @@ void DatapathWrapper::setPacketArbitration(int wrapperCount, int arbitrationMode
101110
102111
mPdaBar->writeRegister(address / 4, value);
103112
}
104-
}
113+
}*/
105114

106115
/// Set Flow Control
107116
void DatapathWrapper::setFlowControl(int wrapper, int allowReject)

src/Cru/DatapathWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class DatapathWrapper
3535
/// Set links with a bitmask
3636
void setLinksEnabled(uint32_t dwrapper, uint32_t mask);
3737
void setLinkEnabled(Link link);
38+
void setLinkDisabled(Link link);
3839
bool getLinkEnabled(Link link);
3940
void setDatapathMode(Link link, uint32_t mode);
4041
DatapathMode::type getDatapathMode(Link link);

src/Cru/Gbt.cxx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ void Gbt::setLoopback(Link link, uint32_t enabled)
7070
mPdaBar->modifyRegister(address / 4, 4, 1, enabled);
7171
}
7272

73-
void Gbt::calibrateGbt()
73+
void Gbt::calibrateGbt(std::map<int, Link> linkMap)
7474
{
75-
Cru::fpllref(mLinkMap, mPdaBar, 2);
76-
Cru::fpllcal(mLinkMap, mPdaBar);
77-
cdrref(2);
78-
txcal();
79-
rxcal();
75+
//Cru::fpllref(linkMap, mPdaBar, 2); //Has been bound with clock configuration
76+
//Cru::fpllcal(linkMap, mPdaBar); //same
77+
cdrref(linkMap, 2);
78+
txcal(linkMap);
79+
rxcal(linkMap);
8080
}
8181

8282
void Gbt::getGbtModes()
@@ -144,27 +144,27 @@ void Gbt::atxcal(uint32_t baseAddress)
144144
}
145145
}
146146

147-
void Gbt::cdrref(uint32_t refClock)
147+
void Gbt::cdrref(std::map<int, Link> linkMap, uint32_t refClock)
148148
{
149-
for (auto const& el : mLinkMap) {
149+
for (auto const& el : linkMap) {
150150
auto& link = el.second;
151151
//uint32_t reg141 = readRegister(getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x141)/4);
152152
uint32_t data = mPdaBar->readRegister(Cru::getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x16A + refClock) / 4);
153153
mPdaBar->writeRegister(Cru::getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x141) / 4, data);
154154
}
155155
}
156156

157-
void Gbt::rxcal()
157+
void Gbt::rxcal(std::map<int, Link> linkMap)
158158
{
159-
for (auto const& el : mLinkMap) {
159+
for (auto const& el : linkMap) {
160160
auto& link = el.second;
161161
Cru::rxcal0(mPdaBar, link.baseAddress);
162162
}
163163
}
164164

165-
void Gbt::txcal()
165+
void Gbt::txcal(std::map<int, Link> linkMap)
166166
{
167-
for (auto const& el : mLinkMap) {
167+
for (auto const& el : linkMap) {
168168
auto& link = el.second;
169169
Cru::txcal0(mPdaBar, link.baseAddress);
170170
}

src/Cru/Gbt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Gbt
4040
void setTxMode(Link link, uint32_t mode);
4141
void setRxMode(Link link, uint32_t mode);
4242
void setLoopback(Link link, uint32_t enabled);
43-
void calibrateGbt();
43+
void calibrateGbt(std::map<int, Link> linkMap);
4444
void getGbtModes();
4545
void getGbtMuxes();
4646
void getLoopbacks();
@@ -57,9 +57,9 @@ class Gbt
5757
uint32_t getAtxPllRegisterAddress(int wrapper, uint32_t reg);
5858

5959
void atxcal(uint32_t baseAddress = 0x0);
60-
void cdrref(uint32_t refClock);
61-
void txcal();
62-
void rxcal();
60+
void cdrref(std::map<int, Link> linkMap, uint32_t refClock);
61+
void txcal(std::map<int, Link> linkMap);
62+
void rxcal(std::map<int, Link> linkMap);
6363

6464
void resetStickyBit(Link link);
6565

0 commit comments

Comments
 (0)