Skip to content

Commit e8ad7cf

Browse files
committed
[status] Initial support for CRORC
1 parent 28516df commit e8ad7cf

File tree

5 files changed

+269
-92
lines changed

5 files changed

+269
-92
lines changed

src/CommandLineUtilities/ProgramStatus.cxx

Lines changed: 177 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include "Cru/Common.h"
1818
#include "Cru/Constants.h"
1919
#include "Cru/CruBar.h"
20+
#include "Crorc/Common.h"
21+
#include "Crorc/CrorcBar.h"
2022
#include "ReadoutCard/ChannelFactory.h"
2123
#include "CommandLineUtilities/Options.h"
2224
#include "CommandLineUtilities/Program.h"
@@ -62,125 +64,208 @@ class ProgramStatus : public Program
6264
};
6365

6466
std::ostringstream table;
65-
auto formatHeader = " %-9s %-16s %-10s %-14s %-15s %-10s %-14s %-14s %-8s %-19s\n";
66-
auto formatRow = " %-9s %-16s %-10s %-14s %-15s %-10s %-14.2f %-14.2f %-8s %-19.1f\n";
67-
auto header = (boost::format(formatHeader) % "Link ID" % "GBT Mode Tx/Rx" % "Loopback" % "GBT MUX" % "Datapath Mode" % "Datapath" % "RX freq(MHz)" % "TX freq(MHz)" % "Status" % "Optical power(uW)").str();
68-
auto lineFat = std::string(header.length(), '=') + '\n';
69-
auto lineThin = std::string(header.length(), '-') + '\n';
70-
71-
if (mOptions.csvOut) {
72-
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW)\n";
73-
std::cout << csvHeader;
74-
} else if (!mOptions.jsonOut) {
75-
table << lineFat << header << lineThin;
76-
}
67+
std::string formatHeader;
68+
std::string formatRow;
69+
std::string header;
70+
std::string lineFat;
71+
std::string lineThin;
7772

7873
// initialize ptree
7974
pt::ptree root;
8075

8176
auto cardId = Options::getOptionCardId(map);
82-
auto params = Parameters::makeParameters(cardId, 2); //status available on BAR2
83-
// We care for all of the links
84-
//params.setLinkMask(Parameters::linkMaskFromString("0-23"));
85-
auto bar2 = ChannelFactory().getBar(params);
77+
auto cardType = RocPciDevice(cardId).getCardDescriptor().cardType;
8678

87-
CardType::type cardType = bar2->getCardType();
8879
if (cardType == CardType::type::Crorc) {
89-
std::cout << "CRORC status report not yet supported" << std::endl;
90-
return;
91-
} else if (cardType != CardType::type::Cru) {
92-
std::cout << "Invalid card type" << std::endl;
93-
return;
94-
}
80+
formatHeader = " %-9s %-8s %-19s\n";
81+
formatRow = " %-9s %-8s %-19.1f\n";
82+
header = (boost::format(formatHeader) % "Link ID" % "Status" % "Optical power(uW)").str();
83+
lineFat = std::string(header.length(), '=') + '\n';
84+
lineThin = std::string(header.length(), '-') + '\n';
9585

96-
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2);
86+
if (mOptions.csvOut) {
87+
auto csvHeader = "Link ID,Status,Optical Power(uW),QSFP Enabled,Offset\n";
88+
std::cout << csvHeader;
89+
} else if (!mOptions.jsonOut) {
90+
table << lineFat << header << lineThin;
91+
}
9792

98-
Cru::ReportInfo reportInfo = cruBar2->report();
93+
auto params = Parameters::makeParameters(cardId, 0); //status available on BAR0
94+
auto bar0 = ChannelFactory().getBar(params);
95+
auto crorcBar0 = std::dynamic_pointer_cast<CrorcBar>(bar0);
9996

100-
std::string clock = (reportInfo.ttcClock == 0 ? "TTC" : "Local");
97+
Crorc::ReportInfo reportInfo = crorcBar0->report();
10198

102-
if (mOptions.jsonOut) {
103-
root.put("clock", clock);
104-
if (reportInfo.dynamicOffset) {
105-
root.put("offset", "Dynamic");
106-
} else {
107-
root.put("offset", "Fixed");
108-
}
109-
} else if (!mOptions.csvOut) {
110-
std::cout << "----------------------------" << std::endl;
111-
std::cout << clock << " clock | ";
112-
if (reportInfo.dynamicOffset) {
113-
std::cout << "Dynamic offset" << std::endl;
99+
/* GENERAL PARAMETERS */
100+
if (mOptions.jsonOut) {
101+
if (reportInfo.qsfpEnabled) {
102+
root.put("qsfp", "Enabled");
103+
} else {
104+
root.put("qsfp", "Disabled");
105+
}
106+
107+
if (reportInfo.dynamicOffset) {
108+
root.put("offset", "Dynamic");
109+
} else {
110+
root.put("offset", "Fixed");
111+
}
112+
} else if (mOptions.csvOut) {
113+
auto csvLine = std::string(",,,") + (reportInfo.qsfpEnabled ? "Enabled" : "Disabled") + "," + (reportInfo.dynamicOffset ? "Dynamic" : "Fixed") + "\n";
114+
std::cout << csvLine;
114115
} else {
115-
std::cout << "Fixed offset" << std::endl;
116-
}
117-
std::cout << "----------------------------" << std::endl;
118-
}
116+
std::cout << "----------------------------" << std::endl;
117+
if (reportInfo.qsfpEnabled) {
118+
std::cout << "QSFP enabled | ";
119+
} else {
120+
std::cout << "QSFP disabled | ";
121+
}
119122

120-
for (const auto& el : reportInfo.linkMap) {
121-
auto link = el.second;
122-
int globalId = el.first; //Use the "new" link mapping
123-
std::string gbtTxMode = GbtMode::toString(link.gbtTxMode);
124-
std::string gbtRxMode = GbtMode::toString(link.gbtRxMode);
125-
std::string gbtTxRxMode = gbtTxMode + "/" + gbtRxMode;
126-
std::string loopback = (link.loopback == false ? "None" : "Enabled");
127-
128-
std::string downstreamData;
129-
if (reportInfo.downstreamData == Cru::DATA_CTP) {
130-
downstreamData = "CTP";
131-
} else if (reportInfo.downstreamData == Cru::DATA_PATTERN) {
132-
downstreamData = "PATTERN";
133-
} else if (reportInfo.downstreamData == Cru::DATA_MIDTRG) {
134-
downstreamData = "MIDTRG";
123+
if (reportInfo.dynamicOffset) {
124+
std::cout << "Dynamic offset" << std::endl;
125+
} else {
126+
std::cout << "Fixed offset" << std::endl;
127+
}
128+
std::cout << "----------------------------" << std::endl;
135129
}
136130

137-
std::string gbtMux = GbtMux::toString(link.gbtMux);
138-
if (gbtMux == "TTC") {
139-
gbtMux += ":" + downstreamData;
140-
}
131+
/* PARAMETERS PER LINK */
132+
for (const auto& el : reportInfo.linkMap) {
133+
auto link = el.second;
134+
int id = el.first;
141135

142-
std::string datapathMode = DatapathMode::toString(link.datapathMode);
136+
std::string linkStatus = link.status == Crorc::LinkStatus::Up ? "UP" : "DOWN";
137+
float opticalPower = link.opticalPower;
143138

144-
std::string enabled = (link.enabled) ? "Enabled" : "Disabled";
139+
if (mOptions.jsonOut) {
140+
pt::ptree linkNode;
145141

146-
float rxFreq = link.rxFreq;
147-
float txFreq = link.txFreq;
142+
// add kv pairs for this card
143+
linkNode.put("status", linkStatus);
144+
linkNode.put("opticalPower", enforcePrecision(opticalPower));
148145

149-
std::string linkStatus;
150-
if (link.stickyBit == Cru::LinkStatus::Up) {
151-
linkStatus = "UP";
152-
} else if (link.stickyBit == Cru::LinkStatus::UpWasDown) {
153-
linkStatus = "UP (was DOWN)";
154-
} else if (link.stickyBit == Cru::LinkStatus::Down) {
155-
linkStatus = "DOWN";
146+
// add the link node to the tree
147+
root.add_child(std::to_string(id), linkNode);
148+
} else if (mOptions.csvOut) {
149+
auto csvLine = std::to_string(id) + "," + linkStatus + "," + std::to_string(opticalPower) + "\n";
150+
std::cout << csvLine;
151+
} else {
152+
auto format = boost::format(formatRow) % id % linkStatus % opticalPower;
153+
table << format;
154+
}
156155
}
156+
} else if (cardType == CardType::type::Cru) {
157+
formatHeader = " %-9s %-16s %-10s %-14s %-15s %-10s %-14s %-14s %-8s %-19s\n";
158+
formatRow = " %-9s %-16s %-10s %-14s %-15s %-10s %-14.2f %-14.2f %-8s %-19.1f\n";
159+
header = (boost::format(formatHeader) % "Link ID" % "GBT Mode Tx/Rx" % "Loopback" % "GBT MUX" % "Datapath Mode" % "Datapath" % "RX freq(MHz)" % "TX freq(MHz)" % "Status" % "Optical power(uW)").str();
160+
lineFat = std::string(header.length(), '=') + '\n';
161+
lineThin = std::string(header.length(), '-') + '\n';
157162

158-
float opticalPower = link.opticalPower;
163+
auto params = Parameters::makeParameters(cardId, 2); //status available on BAR2
164+
auto bar2 = ChannelFactory().getBar(params);
165+
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2);
159166

167+
if (mOptions.csvOut) {
168+
auto csvHeader = "Link ID,GBT Mode,Loopback,GBT Mux,Datapath Mode,Datapath,RX Freq(MHz),TX Freq(MHz),Status,Optical Power(uW),Clock,Offset\n";
169+
std::cout << csvHeader;
170+
} else if (!mOptions.jsonOut) {
171+
table << lineFat << header << lineThin;
172+
}
173+
174+
Cru::ReportInfo reportInfo = cruBar2->report();
175+
176+
std::string clock = (reportInfo.ttcClock == 0 ? "TTC" : "Local");
177+
178+
/* GENERAL PARAMETERS */
160179
if (mOptions.jsonOut) {
161-
pt::ptree linkNode;
162-
163-
// add kv pairs for this card
164-
linkNode.put("gbtMode", gbtTxRxMode);
165-
linkNode.put("loopback", loopback);
166-
linkNode.put("gbtMux", gbtMux);
167-
linkNode.put("datapathMode", datapathMode);
168-
linkNode.put("datapath", enabled);
169-
linkNode.put("rxFreq", enforcePrecision(rxFreq));
170-
linkNode.put("txFreq", enforcePrecision(txFreq));
171-
linkNode.put("status", linkStatus);
172-
linkNode.put("opticalPower", enforcePrecision(opticalPower));
173-
174-
// add the link node to the tree
175-
root.add_child(std::to_string(globalId), linkNode);
180+
root.put("clock", clock);
181+
if (reportInfo.dynamicOffset) {
182+
root.put("offset", "Dynamic");
183+
} else {
184+
root.put("offset", "Fixed");
185+
}
176186
} else if (mOptions.csvOut) {
177-
auto csvLine = std::to_string(globalId) + "," + gbtTxRxMode + "," + loopback + "," + gbtMux + "," + datapathMode + "," + enabled + "," +
178-
std::to_string(rxFreq) + "," + std::to_string(txFreq) + "," + linkStatus + "," + std::to_string(opticalPower) + "\n";
187+
auto csvLine = ",,,,,,,,,," + clock + "," + (reportInfo.dynamicOffset ? "Dynamic" : "Fixed") + "\n";
179188
std::cout << csvLine;
180189
} else {
181-
auto format = boost::format(formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled % rxFreq % txFreq % linkStatus % opticalPower;
182-
table << format;
190+
std::cout << "----------------------------" << std::endl;
191+
std::cout << clock << " clock | ";
192+
if (reportInfo.dynamicOffset) {
193+
std::cout << "Dynamic offset" << std::endl;
194+
} else {
195+
std::cout << "Fixed offset" << std::endl;
196+
}
197+
std::cout << "----------------------------" << std::endl;
183198
}
199+
200+
/* PARAMETERS PER LINK */
201+
for (const auto& el : reportInfo.linkMap) {
202+
auto link = el.second;
203+
int globalId = el.first; //Use the "new" link mapping
204+
std::string gbtTxMode = GbtMode::toString(link.gbtTxMode);
205+
std::string gbtRxMode = GbtMode::toString(link.gbtRxMode);
206+
std::string gbtTxRxMode = gbtTxMode + "/" + gbtRxMode;
207+
std::string loopback = (link.loopback == false ? "None" : "Enabled");
208+
209+
std::string downstreamData;
210+
if (reportInfo.downstreamData == Cru::DATA_CTP) {
211+
downstreamData = "CTP";
212+
} else if (reportInfo.downstreamData == Cru::DATA_PATTERN) {
213+
downstreamData = "PATTERN";
214+
} else if (reportInfo.downstreamData == Cru::DATA_MIDTRG) {
215+
downstreamData = "MIDTRG";
216+
}
217+
218+
std::string gbtMux = GbtMux::toString(link.gbtMux);
219+
if (gbtMux == "TTC") {
220+
gbtMux += ":" + downstreamData;
221+
}
222+
223+
std::string datapathMode = DatapathMode::toString(link.datapathMode);
224+
225+
std::string enabled = (link.enabled) ? "Enabled" : "Disabled";
226+
227+
float rxFreq = link.rxFreq;
228+
float txFreq = link.txFreq;
229+
230+
std::string linkStatus;
231+
if (link.stickyBit == Cru::LinkStatus::Up) {
232+
linkStatus = "UP";
233+
} else if (link.stickyBit == Cru::LinkStatus::UpWasDown) {
234+
linkStatus = "UP (was DOWN)";
235+
} else if (link.stickyBit == Cru::LinkStatus::Down) {
236+
linkStatus = "DOWN";
237+
}
238+
239+
float opticalPower = link.opticalPower;
240+
241+
if (mOptions.jsonOut) {
242+
pt::ptree linkNode;
243+
244+
// add kv pairs for this card
245+
linkNode.put("gbtMode", gbtTxRxMode);
246+
linkNode.put("loopback", loopback);
247+
linkNode.put("gbtMux", gbtMux);
248+
linkNode.put("datapathMode", datapathMode);
249+
linkNode.put("datapath", enabled);
250+
linkNode.put("rxFreq", enforcePrecision(rxFreq));
251+
linkNode.put("txFreq", enforcePrecision(txFreq));
252+
linkNode.put("status", linkStatus);
253+
linkNode.put("opticalPower", enforcePrecision(opticalPower));
254+
255+
// add the link node to the tree
256+
root.add_child(std::to_string(globalId), linkNode);
257+
} else if (mOptions.csvOut) {
258+
auto csvLine = std::to_string(globalId) + "," + gbtTxRxMode + "," + loopback + "," + gbtMux + "," + datapathMode + "," + enabled + "," +
259+
std::to_string(rxFreq) + "," + std::to_string(txFreq) + "," + linkStatus + "," + std::to_string(opticalPower) + "\n";
260+
std::cout << csvLine;
261+
} else {
262+
auto format = boost::format(formatRow) % globalId % gbtTxRxMode % loopback % gbtMux % datapathMode % enabled % rxFreq % txFreq % linkStatus % opticalPower;
263+
table << format;
264+
}
265+
}
266+
} else {
267+
std::cout << "Invalid card type" << std::endl;
268+
return;
184269
}
185270

186271
if (mOptions.jsonOut) {

src/Crorc/Common.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file Crorc/Common.h
12+
/// \brief Definition of common CRORC structs and utilities
13+
///
14+
/// \author Kostas Alexopoulos ([email protected])
15+
16+
#ifndef ALICEO2_READOUTCARD_CRORC_COMMON_H_
17+
#define ALICEO2_READOUTCARD_CRORC_COMMON_H_
18+
19+
namespace AliceO2
20+
{
21+
namespace roc
22+
{
23+
namespace Crorc
24+
{
25+
26+
enum LinkStatus {
27+
Up,
28+
Down,
29+
};
30+
31+
struct Link {
32+
LinkStatus status = LinkStatus::Down;
33+
float opticalPower = 0.0;
34+
};
35+
36+
struct ReportInfo {
37+
std::map<int, Link> linkMap;
38+
uint16_t crorcId;
39+
bool dynamicOffset;
40+
bool qsfpEnabled;
41+
};
42+
43+
} // namespace Crorc
44+
} // namespace roc
45+
} // namespace AliceO2
46+
47+
#endif // ALICEO2_READOUTCARD_CRORC_COMMON_H_

src/Crorc/Constants.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ static constexpr Register CFG_CONTROL(0x000001f0);
366366

367367
// Register that contains the firmware hash
368368
static constexpr Register FIRMWARE_HASH(0x0000019C);
369+
370+
// Channel Control & Status Register
371+
static constexpr Register C_CSR(0x00000010);
372+
373+
// At bit 13
374+
static constexpr uint32_t LINK_DOWN(0x00002000);
375+
369376
} // namespace Registers
370377
} //namespace Crorc
371378

0 commit comments

Comments
 (0)