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
403404Cru::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
0 commit comments