forked from AliceO2Group/ReadoutCard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgramConfig.cxx
259 lines (240 loc) · 11.6 KB
/
ProgramConfig.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file ProgramConfig.cxx
/// \brief Tool that configures the CRU.
///
/// \author Kostas Alexopoulos (kostas.alexopoulos@cern.ch)
#include <fstream>
#include <iostream>
#include "CommandLineUtilities/Options.h"
#include "CommandLineUtilities/Program.h"
#include "Cru/CruBar.h"
#include "ReadoutCard/CardConfigurator.h"
#include "ReadoutCard/ChannelFactory.h"
#include "ReadoutCard/Exception.h"
#include "ReadoutCard/FirmwareChecker.h"
#include "RocPciDevice.h"
using namespace AliceO2::roc::CommandLineUtilities;
using namespace AliceO2::roc;
using namespace AliceO2::InfoLogger;
namespace po = boost::program_options;
class ProgramConfig : public Program
{
public:
virtual Description getDescription()
{
return { "Config", "Configure the ReadoutCard(s)",
"roc-config --config-uri ini:///home/flp/roc.cfg\n"
"roc-config --id 42:00.0 --links 0-23 --clock local --datapathmode packet --loopback --gbtmux ttc #CRU\n"
"roc-config --id #0 --crorc-id 0x42 --dyn-offset --tf-length 255 #CRORC\n" };
}
virtual void addOptions(boost::program_options::options_description& options)
{
options.add_options()("allow-rejection",
po::bool_switch(&mOptions.allowRejection),
"Flag to allow HBF rejection");
options.add_options()("clock",
po::value<std::string>(&mOptions.clock)->default_value("LOCAL"),
"Clock [LOCAL, TTC]");
options.add_options()("crorc-id",
po::value<std::string>(&mOptions.crorcId)->default_value("0x0"),
"12-bit CRORC ID");
options.add_options()("cru-id",
po::value<std::string>(&mOptions.cruId)->default_value("0x0"),
"12-bit CRU ID");
options.add_options()("datapathmode",
po::value<std::string>(&mOptions.datapathMode)->default_value("PACKET"),
"DatapathMode [PACKET, CONTINUOUS]");
options.add_options()("downstreamdata",
po::value<std::string>(&mOptions.downstreamData)->default_value("CTP"),
"DownstreamData [CTP, PATTERN, MIDTRG]");
options.add_options()("gbtmode",
po::value<std::string>(&mOptions.gbtMode)->default_value("GBT"),
"GBT MODE [GBT, WB]");
options.add_options()("gbtmux",
po::value<std::string>(&mOptions.gbtMux)->default_value("TTC"),
"GBT MUX [TTC, DDG, SWT]");
options.add_options()("links",
po::value<std::string>(&mOptions.links)->default_value("0"),
"Links to enable");
options.add_options()("config-uri",
po::value<std::string>(&mOptions.configUri)->default_value(""),
"Configuration URI ('ini://[path]', 'json://[path]' or 'consul://[host][:port][/path]'");
options.add_options()("loopback",
po::bool_switch(&mOptions.linkLoopbackEnabled),
"Flag to enable link loopback for DDG");
options.add_options()("pon-upstream",
po::bool_switch(&mOptions.ponUpstreamEnabled),
"Flag to enable use of the PON upstream");
options.add_options()("dyn-offset",
po::bool_switch(&mOptions.dynamicOffsetEnabled),
"Flag to enable the dynamic offset");
options.add_options()("onu-address",
po::value<uint32_t>(&mOptions.onuAddress)->default_value(0),
"ONU address for PON upstream");
options.add_options()("config-all",
po::bool_switch(&mOptions.configAll),
"Flag to configure all cards with default parameters on startup");
options.add_options()("force-config",
po::bool_switch(&mOptions.forceConfig),
"Flag to force configuration and not check if the configuration is already present");
options.add_options()("bypass-fw-check",
po::bool_switch(&mOptions.bypassFirmwareCheck),
"Flag to force configuration, bypassing the firmware checker");
options.add_options()("trigger-window-size",
po::value<uint32_t>(&mOptions.triggerWindowSize),
"The size of the trigger window in GBT words");
options.add_options()("tf-length",
po::value<uint32_t>(&mOptions.timeFrameLength),
"Sets the length of the Time Frame");
options.add_options()("no-tf-detection",
po::bool_switch(&mOptions.timeFrameDetectionDisabled),
"Flag to enable the Time Frame Detection");
options.add_options()("gen-cfg-file",
po::value<std::string>(&mOptions.genConfigFile),
"If set generates a configuration file from the command line options. [DOES NOT CONFIGURE]");
options.add_options()("no-gbt",
po::bool_switch(&mOptions.noGbt),
"Flag to switch off GBT");
options.add_options()("user-logic",
po::bool_switch(&mOptions.userLogicEnabled),
"Flag to enable the User Logic link");
Options::addOptionCardId(options);
}
virtual void run(const boost::program_options::variables_map& map)
{
// Configure all cards found - Normally used during boot
if (mOptions.configAll) {
std::cout << "Running RoC Configuration for all cards" << std::endl;
std::vector<CardDescriptor> cardsFound;
if (mOptions.configUri == "") {
std::cout << "A configuration URI is necessary with the startup-config flag set" << std::endl;
return;
}
cardsFound = RocPciDevice::findSystemDevices();
for (auto const& card : cardsFound) {
std::cout << " __== " << card.pciAddress.toString() << " ==__ " << std::endl;
auto params = Parameters::makeParameters(card.pciAddress, 2);
if (!mOptions.bypassFirmwareCheck) {
try {
FirmwareChecker().checkFirmwareCompatibility(params);
CardConfigurator(card.pciAddress, mOptions.configUri, mOptions.forceConfig);
} catch (const Exception& e) {
std::cout << boost::diagnostic_information(e) << std::endl;
}
}
}
return;
}
// Configure specific card
auto cardId = Options::getOptionCardId(map); //TODO: Parameters not planned for the CRORC should throw an exception when used
if (!mOptions.bypassFirmwareCheck) {
try {
FirmwareChecker().checkFirmwareCompatibility(cardId);
} catch (const Exception& e) {
std::cout << boost::diagnostic_information(e) << std::endl;
return;
}
}
if (mOptions.configUri == "") {
auto params = Parameters::makeParameters(cardId, 2);
params.setLinkMask(Parameters::linkMaskFromString(mOptions.links));
params.setAllowRejection(mOptions.allowRejection);
params.setClock(Clock::fromString(mOptions.clock));
params.setCrorcId(strtoul(mOptions.crorcId.c_str(), NULL, 16)); //TODO: Clean up common / per type parameters
params.setCruId(strtoul(mOptions.cruId.c_str(), NULL, 16));
params.setDatapathMode(DatapathMode::fromString(mOptions.datapathMode));
params.setDownstreamData(DownstreamData::fromString(mOptions.downstreamData));
params.setGbtMode(GbtMode::fromString(mOptions.gbtMode));
params.setGbtMux(GbtMux::fromString(mOptions.gbtMux));
params.setLinkLoopbackEnabled(mOptions.linkLoopbackEnabled);
params.setPonUpstreamEnabled(mOptions.ponUpstreamEnabled);
params.setDynamicOffsetEnabled(mOptions.dynamicOffsetEnabled);
params.setOnuAddress(mOptions.onuAddress);
params.setTriggerWindowSize(mOptions.triggerWindowSize);
params.setGbtEnabled(!mOptions.noGbt);
params.setUserLogicEnabled(mOptions.userLogicEnabled);
params.setTimeFrameLength(mOptions.timeFrameLength);
params.setTimeFrameDetectionEnabled(!mOptions.timeFrameDetectionDisabled);
// Generate a configuration file base on the parameters provided
if (mOptions.genConfigFile != "") { //TODO: To be updated for the CRORC
std::cout << "Generating a configuration file at: " << mOptions.genConfigFile << std::endl;
std::ofstream cfgFile;
cfgFile.open(mOptions.genConfigFile);
cfgFile << "[cru]\n";
cfgFile << "allowRejection=" << std::boolalpha << mOptions.allowRejection << "\n";
cfgFile << "clock=" << mOptions.clock << "\n";
cfgFile << "cruId=" << mOptions.cruId << "\n";
cfgFile << "datapathMode=" << mOptions.datapathMode << "\n";
cfgFile << "loopback=" << std::boolalpha << mOptions.linkLoopbackEnabled << "\n";
cfgFile << "gbtMode=" << mOptions.gbtMode << "\n";
cfgFile << "downstreamData=" << mOptions.downstreamData << "\n";
cfgFile << "ponUpstream=" << std::boolalpha << mOptions.ponUpstreamEnabled << "\n";
cfgFile << "onuAddress=" << mOptions.onuAddress << "\n";
cfgFile << "dynamicOffset=" << std::boolalpha << mOptions.dynamicOffsetEnabled << "\n";
cfgFile << "triggerWindowSize=" << mOptions.triggerWindowSize << "\n";
cfgFile << "[links]\n";
cfgFile << "enabled=false\n";
cfgFile << "gbtMux=TTC\n";
for (const auto& link : params.getLinkMaskRequired()) {
cfgFile << "[link" << link << "]\n";
cfgFile << "enabled=true\n";
cfgFile << "gbtMux=" << mOptions.gbtMux << "\n";
}
cfgFile.close();
return;
}
std::cout << "Configuring with command line arguments" << std::endl;
try {
CardConfigurator(params, mOptions.forceConfig);
} catch (const Exception& e) {
std::cout << boost::diagnostic_information(e) << std::endl;
}
} else {
std::cout << "Configuring with config uri" << std::endl;
try {
CardConfigurator(cardId, mOptions.configUri, mOptions.forceConfig);
} catch (std::runtime_error e) {
std::cout << "Error parsing the configuration..." << boost::diagnostic_information(e) << std::endl;
}
}
return;
}
struct OptionsStruct {
std::string clock = "local";
std::string configUri = "";
std::string datapathMode = "packet";
std::string downstreamData = "Ctp";
std::string gbtMode = "gbt";
std::string gbtMux = "ttc";
std::string genConfigFile = "";
std::string links = "0";
bool allowRejection = false;
bool bypassFirmwareCheck = false;
bool configAll = false;
bool forceConfig = false;
bool linkLoopbackEnabled = false;
bool ponUpstreamEnabled = false;
bool dynamicOffsetEnabled = false;
uint32_t onuAddress = 0;
std::string cruId = "0x0";
std::string crorcId = "0x0";
uint32_t triggerWindowSize = 1000;
uint32_t timeFrameLength = 0x100;
bool timeFrameDetectionDisabled = false;
bool userLogicEnabled = false;
bool noGbt = false;
} mOptions;
private:
};
int main(int argc, char** argv)
{
return ProgramConfig().execute(argc, argv);
}