Skip to content

Commit 133874a

Browse files
committed
Bring CRORC DMA channel to a working beta state [WIP]
1 parent fadaf1a commit 133874a

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void CrorcDmaChannel::startPendingDma()
108108
return;
109109
}
110110

111-
if (mTransferQueue.size() < DMA_START_REQUIRED_SUPERPAGES) {
111+
if (mTransferQueue.empty()) { // We should never end up in here
112112
log("Insufficient superpages to start pending DMA");
113113
return;
114114
}
@@ -126,15 +126,16 @@ void CrorcDmaChannel::startPendingDma()
126126
// Resetting the card,according to the RESET LEVEL parameter
127127
deviceResetChannel(mInitialResetLevel);
128128

129+
// TODO: Move datareceiving at deviceStartDma?
129130
// Setting the card to be able to receive data
130131
startDataReceiving();
131132

132-
// Initializing the firmware FIFO, pushing (entries) pages
133-
for(size_t i = 0; i < DMA_START_REQUIRED_SUPERPAGES; ++i){
134-
getReadyFifoUser()->entries[i].reset();
135-
auto superpage = mTransferQueue[i];
136-
mReadyQueue.push_back();
137-
pushFreeFifoPage(i, getBusOffsetAddress(superpage.getOffset()));
133+
auto superpageToPush = mTransferQueue.front(); // Push the first superpage
134+
// After data receiving has begun
135+
for (size_t j = 0; j < READYFIFO_ENTRIES; j++) {
136+
auto offset = superpageToPush.getOffset() + j * mPageSize;
137+
pushFreeFifoPage(j, getBusOffsetAddress(offset));
138+
mFifoSize = 128;
138139
}
139140

140141
if (mGeneratorEnabled) {
@@ -155,22 +156,24 @@ void CrorcDmaChannel::startPendingDma()
155156
}
156157
}
157158

158-
/// Fixed wait for initial pages TODO polling wait with timeout
159-
std::this_thread::sleep_for(10ms);
160-
if (dataArrived(READYFIFO_ENTRIES - 1) != DataArrivalStatus::WholeArrived) {
159+
std::this_thread::sleep_for(100ms);
160+
161+
/// Fixed wait for initial pages TODO polling wait with timeout
162+
while ((dataArrived(READYFIFO_ENTRIES - 1) != DataArrivalStatus::WholeArrived)) {
163+
std::this_thread::sleep_for(100ms);
161164
log("Initial pages not arrived", InfoLogger::InfoLogger::Warning);
162165
}
163166

164-
for(size_t i = 0; i < DMA_START_REQUIRED_SUPERPAGES; ++i){
165-
auto superpage = mTransferQueue.front();
166-
mReadyQueue.push_back(superpage);
167-
mTransferQueue.pop_front();
168-
}
167+
// TODO: Move this read to fillSuperpages...
168+
auto superpageToReadout = mTransferQueue.front(); // Read the first Superpage
169+
mReadyQueue.push_back(superpageToReadout);
169170

170-
getReadyFifoUser()->reset();
171-
mFifoBack = 0;
171+
getReadyFifoUser()->reset(); // Reset ReadyFifo
172+
mFifoBack = 0; // Reset FreeFifo references
172173
mFifoSize = 0;
173174

175+
mTransferQueue.pop_front(); // Pop the Superpage after resets; don't introduce race conditions
176+
174177
mPendingDmaStart = false;
175178
log("DMA started");
176179
}
@@ -317,11 +320,20 @@ void CrorcDmaChannel::pushSuperpage(Superpage superpage)
317320
BOOST_THROW_EXCEPTION(Exception()
318321
<< ErrorInfo::Message("Could not push superpage, firmware queue was full (this should never happen)"));
319322
}
323+
324+
if (mPendingDmaStart) { // TODO: Don't let someone push more than one superpage at this stage
325+
// TODO: Return a "retry" flag?
326+
log("DMA has not started, pushSuperpage only updates mTransferQueue");
327+
mTransferQueue.push_back(superpage);
328+
return;
329+
}
320330

331+
for (int i = 0; i < READYFIFO_ENTRIES; i++) { //TODO: *always* push 128 FIFO entries
332+
auto busAddress = getBusOffsetAddress(superpage.getOffset() + i * mPageSize);
333+
pushFreeFifoPage(i, busAddress);
334+
mFifoSize++;
335+
}
321336
mTransferQueue.push_back(superpage);
322-
auto busAddress = getBusOffsetAddress(superpage.getOffset());
323-
pushFreeFifoPage(getFifoFront(), busAddress);
324-
mFifoSize++;
325337
}
326338

327339
auto CrorcDmaChannel::popSuperpage() -> Superpage
@@ -337,7 +349,7 @@ auto CrorcDmaChannel::popSuperpage() -> Superpage
337349
void CrorcDmaChannel::fillSuperpages()
338350
{
339351
if (mPendingDmaStart) {
340-
if (mTransferQueue.size() >= DMA_START_REQUIRED_SUPERPAGES) {
352+
if (!mTransferQueue.empty()) {
341353
startPendingDma();
342354
} else {
343355
// Waiting on enough superpages to start DMA...
@@ -358,11 +370,13 @@ void CrorcDmaChannel::fillSuperpages()
358370
mFifoSize--;
359371
mFifoBack = (mFifoBack + 1) % READYFIFO_ENTRIES;
360372

361-
auto superpage = mTransferQueue.front();
362-
superpage.setReceived(length);
363-
superpage.setReady(true);
364-
mReadyQueue.push_back(superpage);
365-
mTransferQueue.pop_front();
373+
if (mFifoSize == 0) { // Push the superpage after all of the 128 fifo entries are pushed
374+
auto superpage = mTransferQueue.front();
375+
superpage.setReceived(mPageSize * READYFIFO_ENTRIES); //TODO: Always full pages?
376+
superpage.setReady(true);
377+
mReadyQueue.push_back(superpage);
378+
mTransferQueue.pop_front();
379+
}
366380
} else {
367381
// If the back one hasn't arrived yet, the next ones will certainly not have arrived either...
368382
break;

src/Crorc/CrorcDmaChannel.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "CrorcBar.h"
1717
#include "ReadoutCard/Parameters.h"
1818
#include "ReadyFifo.h"
19-
#include "SuperpageQueue.h"
2019

2120
namespace AliceO2 {
2221
namespace roc {
@@ -57,15 +56,17 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
5756
virtual void deviceResetChannel(ResetLevel::type resetLevel) override;
5857

5958
private:
60-
/// Firmware FIFO Size
61-
static constexpr size_t TRANSFER_QUEUE_CAPACITY = READYFIFO_ENTRIES;
62-
6359
/// Max amount of superpages in the ready queue (i.e. finished transfer).
6460
/// This is an arbitrary size, can easily be increased if more headroom is needed.
65-
static constexpr size_t READY_QUEUE_CAPACITY = READYFIFO_ENTRIES;
61+
static constexpr size_t READY_QUEUE_CAPACITY = READYFIFO_ENTRIES / READYFIFO_ENTRIES; //Single 1Mi Superpage
62+
// TODO: Update to handle larger than 1Mi Superpages
63+
// A superpage should contain as many dma pages as possible
64+
65+
/// Max amount of superpages in the transfer queue (i.e. pending transfer).
66+
static constexpr size_t TRANSFER_QUEUE_CAPACITY = READY_QUEUE_CAPACITY;
6667

6768
/// Minimum number of superpages needed to bootstrap DMA
68-
static constexpr size_t DMA_START_REQUIRED_SUPERPAGES = 1;
69+
//static constexpr size_t DMA_START_REQUIRED_SUPERPAGES = 1;
6970
//static constexpr size_t DMA_START_REQUIRED_SUPERPAGES = READYFIFO_ENTRIES;
7071

7172
using SuperpageQueue = boost::circular_buffer<Superpage>;

0 commit comments

Comments
 (0)