Skip to content

Commit 23da358

Browse files
authored
Fix scrambled DMA page in beginning of run
1 parent 7644f4b commit 23da358

File tree

4 files changed

+33
-70
lines changed

4 files changed

+33
-70
lines changed

src/Crorc/Crorc.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,20 @@ void Crorc::stopTrigger(const DiuConfig& diuConfig)
892892
ddlReadStatus();
893893
};
894894

895+
// Try stopping once
896+
try {
897+
rorcStopTrigger();
898+
} catch (const Exception& e) {
899+
std::cout << "STOP TRIGGER DDL TIME-OUT" << std::endl;
900+
}
901+
895902
// Try stopping twice
896903
try {
897904
rorcStopTrigger();
898905
} catch (const Exception& e) {
899906
std::cout << "STOP TRIGGER DDL TIME-OUT" << std::endl;
900907
}
908+
901909
}
902910

903911
void Crorc::setLoopbackOn(){

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 23 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CrorcDmaChannel::CrorcDmaChannel(const Parameters& parameters)
3232
//mPdaBar(getRocPciDevice().getPciDevice(), getChannelNumber()), // Initialize main DMA channel BAR
3333
//mPdaBar2(getRocPciDevice().getPciDevice(), 2), // Initialize BAR 2
3434
mPageSize(parameters.getDmaPageSize().get_value_or(DMA_PAGE_SIZE)), // 8 kB default for uniformity with CRU
35-
mInitialResetLevel(ResetLevel::Internal), // It's good to reset at least the card channel in general
35+
mInitialResetLevel(ResetLevel::InternalDiuSiu), // It's good to reset at least the card channel in general
3636
mNoRDYRX(false), // Not sure
3737
mUseFeeAddress(false), // Not sure
3838
mLoopbackMode(parameters.getGeneratorLoopback().get_value_or(LoopbackMode::Internal)), // Internal loopback by default
@@ -99,6 +99,20 @@ CrorcDmaChannel::~CrorcDmaChannel()
9999

100100
void CrorcDmaChannel::deviceStartDma()
101101
{
102+
if (mUseContinuousReadout) {
103+
log("Initializing continuous readout");
104+
Crorc::Crorc::initReadoutContinuous(*(getBar()));
105+
}
106+
107+
// Find DIU version, required for armDdl()
108+
mDiuConfig = getCrorc().initDiuVersion();
109+
110+
// Resetting the card,according to the RESET LEVEL parameter
111+
deviceResetChannel(mInitialResetLevel);
112+
113+
// Setting the card to be able to receive data
114+
startDataReceiving();
115+
102116
log("DMA start deferred until enough superpages available");
103117

104118
mFreeFifoBack = 0;
@@ -121,42 +135,17 @@ void CrorcDmaChannel::startPendingDma()
121135

122136
log("Starting pending DMA");
123137

124-
if (mUseContinuousReadout) {
125-
log("Initializing continuous readout");
126-
Crorc::Crorc::initReadoutContinuous(*(getBar()));
127-
}
128-
129-
// Find DIU version, required for armDdl()
130-
mDiuConfig = getCrorc().initDiuVersion();
131-
132-
// Resetting the card,according to the RESET LEVEL parameter
133-
deviceResetChannel(mInitialResetLevel);
134-
135-
// TODO: Move datareceiving at deviceStartDma?
136-
// Setting the card to be able to receive data
137-
startDataReceiving();
138-
139-
auto superpageToPush = mTransferQueue.front(); // Push the first superpage
140-
// After data receiving has begun
141-
for (size_t j = 0; j < READYFIFO_ENTRIES; j++) {
142-
auto offset = superpageToPush.getOffset() + j * mPageSize;
143-
pushFreeFifoPage(j, getBusOffsetAddress(offset));
144-
//mFreeFifoSize++;
145-
}
146-
mFreeFifoSize = READYFIFO_ENTRIES;
147-
148138
if (mGeneratorEnabled) {
149139
log("Starting data generator");
150-
// Starting the data generator
151140
startDataGenerator();
152141
} else {
153142
if (!mNoRDYRX) {
154143
log("Starting trigger");
155144

156145
// Clearing SIU/DIU status.
157146
getCrorc().assertLinkUp();
158-
//getCrorc().siuCommand(Ddl::RandCIFST);
159-
//getCrorc().diuCommand(Ddl::RandCIFST);
147+
getCrorc().siuCommand(Ddl::RandCIFST);
148+
getCrorc().diuCommand(Ddl::RandCIFST);
160149

161150
// RDYRX command to FEE
162151
getCrorc().startTrigger(mDiuConfig);
@@ -165,29 +154,7 @@ void CrorcDmaChannel::startPendingDma()
165154

166155
std::this_thread::sleep_for(100ms);
167156

168-
if (true) { // Kostas: Temp if to try and remove special handling of first superpage
169-
/// Fixed wait for initial pages TODO polling wait with timeout
170-
while ((dataArrived(READYFIFO_ENTRIES - 1) != DataArrivalStatus::WholeArrived)) {
171-
std::this_thread::sleep_for(100ms);
172-
log("Initial pages not arrived", InfoLogger::InfoLogger::Warning);
173-
}
174-
175-
// TODO: Move this read to fillSuperpages...
176-
auto superpageToReadout = mTransferQueue.front(); // Read the first Superpage
177-
//superpageToReadout.setReceived(READYFIFO_ENTRIES * mPageSize);
178-
//superpageToReadout.setReady(true);
179-
mReadyQueue.push_back(superpageToReadout);
180-
181-
getReadyFifoUser()->reset(); // Reset ReadyFifo
182-
mFreeFifoBack = 0; // Reset FreeFifo references
183-
mFreeFifoSize = 0;
184-
185-
mPendingDmaStart = false;
186-
mTransferQueue.pop_front(); // Pop the Superpage after resets; don't introduce race conditions
187-
} else {
188-
mPendingDmaStart = false;
189-
}
190-
157+
mPendingDmaStart = false;
191158
log("DMA started");
192159
}
193160

@@ -211,10 +178,9 @@ void CrorcDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)
211178
}
212179

213180
try {
214-
if (resetLevel == ResetLevel::Internal) {
215-
getCrorc().resetCommand(Rorc::Reset::FF, mDiuConfig);
216-
getCrorc().resetCommand(Rorc::Reset::RORC, mDiuConfig);
217-
}
181+
// Always reset the FreeFifo and the channel
182+
getCrorc().resetCommand(Rorc::Reset::FF, mDiuConfig);
183+
getCrorc().resetCommand(Rorc::Reset::RORC, mDiuConfig);
218184

219185
if (LoopbackMode::isExternal(mLoopbackMode)) {
220186
getCrorc().armDdl(Rorc::Reset::DIU, mDiuConfig);
@@ -228,7 +194,7 @@ void CrorcDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)
228194
getCrorc().armDdl(Rorc::Reset::DIU, mDiuConfig);
229195
}
230196

231-
//getCrorc().resetCommand(Rorc::Reset::FIFOS & Rorc::Reset::DIU & Rorc::Reset::SIU, mDiuConfig);
197+
getCrorc().resetCommand(Rorc::Reset::FIFOS & Rorc::Reset::DIU & Rorc::Reset::SIU, mDiuConfig);
232198
getCrorc().armDdl(Rorc::Reset::RORC, mDiuConfig);
233199
}
234200
}
@@ -244,10 +210,6 @@ void CrorcDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)
244210

245211
void CrorcDmaChannel::startDataGenerator()
246212
{
247-
/*if (LoopbackMode::None == mLoopbackMode) {
248-
getCrorc().startTrigger(mDiuConfig);
249-
}*/
250-
251213
getCrorc().armDataGenerator(mGeneratorInitialValue, mGeneratorInitialWord, mGeneratorPattern, mGeneratorDataSize,
252214
mGeneratorSeed);
253215

@@ -327,13 +289,6 @@ void CrorcDmaChannel::pushSuperpage(Superpage superpage)
327289
<< ErrorInfo::Message("Could not push superpage, firmware queue was full (this should never happen)"));
328290
}
329291

330-
if (mPendingDmaStart) { // TODO: Don't let someone push more than one superpage at this stage
331-
// TODO: Return a "retry" flag?
332-
log("DMA has not started, pushSuperpage only updates mTransferQueue");
333-
mTransferQueue.push_back(superpage);
334-
return;
335-
}
336-
337292
for (int i = 0; i < READYFIFO_ENTRIES; i++) { //TODO: *always* push 128 FIFO entries
338293
auto busAddress = getBusOffsetAddress(superpage.getOffset() + i * mPageSize);
339294
pushFreeFifoPage(i, busAddress);
@@ -378,7 +333,7 @@ void CrorcDmaChannel::fillSuperpages()
378333

379334
if (mFreeFifoBack == 0) { // Push the superpage after all of the 128 fifo entries are pushed
380335
auto superpage = mTransferQueue.front();
381-
superpage.setReceived(mPageSize * READYFIFO_ENTRIES); //TODO: Always full pages?
336+
superpage.setReceived(mPageSize * READYFIFO_ENTRIES); // Always full Superpages
382337
superpage.setReady(true);
383338
mReadyQueue.push_back(superpage);
384339
mTransferQueue.pop_front();

src/Crorc/CrorcDmaChannel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
6767

6868
/// Max amount of superpages in the ready queue (i.e. finished transfer).
6969
/// This is an arbitrary size, can easily be increased if more headroom is needed.
70-
static constexpr size_t READY_QUEUE_CAPACITY = TRANSFER_QUEUE_CAPACITY + 1; //Allow for some leeway
70+
static constexpr size_t READY_QUEUE_CAPACITY = TRANSFER_QUEUE_CAPACITY;
7171

7272

7373
/// Minimum number of superpages needed to bootstrap DMA

src/ParameterTypes/LoopbackMode.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static const auto converter = Utilities::makeEnumConverter<LoopbackMode::type>("
2222

2323
bool LoopbackMode::isExternal(const LoopbackMode::type& mode)
2424
{
25-
return mode == LoopbackMode::Siu || mode == LoopbackMode::Diu;
25+
return mode == LoopbackMode::Siu || mode == LoopbackMode::Diu || mode == LoopbackMode::None;
2626
}
2727

2828
std::string LoopbackMode::toString(const LoopbackMode::type& mode)

0 commit comments

Comments
 (0)