forked from AliceO2Group/ReadoutCard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgramConfig.cxx
195 lines (181 loc) · 8.25 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
// 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 ([email protected])
#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 CRU(s)",
"roc-config --config-file file:roc.cfg\n"
"roc-config --id 42:00.0 --links 0-23 --clock local --datapathmode packet --loopback --gbtmux ttc\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()("cru-id",
po::value<uint16_t>(&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(0x0),
"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),
"Flag to set the size of the trigger window in GBT words");
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);
if (!mOptions.bypassFirmwareCheck) {
try {
FirmwareChecker().checkFirmwareCompatibility(cardId);
} catch (const Exception& e) {
std::cout << boost::diagnostic_information(e) << std::endl;
return;
}
}
if (mOptions.configUri == "") {
std::cout << "Configuring with command line arguments" << std::endl;
auto params = Parameters::makeParameters(cardId, 2);
params.setLinkMask(Parameters::linkMaskFromString(mOptions.links));
params.setAllowRejection(mOptions.allowRejection);
params.setClock(Clock::fromString(mOptions.clock));
params.setCruId(mOptions.cruId);
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);
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 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 = 0x0;
uint16_t cruId = 0x0;
uint32_t triggerWindowSize = 1000;
} mOptions;
private:
};
int main(int argc, char** argv)
{
return ProgramConfig().execute(argc, argv);
}