Skip to content

Commit b027d9f

Browse files
committed
Update for new physical-logical CRU link mapping
1 parent 49671ed commit b027d9f

File tree

7 files changed

+71
-60
lines changed

7 files changed

+71
-60
lines changed

src/CommandLineUtilities/ProgramStatus.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ class ProgramStatus: public Program
8080
std::cout << clock << " clock" << std::endl;
8181
std::cout << "------------" << std::endl;
8282

83-
// TODO: Sort according to linkID
84-
for (const auto& link : reportInfo.linkList) {
85-
int globalId = link.id + link.bank*6;
83+
for (const auto& el : reportInfo.linkMap) {
84+
auto link = el.second;
85+
int globalId = el.first; //Use the "new" link mapping
8686
std::string gbtTxMode = (link.gbtTxMode == Cru::GBT_MODE_WB ? "WB" : "GBT");
8787
std::string gbtRxMode = (link.gbtRxMode == Cru::GBT_MODE_WB ? "WB" : "GBT");
8888
std::string gbtTxRxMode = gbtTxMode + "/" + gbtRxMode;

src/Cru/Common.cxx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,13 @@ uint32_t waitForBit(std::shared_ptr<Pda::PdaBar> pdaBar,uint32_t address, uint32
225225
return bit;
226226
}
227227

228-
void fpllref(std::vector<Link> linkList, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress) //baseAddress = 0
228+
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress) //baseAddress = 0
229229
{
230230
if (baseAddress == 0){
231231
int prevWrapper = -1;
232232
int prevBank = -1;
233-
for (auto const& link: linkList) {
233+
for (auto const& el: linkMap) {
234+
auto& link = el.second;
234235
if ((prevWrapper != link.wrapper) || (prevBank != link.bank)) {
235236
Cru::fpllref0(mPdaBar, getBankPllRegisterAddress(link.wrapper, link.bank), refClock);
236237
prevWrapper = link.wrapper;
@@ -241,12 +242,13 @@ void fpllref(std::vector<Link> linkList, std::shared_ptr<Pda::PdaBar> mPdaBar, u
241242
Cru::fpllref0(mPdaBar, baseAddress, refClock);
242243
}
243244

244-
void fpllcal(std::vector<Link> linkList, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress, bool configCompensation) //baseAddress = 0, configCompensation = true
245+
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress, bool configCompensation) //baseAddress = 0, configCompensation = true
245246
{
246247
if (baseAddress == 0){
247248
int prevWrapper = -1;
248249
int prevBank = -1;
249-
for (auto const& link: linkList) {
250+
for (auto const& el: linkMap) {
251+
auto& link = el.second;
250252
if ((prevWrapper != link.wrapper) || (prevBank!= link.bank)) {
251253
Cru::fpllcal0(mPdaBar, getBankPllRegisterAddress(link.wrapper, link.bank), configCompensation);
252254
prevWrapper = link.wrapper;

src/Cru/Common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct Link {
6161
};
6262

6363
struct ReportInfo {
64-
std::vector<Link> linkList;
64+
std::map<int, Link> linkMap;
6565
uint32_t ttcClock;
6666
uint32_t downstreamData;
6767
};
@@ -73,8 +73,8 @@ void txcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress);
7373
void rxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress);
7474
void fpllref0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, uint32_t refClock);
7575
void fpllcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, bool configCompensation=true);
76-
void fpllref(std::vector<Link> linkList, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress=0);
77-
void fpllcal(std::vector<Link> linkList, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress=0, bool configCompensation=true);
76+
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress=0);
77+
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress=0, bool configCompensation=true);
7878
uint32_t getBankPllRegisterAddress(int wrapper, int bank);
7979
uint32_t waitForBit(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t address, uint32_t position, uint32_t value);
8080

src/Cru/CruBar.cxx

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <chrono>
1919
#include <fstream>
2020
#include <iostream>
21+
#include <map>
2122
#include <thread>
2223
#include "CruBar.h"
2324
#include "Gbt.h"
@@ -402,19 +403,18 @@ void CruBar::setDataGeneratorRandomSizeBits(uint32_t& bits, bool enabled)
402403
/// Reports the CRU status
403404
Cru::ReportInfo CruBar::report()
404405
{
405-
std::vector<Link> linkList = initializeLinkList();
406-
/*for (auto const& link: mLinkList)
407-
mLogger << "link: " << link.id;*/
406+
std::map<int, Link> linkMap = initializeLinkMap();
408407

409-
// Update linkList
410-
Gbt gbt = Gbt(mPdaBar, linkList, mWrapperCount);
408+
// Update linkMap
409+
Gbt gbt = Gbt(mPdaBar, linkMap, mWrapperCount);
411410
gbt.getGbtModes();
412411
gbt.getGbtMuxes();
413412
gbt.getLoopbacks();
414413

415414
DatapathWrapper datapathWrapper = DatapathWrapper(mPdaBar);
416415

417-
for (auto& link: linkList) {
416+
for (auto& el: linkMap) {
417+
auto& link = el.second;
418418
link.datapathMode = datapathWrapper.getDatapathMode(link);
419419
link.enabled = datapathWrapper.getLinkEnabled(link);
420420
}
@@ -424,7 +424,7 @@ Cru::ReportInfo CruBar::report()
424424
uint32_t downstreamData = ttc.getDownstreamData();
425425

426426
Cru::ReportInfo reportInfo = {
427-
linkList,
427+
linkMap,
428428
clock,
429429
downstreamData
430430
};
@@ -437,11 +437,11 @@ void CruBar::reconfigure()
437437
// Get current info
438438
Cru::ReportInfo reportInfo = report();
439439

440-
populateLinkList(mLinkList);
440+
populateLinkMap(mLinkMap);
441441

442442
if (static_cast<uint32_t>(mClock) == reportInfo.ttcClock &&
443443
static_cast<uint32_t>(mDownstreamData) == reportInfo.downstreamData &&
444-
std::equal(mLinkList.begin(), mLinkList.end(), reportInfo.linkList.begin())) {
444+
std::equal(mLinkMap.begin(), mLinkMap.end(), reportInfo.linkMap.begin())) {
445445
log("No need to reconfigure further");
446446
} else {
447447
log("Reconfiguring");
@@ -455,13 +455,13 @@ void CruBar::configure()
455455
bool ponUpstream = false;
456456
uint32_t onuAddress = 0xbadcafe;
457457

458-
if (mLinkList.empty()) {
459-
populateLinkList(mLinkList);
458+
if (mLinkMap.empty()) {
459+
populateLinkMap(mLinkMap);
460460
}
461461

462462
/* GBT */
463463
log("Calibrating GBT");
464-
Gbt gbt = Gbt(mPdaBar, mLinkList, mWrapperCount);
464+
Gbt gbt = Gbt(mPdaBar, mLinkMap, mWrapperCount);
465465
gbt.calibrateGbt();
466466

467467
/* TTC */
@@ -492,7 +492,8 @@ void CruBar::configure()
492492
datapathWrapper.setLinksEnabled(1, 0x0);
493493

494494
log("Enabling links and setting datapath mode");
495-
for (auto const& link: mLinkList) {
495+
for (auto const& el: mLinkMap) {
496+
auto& link = el.second;
496497
if (link.enabled) {
497498
datapathWrapper.setLinkEnabled(link);
498499
datapathWrapper.setDatapathMode(link, mDatapathMode);
@@ -525,8 +526,8 @@ void CruBar::setWrapperCount()
525526
mWrapperCount = wrapperCount;
526527
}
527528

528-
/// Returns a LinkList with indexes and base addresses initialized
529-
std::vector<Link> CruBar::initializeLinkList()
529+
/// Returns a LinkMap with indexes and base addresses initialized
530+
std::map<int, Link> CruBar::initializeLinkMap()
530531
{
531532
std::vector<Link> links;
532533
if (mWrapperCount == 0) {
@@ -564,36 +565,35 @@ std::vector<Link> CruBar::initializeLinkList()
564565
}
565566
}
566567

567-
std::vector<Link> newLinks(sizeof(links));
568+
// Calculate "new" positions to accommodate CRU FW v3.0.0 link mapping
569+
std::map<int, Link> newLinkMap;
568570
for(int i=0; i<links.size(); i++) {
569571
Link link = links.at(i);
570-
int newpos = (i-link.bank*6) * 2 + 12*(link.bank/2) + (link.bank %2);
571-
newLinks[newpos] = link;
572+
int newPos = (i-link.bank*6) * 2 + 12*(int)(link.bank/2) + (link.bank %2);
573+
link.dwrapperId = newPos % 12;
574+
newLinkMap.insert({newPos, link});
572575
}
573576

574-
for(auto link: links) {
575-
std::cout << link.id << std::endl;
576-
}
577-
std::cout << "====" << std::endl;
578-
for (auto link: newLinks) {
579-
std::cout << link.id << std::endl;
580-
std::cout << std::hex << link.baseAddress << std::endl;
581-
}
582-
return newLinks;
583-
//return links;
577+
578+
/*for(auto el : newLinkMap)
579+
std::cout << el.first << " " << el.second.bank << " " << el.second.id << std::endl;*/
580+
581+
return newLinkMap;
584582
}
585583

586-
/// Initializes and Populates the linkList with the GBT configuration parameters
584+
/// Initializes and Populates the linkMap with the GBT configuration parameters
587585
/// Also runs the corresponding configuration
588-
void CruBar::populateLinkList(std::vector<Link> &linkList)
586+
void CruBar::populateLinkMap(std::map<int, Link> &linkMap)
589587
{
590-
linkList = initializeLinkList();
588+
linkMap = initializeLinkMap();
591589

592-
Gbt gbt = Gbt(mPdaBar, linkList, mWrapperCount);
590+
Gbt gbt = Gbt(mPdaBar, linkMap, mWrapperCount);
593591

594592
log("Configuring GBT");
595-
for (auto &link: linkList) {
596-
if (!(mLinkMask.find(link.globalId) == mLinkMask.end())) {
593+
for (auto& el: linkMap) {
594+
auto& link = el.second;
595+
596+
if (!(mLinkMask.find(el.first) == mLinkMask.end())) {
597597
link.enabled = true;
598598

599599
gbt.setInternalDataGenerator(link, 0);
@@ -607,7 +607,7 @@ void CruBar::populateLinkList(std::vector<Link> &linkList)
607607
link.loopback = mLoopback;
608608
gbt.setLoopback(link, link.loopback);
609609

610-
auto gbtMuxMapElement = mGbtMuxMap.find(link.globalId);
610+
auto gbtMuxMapElement = mGbtMuxMap.find(el.first);
611611
if (gbtMuxMapElement != mGbtMuxMap.end()) { // Different MUXs per link
612612
link.gbtMux = gbtMuxMapElement->second;
613613
} else { // Specific MUX not found

src/Cru/CruBar.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <cstddef>
2121
#include <set>
22+
#include <map>
2223
#include <boost/optional/optional.hpp>
2324
#include "BarInterfaceBase.h"
2425
#include "Common.h"
@@ -102,8 +103,8 @@ class CruBar final : public BarInterfaceBase
102103
uint32_t getFirmwareTime();
103104
uint32_t getFpgaChipHigh();
104105
uint32_t getFpgaChipLow();
105-
std::vector<Link> initializeLinkList();
106-
void populateLinkList(std::vector<Link> &linkList);
106+
std::map<int, Link> initializeLinkMap();
107+
void populateLinkMap(std::map<int, Link> &linkMap);
107108

108109
int getDdgBurstLength();
109110
//void checkParameters();
@@ -119,7 +120,7 @@ class CruBar final : public BarInterfaceBase
119120
uint32_t mLoopback;
120121
int mWrapperCount = 0;
121122
std::set<uint32_t> mLinkMask;
122-
std::vector<Link> mLinkList;
123+
std::map<int, Link> mLinkMap;
123124
std::map<uint32_t, uint32_t> mRegisterMap;
124125
std::map<uint32_t, GbtMux::type> mGbtMuxMap;
125126

src/Cru/Gbt.cxx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace roc {
2323

2424
using Link = Cru::Link;
2525

26-
Gbt::Gbt(std::shared_ptr<Pda::PdaBar> pdaBar, std::vector<Link> &linkList, int wrapperCount) :
26+
Gbt::Gbt(std::shared_ptr<Pda::PdaBar> pdaBar, std::map<int, Link> &linkMap, int wrapperCount) :
2727
mPdaBar(pdaBar),
28-
mLinkList(linkList),
28+
mLinkMap(linkMap),
2929
mWrapperCount(wrapperCount)
3030
{
3131
}
@@ -70,16 +70,17 @@ void Gbt::setLoopback(Link link, uint32_t enabled)
7070

7171
void Gbt::calibrateGbt()
7272
{
73-
Cru::fpllref(mLinkList, mPdaBar, 2);
74-
Cru::fpllcal(mLinkList, mPdaBar);
73+
Cru::fpllref(mLinkMap, mPdaBar, 2);
74+
Cru::fpllcal(mLinkMap, mPdaBar);
7575
cdrref(2);
7676
txcal();
7777
rxcal();
7878
}
7979

8080
void Gbt::getGbtModes()
8181
{
82-
for (auto& link: mLinkList) {
82+
for (auto& el : mLinkMap) {
83+
auto& link = el.second;
8384
uint32_t rxControl = mPdaBar->readRegister(getRxControlAddress(link)/4);
8485
if (((rxControl >> 8) & 0x1) == Cru::GBT_MODE_WB) { //TODO: Change with Constants
8586
link.gbtRxMode = GbtMode::type::Wb;
@@ -98,7 +99,9 @@ void Gbt::getGbtModes()
9899

99100
void Gbt::getGbtMuxes()
100101
{
101-
for (auto& link: mLinkList) { uint32_t txMux = mPdaBar->readRegister((Cru::Registers::GBT_MUX_SELECT.address + link.bank * 4)/4);
102+
for (auto& el: mLinkMap) {
103+
auto& link = el.second;
104+
uint32_t txMux = mPdaBar->readRegister((Cru::Registers::GBT_MUX_SELECT.address + link.bank * 4)/4);
102105
txMux = (txMux >> (link.id*4)) & 0x3;
103106
if (txMux == Cru::GBT_MUX_TTC) {
104107
link.gbtMux = GbtMux::type::Ttc;
@@ -112,7 +115,8 @@ void Gbt::getGbtMuxes()
112115

113116
void Gbt::getLoopbacks()
114117
{
115-
for (auto& link: mLinkList) {
118+
for (auto& el: mLinkMap) {
119+
auto& link = el.second;
116120
uint32_t loopback = mPdaBar->readRegister(getSourceSelectAddress(link)/4);
117121
if (((loopback >> 4) & 0x1) == 0x1) {
118122
link.loopback = true;
@@ -136,7 +140,8 @@ void Gbt::atxcal(uint32_t baseAddress)
136140

137141
void Gbt::cdrref(uint32_t refClock)
138142
{
139-
for (auto const& link: mLinkList) {
143+
for (auto const& el: mLinkMap) {
144+
auto& link = el.second;
140145
//uint32_t reg141 = readRegister(getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x141)/4);
141146
uint32_t data = mPdaBar->readRegister(Cru::getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x16A + refClock)/4);
142147
mPdaBar->writeRegister(Cru::getXcvrRegisterAddress(link.wrapper, link.bank, link.id, 0x141)/4, data);
@@ -145,14 +150,16 @@ void Gbt::cdrref(uint32_t refClock)
145150

146151
void Gbt::rxcal()
147152
{
148-
for (auto const& link: mLinkList) {
153+
for (auto const& el: mLinkMap) {
154+
auto& link = el.second;
149155
Cru::rxcal0(mPdaBar, link.baseAddress);
150156
}
151157
}
152158

153159
void Gbt::txcal()
154160
{
155-
for (auto const& link: mLinkList) {
161+
for (auto const& el: mLinkMap) {
162+
auto& link = el.second;
156163
Cru::txcal0(mPdaBar, link.baseAddress);
157164
}
158165
}

src/Cru/Gbt.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Gbt {
2727
using Link = Cru::Link;
2828

2929
public:
30-
Gbt(std::shared_ptr<Pda::PdaBar> pdaBar, std::vector<Link> &mLinkList, int wrapperCount);
30+
//Gbt(std::shared_ptr<Pda::PdaBar> pdaBar, std::vector<Link> &mLinkList, int wrapperCount);
31+
Gbt(std::shared_ptr<Pda::PdaBar> pdaBar, std::map<int, Link> &mLinkMap, int wrapperCount);
3132
void setMux(Link link, uint32_t mux);
3233
void setInternalDataGenerator(Link link, uint32_t value);
3334
void setTxMode(Link link, uint32_t mode);
@@ -50,7 +51,7 @@ class Gbt {
5051
void rxcal();
5152

5253
std::shared_ptr<Pda::PdaBar> mPdaBar;
53-
std::vector<Link> &mLinkList;
54+
std::map<int, Link> &mLinkMap;
5455
int mWrapperCount;
5556
};
5657
} // namespace roc

0 commit comments

Comments
 (0)