Skip to content

Commit 3df0909

Browse files
committed
new pattern player registers
1 parent 58802db commit 3df0909

File tree

4 files changed

+238
-218
lines changed

4 files changed

+238
-218
lines changed

include/ReadoutCard/PatternPlayer.h

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,22 @@ class PatternPlayer
3333
{
3434
public:
3535
struct Info {
36-
uint128_t syncPattern = 0x0;
37-
uint128_t resetPattern = 0x0;
38-
uint128_t idlePattern = 0x0;
39-
uint32_t syncLength = 1;
40-
uint32_t syncDelay = 0;
41-
uint32_t resetLength = 1;
42-
uint32_t resetTriggerSelect = 30;
43-
uint32_t syncTriggerSelect = 29;
44-
bool syncAtStart = false;
45-
bool triggerSync = false;
46-
bool triggerReset = false;
36+
uint128_t pat0= 0x0;
37+
uint128_t pat1 = 0x0;
38+
uint128_t pat2 = 0x0;
39+
uint128_t pat3 = 0x0;
40+
uint32_t pat1Length = 1;
41+
uint32_t pat1Delay = 0;
42+
uint32_t pat2Length = 1;
43+
uint32_t pat3Length = 1;
44+
uint32_t pat1TriggerSelect = 29;
45+
uint32_t pat2TriggerSelect = 30;
46+
uint32_t pat3TriggerSelect = 0;
47+
uint32_t pat2TriggerTF = 0;
48+
49+
bool exePat1AtStart = false;
50+
bool exePat1Now = false;
51+
bool exePat2Now = false;
4752
};
4853

4954
PatternPlayer(std::shared_ptr<BarInterface> bar);
@@ -52,24 +57,9 @@ class PatternPlayer
5257

5358
private:
5459
void configure(bool startConfig);
55-
void setIdlePattern(uint128_t pattern);
56-
void setSyncPattern(uint128_t pattern);
57-
void configureSync(uint32_t length = 1, uint32_t delay = 0);
58-
void setResetPattern(uint128_t pattern);
59-
void configureReset(uint32_t length = 1);
60-
void selectPatternTrigger(uint32_t syncTrigger = 3, uint32_t resetTrigger = 3);
61-
void enableSyncAtStart(bool enable = false);
62-
void triggerSync();
63-
void triggerReset();
64-
65-
uint128_t getSyncPattern();
66-
uint128_t getResetPattern();
67-
uint128_t getIdlePattern();
68-
uint32_t getSyncLength();
69-
uint32_t getSyncDelay();
70-
uint32_t getResetLength();
71-
uint32_t getResetTriggerSelect();
72-
uint32_t getSyncTriggerSelect();
60+
void exePat1AtStart(bool enable = false);
61+
void exePat1();
62+
void exePat2();
7363

7464
std::shared_ptr<BarInterface> mBar;
7565
};

src/CommandLineUtilities/ProgramPatternPlayer.cxx

Lines changed: 125 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
33
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
44
// All rights not expressly granted are reserved.
@@ -32,51 +32,103 @@ using namespace o2::roc;
3232
namespace po = boost::program_options;
3333
using namespace boost::multiprecision;
3434

35+
// 128-bit hex string parser
36+
// nBits specifies the maximum allowed bit width
37+
// throws exception on error
38+
uint128_t parsePattern(const std::string &s, int nBits = 128) {
39+
uint128_t v = 0;
40+
if (strncmp(s.c_str(), "0x", 2) || (s.length() <= 2)) {
41+
BOOST_THROW_EXCEPTION(InvalidOptionValueException()
42+
<< ErrorInfo::Message("Pattern must be hexadecimal"));
43+
}
44+
for (unsigned int i=2; i<s.length(); i++) {
45+
int c = s[i];
46+
uint128_t x = 0;
47+
if ( ( c >= '0') && ( c <= '9')) {
48+
x = c - '0';
49+
} else if ( ( c >= 'A') && ( c <= 'F')) {
50+
x = 10 + c - 'A';
51+
} else if ( ( c >= 'a') && ( c <= 'f')) {
52+
x = 10 + c - 'a';
53+
} else {
54+
BOOST_THROW_EXCEPTION(InvalidOptionValueException()
55+
<< ErrorInfo::Message("Pattern must be hexadecimal"));
56+
}
57+
v = (v << 4) + x;
58+
59+
/*
60+
// print value
61+
for (int k=8; k > 0; k--) {
62+
printf("%04X ", (unsigned int)((v >> ((k-1)*16)) & 0xffff));
63+
}
64+
printf("\n");
65+
*/
66+
}
67+
68+
if (((v >> nBits) != 0) || (s.length() - 2 > 32)) {
69+
BOOST_THROW_EXCEPTION(InvalidOptionValueException()
70+
<< ErrorInfo::Message("Pattern exceeds " + std::to_string(nBits) + " bits"));
71+
}
72+
return v;
73+
}
74+
3575
class ProgramPatternPlayer : public Program
3676
{
3777
public:
3878
virtual Description getDescription()
3979
{
4080
return { "PatternPlayer", "Configure the CRU pattern player",
41-
"o2-roc-pat-player --id 42:00.0 --sync 0x0123457899876543210abcdefedcb --sync-length 4 --sync-delay 2 --sync-at-start\n" };
81+
"o2-roc-pat-player --id 42:00.0 --pat1 0x012345789abdef0123 --pat1-length 4 --pat1-delay 2 --execute-pat1-at-start\n" };
4282
}
4383

4484
virtual void addOptions(boost::program_options::options_description& options)
4585
{
4686
Options::addOptionCardId(options);
47-
options.add_options()("sync",
48-
po::value<std::string>(&mOptions.syncPattern)->default_value("0x0"),
49-
"80-bit sync pattern in hex");
50-
options.add_options()("reset",
51-
po::value<std::string>(&mOptions.resetPattern)->default_value("0x0"),
52-
"80-bit reset pattern in hex");
53-
options.add_options()("idle",
54-
po::value<std::string>(&mOptions.idlePattern)->default_value("0x0"),
55-
"80-bit idle pattern in hex");
56-
options.add_options()("sync-length",
57-
po::value<uint32_t>(&mOptions.syncLength)->default_value(1),
58-
"Sync pattern's length");
59-
options.add_options()("sync-delay",
60-
po::value<uint32_t>(&mOptions.syncDelay)->default_value(0),
61-
"Sync pattern's delay");
62-
options.add_options()("reset-length",
63-
po::value<uint32_t>(&mOptions.resetLength)->default_value(1),
64-
"Reset pattern's length");
65-
options.add_options()("reset-trigger-select",
66-
po::value<uint32_t>(&mOptions.resetTriggerSelect)->default_value(30),
67-
"Select trigger for SYNC from TTC_DATA[0-31]");
68-
options.add_options()("sync-trigger-select",
69-
po::value<uint32_t>(&mOptions.syncTriggerSelect)->default_value(29),
70-
"Select trigger for RESET from TTC_DATA[0-31]");
71-
options.add_options()("sync-at-start",
72-
po::bool_switch(&mOptions.syncAtStart)->default_value(false),
73-
"Enable automatically sending a sync pattern when runenable goes high");
74-
options.add_options()("trigger-sync",
75-
po::bool_switch(&mOptions.triggerSync)->default_value(false),
76-
"Manually trigger the SYNC pattern");
77-
options.add_options()("trigger-reset",
78-
po::bool_switch(&mOptions.triggerReset)->default_value(false),
79-
"Manually trigger the reset pattern");
87+
options.add_options()("pat0",
88+
po::value<std::string>(&mOptions.pat0),
89+
"80-bit pat0 pattern in hex");
90+
options.add_options()("pat1",
91+
po::value<std::string>(&mOptions.pat1),
92+
"80-bit pat1 pattern in hex");
93+
options.add_options()("pat2",
94+
po::value<std::string>(&mOptions.pat2),
95+
"80-bit pat2 pattern in hex");
96+
options.add_options()("pat3",
97+
po::value<std::string>(&mOptions.pat3),
98+
"80-bit pat3 pattern in hex");
99+
options.add_options()("pat1-length",
100+
po::value<uint32_t>(&mOptions.info.pat1Length),
101+
"pat1 pattern's length");
102+
options.add_options()("pat1-delay",
103+
po::value<uint32_t>(&mOptions.info.pat1Delay),
104+
"pat1 pattern's delay");
105+
options.add_options()("pat2-length",
106+
po::value<uint32_t>(&mOptions.info.pat2Length),
107+
"pat2 pattern's length");
108+
options.add_options()("pat2-trigger-counters",
109+
po::value<uint32_t>(&mOptions.info.pat2TriggerTF),
110+
"Trigger counters for pat2: TF[31:20] ORBIT[19:12] BC[11:0]");
111+
options.add_options()("pat3-length",
112+
po::value<uint32_t>(&mOptions.info.pat3Length),
113+
"pat3 pattern's length");
114+
options.add_options()("pat1-trigger-select",
115+
po::value<uint32_t>(&mOptions.info.pat1TriggerSelect),
116+
"Select trigger for pat1");
117+
options.add_options()("pat2-trigger-select",
118+
po::value<uint32_t>(&mOptions.info.pat2TriggerSelect),
119+
"Select trigger for pat2");
120+
options.add_options()("pat3-trigger-select",
121+
po::value<uint32_t>(&mOptions.info.pat3TriggerSelect),
122+
"Select trigger for pat3");
123+
options.add_options()("execute-pat1-at-start",
124+
po::bool_switch(&mOptions.info.exePat1AtStart)->default_value(false),
125+
"Enable automatically sending a pat1 pattern when runenable goes high");
126+
options.add_options()("execute-pat1-now",
127+
po::bool_switch(&mOptions.info.exePat1Now)->default_value(false),
128+
"Manually trigger the pat1 pattern now");
129+
options.add_options()("execute-pat2-now",
130+
po::bool_switch(&mOptions.info.exePat2Now)->default_value(false),
131+
"Manually trigger the pat2 pattern now");
80132
options.add_options()("read-back",
81133
po::bool_switch(&mOptions.readBack)->default_value(false),
82134
"Reads back the pattern player configuration [DOES NOT CONFIGURE!!]");
@@ -98,45 +150,53 @@ class ProgramPatternPlayer : public Program
98150
return;
99151
}
100152

153+
if (mOptions.pat0.length()) {
154+
mOptions.info.pat0 = parsePattern(mOptions.pat0, 80);
155+
}
156+
if (mOptions.pat1.length()) {
157+
mOptions.info.pat1 = parsePattern(mOptions.pat1, 80);
158+
}
159+
if (mOptions.pat2.length()) {
160+
mOptions.info.pat2 = parsePattern(mOptions.pat2, 80);
161+
}
162+
if (mOptions.pat3.length()) {
163+
mOptions.info.pat3 = parsePattern(mOptions.pat3, 80);
164+
}
165+
101166
auto cruBar2 = std::dynamic_pointer_cast<CruBar>(bar2);
102167
if (!mOptions.readBack) {
103-
cruBar2->patternPlayer({ uint128_t(mOptions.syncPattern), //TODO: Parse this correctly!
104-
uint128_t(mOptions.resetPattern),
105-
uint128_t(mOptions.idlePattern),
106-
mOptions.syncLength,
107-
mOptions.syncDelay,
108-
mOptions.resetLength,
109-
mOptions.resetTriggerSelect,
110-
mOptions.syncTriggerSelect,
111-
mOptions.syncAtStart,
112-
mOptions.triggerSync,
113-
mOptions.triggerReset });
168+
cruBar2->patternPlayer(mOptions.info);
114169
} else {
115170
auto ppInfo = cruBar2->patternPlayerRead();
116-
std::cout << "sync pattern:\t\t0x" << std::hex << ppInfo.syncPattern << std::endl;
117-
std::cout << "reset pattern:\t\t0x" << ppInfo.resetPattern << std::endl;
118-
std::cout << "idle pattern:\t\t0x" << ppInfo.idlePattern << std::dec << std::endl;
119-
std::cout << "sync length:\t\t" << ppInfo.syncLength << std::endl;
120-
std::cout << "sync delay:\t\t" << ppInfo.syncDelay << std::endl;
121-
std::cout << "reset length:\t\t" << ppInfo.resetLength << std::endl;
122-
std::cout << "reset trigger select:\t" << ppInfo.resetTriggerSelect << std::endl;
123-
std::cout << "sync trigger select:\t" << ppInfo.syncTriggerSelect << std::endl;
171+
std::cout << "pat0 pattern:\t\t0x" << std::hex << ppInfo.pat0 << std::endl;
172+
std::cout << "pat1 pattern:\t\t0x" << std::hex << ppInfo.pat1 << std::endl;
173+
std::cout << "pat2 pattern:\t\t0x" << std::hex << ppInfo.pat2 << std::endl;
174+
std::cout << "pat3 pattern:\t\t0x" << std::hex << ppInfo.pat3 << std::endl;
175+
176+
std::cout << "pat1 length:\t\t" << std::dec << ppInfo.pat1Length << std::endl;
177+
std::cout << "pat1 delay:\t\t" << std::dec << ppInfo.pat1Delay << std::endl;
178+
std::cout << "pat2 length:\t\t" << std::dec << ppInfo.pat2Length << std::endl;
179+
std::cout << "pat3 length:\t\t" << std::dec << ppInfo.pat3Length << std::endl;
180+
181+
std::cout << "pat1 trigger select:\t0x" << std::hex << ppInfo.pat1TriggerSelect << std::endl;
182+
std::cout << "pat2 trigger select:\t0x" << std::hex << ppInfo.pat2TriggerSelect << std::endl;
183+
std::cout << "pat3 trigger select:\t0x" << std::hex << ppInfo.pat3TriggerSelect << std::endl;
184+
185+
std::cout << "pat2 trigger counters:\t"
186+
<< "TF 0x" << std::hex << ((ppInfo.pat2TriggerTF >> 20) & 0xFFF)
187+
<< " ORBIT 0x" << std::hex << ((ppInfo.pat2TriggerTF >> 12) & 0xFF)
188+
<< " BC 0x" << std::hex << (ppInfo.pat2TriggerTF & 0xFFF)
189+
<< std::endl;
124190
}
125191
}
126192

127193
private:
128194
struct OptionsStruct {
129-
std::string syncPattern = "0x0";
130-
std::string resetPattern = "0x0";
131-
std::string idlePattern = "0x0";
132-
uint32_t syncLength = 1;
133-
uint32_t syncDelay = 0;
134-
uint32_t resetLength = 1;
135-
uint32_t resetTriggerSelect = 30;
136-
uint32_t syncTriggerSelect = 29;
137-
bool syncAtStart = false;
138-
bool triggerSync = false;
139-
bool triggerReset = false;
195+
std::string pat0;
196+
std::string pat1;
197+
std::string pat2;
198+
std::string pat3;
199+
PatternPlayer::Info info;
140200
bool readBack = false;
141201
} mOptions;
142202
};

src/Cru/Constants.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -354,20 +354,29 @@ static constexpr Register CTP_EMU_FBCT(0x00280024);
354354
static constexpr Register CTP_EMU_ORBIT_INIT(0x00280028);
355355

356356
/// Registers for the Pattern Player
357+
/// see https://gitlab.cern.ch/alice-cru/cru-fw/-/tree/pplayer/TTC#address-table
357358
static constexpr Register PATPLAYER_CFG(0x00260000);
358-
static constexpr Register PATPLAYER_IDLE_PATTERN_0(0x00260004);
359-
static constexpr Register PATPLAYER_IDLE_PATTERN_1(0x00260008);
360-
static constexpr Register PATPLAYER_IDLE_PATTERN_2(0x0026000c);
361-
static constexpr Register PATPLAYER_SYNC_PATTERN_0(0x00260010);
362-
static constexpr Register PATPLAYER_SYNC_PATTERN_1(0x00260014);
363-
static constexpr Register PATPLAYER_SYNC_PATTERN_2(0x00260018);
364-
static constexpr Register PATPLAYER_RESET_PATTERN_0(0x0026001c);
365-
static constexpr Register PATPLAYER_RESET_PATTERN_1(0x00260020);
366-
static constexpr Register PATPLAYER_RESET_PATTERN_2(0x00260024);
367-
static constexpr Register PATPLAYER_SYNC_CNT(0x00260028);
368-
static constexpr Register PATPLAYER_DELAY_CNT(0x0026002c);
369-
static constexpr Register PATPLAYER_RESET_CNT(0x00260030);
370-
static constexpr Register PATPLAYER_TRIGGER_SEL(0x00260034);
359+
static constexpr Register PATPLAYER_PAT0_0(0x00260004);
360+
static constexpr Register PATPLAYER_PAT0_1(0x00260008);
361+
static constexpr Register PATPLAYER_PAT0_2(0x0026000c);
362+
static constexpr Register PATPLAYER_PAT1_0(0x00260010);
363+
static constexpr Register PATPLAYER_PAT1_1(0x00260014);
364+
static constexpr Register PATPLAYER_PAT1_2(0x00260018);
365+
static constexpr Register PATPLAYER_PAT2_0(0x0026001c);
366+
static constexpr Register PATPLAYER_PAT2_1(0x00260020);
367+
static constexpr Register PATPLAYER_PAT2_2(0x00260024);
368+
static constexpr Register PATPLAYER_PAT1_LENGTH(0x00260028);
369+
static constexpr Register PATPLAYER_PAT1_DELAY_CNT(0x0026002c);
370+
static constexpr Register PATPLAYER_PAT2_LENGTH(0x00260030);
371+
static constexpr Register PATPLAYER_PAT1_TRIGGER_SEL(0x00260034);
372+
static constexpr Register PATPLAYER_PAT2_TRIGGER_SEL(0x00260038);
373+
static constexpr Register PATPLAYER_PAT3_TRIGGER_SEL(0x0026003c);
374+
static constexpr Register PATPLAYER_PAT2_TRIGGER_TF(0x00260040);
375+
static constexpr Register PATPLAYER_PAT3_LENGTH(0x00260044);
376+
static constexpr Register PATPLAYER_PAT3_0(0x00260048);
377+
static constexpr Register PATPLAYER_PAT3_1(0x0026004c);
378+
static constexpr Register PATPLAYER_PAT3_2(0x00260050);
379+
371380

372381
//** I2C **//
373382
/// I2C base addresses

0 commit comments

Comments
 (0)