Skip to content

Commit 2760dcd

Browse files
committed
[pat-play] Publish an interface to the pattern player
1 parent 4aa7cba commit 2760dcd

File tree

13 files changed

+221
-211
lines changed

13 files changed

+221
-211
lines changed

include/ReadoutCard/BarInterface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "ReadoutCard/Parameters.h"
2323
#include "boost/optional.hpp"
2424

25+
#include "ReadoutCard/Cru.h"
26+
2527
namespace AliceO2
2628
{
2729
namespace roc

include/ReadoutCard/Cru.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define ALICEO2_INCLUDE_READOUTCARD_CRU_H_
1818

1919
#include <cstdint>
20+
2021
#include "Register.h"
2122

2223
namespace AliceO2
Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
///
44
/// \author Kostas Alexopoulos ([email protected])
55

6-
#ifndef ALICEO2_READOUTCARD_CRU_PATTERNPLAYER_H_
7-
#define ALICEO2_READOUTCARD_CRU_PATTERNPLAYER_H_
6+
#ifndef ALICEO2_INCLUDE_READOUTCARD_PATTERNPLAYER_H_
7+
#define ALICEO2_INCLUDE_READOUTCARD_PATTERNPLAYER_H_
88

9-
#include "Pda/PdaBar.h"
9+
#include "ReadoutCard/Cru.h"
10+
#include "ReadoutCard/BarInterface.h"
1011
#include <boost/multiprecision/cpp_int.hpp>
1112

1213
using namespace boost::multiprecision;
@@ -19,8 +20,24 @@ namespace roc
1920
class PatternPlayer
2021
{
2122
public:
22-
PatternPlayer(std::shared_ptr<Pda::PdaBar> pdaBar);
23+
struct Info {
24+
uint128_t syncPattern = 0x0;
25+
uint128_t resetPattern = 0x0;
26+
uint128_t idlePattern = 0x0;
27+
uint32_t syncLength = 1;
28+
uint32_t syncDelay = 0;
29+
uint32_t resetLength = 1;
30+
uint32_t resetTriggerSelect = 30;
31+
uint32_t syncTriggerSelect = 29;
32+
bool syncAtStart = false;
33+
bool triggerSync = false;
34+
bool triggerReset = false;
35+
};
36+
37+
PatternPlayer(std::shared_ptr<BarInterface> bar);
38+
void play(PatternPlayer::Info info);
2339

40+
private:
2441
void configure(bool startConfig);
2542
void setIdlePattern(uint128_t pattern);
2643
void setSyncPattern(uint128_t pattern);
@@ -32,11 +49,10 @@ class PatternPlayer
3249
void triggerSync();
3350
void triggerReset();
3451

35-
private:
36-
std::shared_ptr<Pda::PdaBar> mPdaBar;
52+
std::shared_ptr<BarInterface> mBar;
3753
};
3854

3955
} // namespace roc
4056
} // namespace AliceO2
4157

42-
#endif // ALICEO2_READOUTCARD_CRU_PATTERNPLAYER_H_
58+
#endif // ALICEO2_INCLUDE_READOUTCARD_PATTERNPLAYER_H_

src/CommandLineUtilities/ProgramPatternPlayer.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "Cru/Constants.h"
2020
#include "Cru/CruBar.h"
2121
#include "ReadoutCard/ChannelFactory.h"
22+
#include "ReadoutCard/PatternPlayer.h"
2223
#include "CommandLineUtilities/Options.h"
2324
#include "CommandLineUtilities/Program.h"
2425
#include "Utilities/Enum.h"

src/Cru/Common.cxx

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,159 +43,159 @@ uint32_t getXcvrRegisterAddress(int wrapper, int bank, int link, int reg)
4343
Cru::Registers::GBT_LINK_XCVR_OFFSET.address + (4 * reg);
4444
}
4545

46-
void atxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
46+
void atxcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress)
4747
{
4848

4949
//std::cout << "Starting ATX PLL calibration" << std::endl;
5050

51-
/*uint32_t identifier = pdaBar->readRegister((baseAddress + 4 * 0x200)/4);
51+
/*uint32_t identifier = bar->readRegister((baseAddress + 4 * 0x200)/4);
5252
5353
std::cout << "Base Address: 0x" << std::hex << baseAddress <<
5454
" Identifier: 0x" << std::hex << identifier << std::endl;
5555
std::cout << "Requesting internal configuration bus user access..." << std::endl;*/
5656

5757
// a. Direct write of 0x2 to address 0x00 to request access (do not use modify...)
5858

59-
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x02); //...
59+
bar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x02); //...
6060

6161
// b. Validate that user has control
62-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
62+
waitForBit(bar, baseAddress + 4 * 0x280, 2, 0);
6363

6464
// c. Enable ATX PLL alibration
65-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 0, 1, 0x1);
65+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 0, 1, 0x1);
6666

6767
//d. let PreSice do the calibration
68-
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
68+
bar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
6969

7070
//e. Wait...
71-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
71+
waitForBit(bar, baseAddress + 4 * 0x280, 1, 0);
7272

7373
//f. Calibration complete...
7474
}
7575

7676
/// Calibrate XCVR TX
77-
void txcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
77+
void txcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress)
7878
{
7979

8080
//a. Request access to internal configuration bus
81-
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
81+
bar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
8282

8383
//b. Validate that user has control
84-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
84+
waitForBit(bar, baseAddress + 4 * 0x280, 2, 0);
8585

8686
//c. Mask out rx_cal_busy...
87-
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 5, 1, 0x0);
87+
bar->modifyRegister((baseAddress + 4 * 0x281) / 4, 5, 1, 0x0);
8888

8989
//d. Set the Tx calibration bit
90-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 5, 1, 0x1);
91-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 6, 1, 0x0);
90+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 5, 1, 0x1);
91+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 6, 1, 0x0);
9292

9393
//e. Let PreSice do the calibration
94-
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
94+
bar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
9595

9696
//f. Wait..
97-
waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
97+
waitForBit(bar, baseAddress + 4 * 0x281, 1, 0);
9898

9999
//g. Calibration is complete
100100

101101
//h. Enable rx_cal_busy
102-
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 5, 1, 0x1);
102+
bar->modifyRegister((baseAddress + 4 * 0x281) / 4, 5, 1, 0x1);
103103
}
104104

105105
/// Calibrate XCVR RX
106-
void rxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress)
106+
void rxcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress)
107107
{
108108
//a. Request access to internal configuration bus
109-
pdaBar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
109+
bar->writeRegister((baseAddress + 4 * 0x000) / 4, 0x2);
110110

111111
//b. Validate that user has control
112-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
112+
waitForBit(bar, baseAddress + 4 * 0x280, 2, 0);
113113

114114
//c. Mask out tx_cal_busy...
115-
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 4, 1, 0x0);
115+
bar->modifyRegister((baseAddress + 4 * 0x281) / 4, 4, 1, 0x0);
116116

117117
//d. Set the Rx calibration bit
118-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 1, 1, 0x1);
119-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 6, 1, 0x1);
118+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 1, 1, 0x1);
119+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 6, 1, 0x1);
120120

121121
//e. Set the rate switch flag register for PMA Rx calibration TODO(cru-sw)
122122

123123
//f. Let PreSice do the calibration
124-
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
124+
bar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
125125

126126
//g. Wait..
127-
waitForBit(pdaBar, baseAddress + 4 * 0x281, 1, 0);
127+
waitForBit(bar, baseAddress + 4 * 0x281, 1, 0);
128128

129129
//h. Calibration is complete
130130

131131
//i. Enable tx_cal_busy
132-
pdaBar->modifyRegister((baseAddress + 4 * 0x281) / 4, 4, 1, 0x1);
132+
bar->modifyRegister((baseAddress + 4 * 0x281) / 4, 4, 1, 0x1);
133133
}
134134

135-
void fpllref0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, uint32_t refClock)
135+
void fpllref0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress, uint32_t refClock)
136136
{
137137
//uint32_t current114 = mPdaBar->readRegister((baseAddress + 4 * 0x114)/4);
138-
//uint32_t current11C = pdaBar->readRegister((baseAddress + 4 * 0x11C)/4);
138+
//uint32_t current11C = bar->readRegister((baseAddress + 4 * 0x11C)/4);
139139

140-
uint32_t new114 = pdaBar->readRegister((baseAddress + 4 * (0x117 + refClock)) / 4);
141-
uint32_t new11C = pdaBar->readRegister((baseAddress + 4 * (0x11D + refClock)) / 4);
140+
uint32_t new114 = bar->readRegister((baseAddress + 4 * (0x117 + refClock)) / 4);
141+
uint32_t new11C = bar->readRegister((baseAddress + 4 * (0x11D + refClock)) / 4);
142142

143-
pdaBar->modifyRegister((baseAddress + 4 * 0x114) / 4, 0, 8, new114);
144-
pdaBar->modifyRegister((baseAddress + 4 * 0x11C) / 4, 0, 8, new11C);
143+
bar->modifyRegister((baseAddress + 4 * 0x114) / 4, 0, 8, new114);
144+
bar->modifyRegister((baseAddress + 4 * 0x11C) / 4, 0, 8, new11C);
145145
}
146146

147-
void fpllcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, bool configCompensation)
147+
void fpllcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress, bool configCompensation)
148148
{
149-
/*uint32_t identifier = pdaBar->readRegister((baseAddress + 4 * 0x200)/4);
149+
/*uint32_t identifier = bar->readRegister((baseAddress + 4 * 0x200)/4);
150150
151151
std::cout << "Base Address: 0x" << std::hex << baseAddress <<
152152
" Identifier: 0x" << std::hex << identifier << std::endl;*/
153153

154154
// Set fPLL to direct feedback mode
155-
pdaBar->modifyRegister((baseAddress + 4 * 0x126) / 4, 0, 1, 0x1);
155+
bar->modifyRegister((baseAddress + 4 * 0x126) / 4, 0, 1, 0x1);
156156

157157
//a. Request internal configuration bus (do not use modify but modify is used...)
158-
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x02);
158+
bar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x02);
159159

160160
//b. Validate that user has control
161-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 2, 0);
161+
waitForBit(bar, baseAddress + 4 * 0x280, 2, 0);
162162

163163
//c. Enable fPLL calibration
164-
pdaBar->modifyRegister((baseAddress + 4 * 0x100) / 4, 1, 1, 0x1);
164+
bar->modifyRegister((baseAddress + 4 * 0x100) / 4, 1, 1, 0x1);
165165

166166
//d. let PreSice do the calibration
167-
pdaBar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
167+
bar->modifyRegister((baseAddress + 4 * 0x000) / 4, 0, 8, 0x1);
168168

169169
//e. Wait...
170-
waitForBit(pdaBar, baseAddress + 4 * 0x280, 1, 0);
170+
waitForBit(bar, baseAddress + 4 * 0x280, 1, 0);
171171

172172
//f. Calibration is complete
173173

174174
//g. Set fPLL to feedback compensation mode
175175
if (configCompensation) {
176-
pdaBar->modifyRegister((baseAddress + 4 * 0x126) / 4, 0, 1, 0x0);
176+
bar->modifyRegister((baseAddress + 4 * 0x126) / 4, 0, 1, 0x0);
177177
}
178178
}
179179

180-
uint32_t waitForBit(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t address, uint32_t position, uint32_t value)
180+
uint32_t waitForBit(std::shared_ptr<BarInterface> bar, uint32_t address, uint32_t position, uint32_t value)
181181
{
182182
auto start = std::chrono::system_clock::now();
183183
auto curr = start;
184184
auto elapsed = curr - start;
185185

186-
uint32_t readValue = pdaBar->readRegister(address / 4);
186+
uint32_t readValue = bar->readRegister(address / 4);
187187
uint32_t bit = Utilities::getBit(readValue, position);
188188

189189
while ((elapsed <= std::chrono::milliseconds(500)) && bit != value) {
190-
readValue = pdaBar->readRegister(address / 4);
190+
readValue = bar->readRegister(address / 4);
191191
bit = Utilities::getBit(readValue, position);
192192
curr = std::chrono::system_clock::now();
193193
elapsed = curr - start;
194194
}
195195
return bit;
196196
}
197197

198-
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress) //baseAddress = 0
198+
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<BarInterface> mPdaBar, uint32_t refClock, uint32_t baseAddress) //baseAddress = 0
199199
{
200200
if (baseAddress == 0) {
201201
int prevWrapper = -1;
@@ -212,7 +212,7 @@ void fpllref(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar,
212212
Cru::fpllref0(mPdaBar, baseAddress, refClock);
213213
}
214214

215-
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress, bool configCompensation) //baseAddress = 0, configCompensation = true
215+
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<BarInterface> mPdaBar, uint32_t baseAddress, bool configCompensation) //baseAddress = 0, configCompensation = true
216216
{
217217
if (baseAddress == 0) {
218218
int prevWrapper = -1;

src/Cru/Common.h

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
#ifndef ALICEO2_READOUTCARD_CRU_COMMON_H_
1717
#define ALICEO2_READOUTCARD_CRU_COMMON_H_
1818

19-
#include <boost/multiprecision/cpp_int.hpp>
20-
2119
#include "Constants.h"
22-
#include "Pda/PdaBar.h"
23-
24-
using namespace boost::multiprecision;
20+
#include "ExceptionInternal.h"
21+
#include "ReadoutCard/BarInterface.h"
2522

2623
namespace AliceO2
2724
{
@@ -146,31 +143,17 @@ struct CtpInfo {
146143
bool generateSingleTrigger;
147144
};
148145

149-
struct PatternPlayerInfo {
150-
uint128_t syncPattern = 0x0;
151-
uint128_t resetPattern = 0x0;
152-
uint128_t idlePattern = 0x0;
153-
uint32_t syncLength = 1;
154-
uint32_t syncDelay = 0;
155-
uint32_t resetLength = 1;
156-
uint32_t resetTriggerSelect = 30;
157-
uint32_t syncTriggerSelect = 29;
158-
bool syncAtStart = false;
159-
bool triggerSync = false;
160-
bool triggerReset = false;
161-
};
162-
163146
uint32_t getWrapperBaseAddress(int wrapper);
164147
uint32_t getXcvrRegisterAddress(int wrapper, int bank, int link, int reg = 0);
165-
void atxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress);
166-
void txcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress);
167-
void rxcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress);
168-
void fpllref0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, uint32_t refClock);
169-
void fpllcal0(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t baseAddress, bool configCompensation = true);
170-
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t refClock, uint32_t baseAddress = 0);
171-
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<Pda::PdaBar> mPdaBar, uint32_t baseAddress = 0, bool configCompensation = true);
148+
void atxcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress);
149+
void txcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress);
150+
void rxcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress);
151+
void fpllref0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress, uint32_t refClock);
152+
void fpllcal0(std::shared_ptr<BarInterface> bar, uint32_t baseAddress, bool configCompensation = true);
153+
void fpllref(std::map<int, Link> linkMap, std::shared_ptr<BarInterface> bar, uint32_t refClock, uint32_t baseAddress = 0);
154+
void fpllcal(std::map<int, Link> linkMap, std::shared_ptr<BarInterface> bar, uint32_t baseAddress = 0, bool configCompensation = true);
172155
uint32_t getBankPllRegisterAddress(int wrapper, int bank);
173-
uint32_t waitForBit(std::shared_ptr<Pda::PdaBar> pdaBar, uint32_t address, uint32_t position, uint32_t value);
156+
uint32_t waitForBit(std::shared_ptr<BarInterface> bar, uint32_t address, uint32_t position, uint32_t value);
174157

175158
} // namespace Cru
176159
} // namespace roc

0 commit comments

Comments
 (0)