Skip to content

Commit a45fe7c

Browse files
committed
[dma] Implement for CRORC + cleanup
1 parent 66d0703 commit a45fe7c

File tree

2 files changed

+32
-41
lines changed

2 files changed

+32
-41
lines changed

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ void CrorcDmaChannel::deviceStopDma()
184184
}
185185
}
186186
getCrorc().stopDataReceiver();
187+
188+
// Return any filled superpages
189+
fillSuperpages();
190+
191+
// Return any superpages that have been pushed up in the meantime but won't get filled
192+
while (mTransferQueue.size()) {
193+
auto superpage = mTransferQueue.front();
194+
superpage.setReceived(0);
195+
superpage.setReady(false);
196+
mReadyQueue.push_back(superpage);
197+
mTransferQueue.pop_front();
198+
}
187199
}
188200

189201
void CrorcDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)

src/Cru/CruDmaChannel.cxx

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,7 @@ void CruDmaChannel::deviceStopDma()
164164
getBar2()->disableDataTaking();
165165

166166
// Transfer remaining (filled) superpages to ReadyQueue
167-
int moved = 0;
168-
for (auto& link : mLinks) {
169-
int32_t superpageCount = getBar()->getSuperpageCount(link.id);
170-
uint32_t amountAvailable = superpageCount - link.superpageCounter;
171-
//log((format("superpageCount %1% amountAvailable %2%") % superpageCount % amountAvailable).str());
172-
while (amountAvailable) {
173-
if (mReadyQueue.size() >= READY_QUEUE_CAPACITY) {
174-
break;
175-
}
176-
177-
if (!link.queue.empty()) {
178-
transferSuperpageFromLinkToReady(link);
179-
moved++;
180-
}
181-
amountAvailable--;
182-
}
183-
}
167+
fillSuperpages();
184168

185169
// Return any superpages that have been pushed up in the meantime but won't get filled
186170
for (auto& link : mLinks) {
@@ -197,8 +181,6 @@ void CruDmaChannel::deviceStopDma()
197181
InfoLogger::InfoLogger::Error);
198182
}
199183
}
200-
201-
log((format("Moved %1% remaining superpage(s) to ready queue") % moved).str());
202184
}
203185

204186
void CruDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)
@@ -319,30 +301,27 @@ void CruDmaChannel::transferSuperpageFromLinkToReady(Link& link)
319301
void CruDmaChannel::fillSuperpages()
320302
{
321303
// Check for arrivals & handle them
322-
const auto links = mLinks.size();
323-
for (LinkIndex linkIndex = 0; linkIndex < links; ++linkIndex) {
324-
auto& link = mLinks[linkIndex];
325-
uint32_t superpageCount = getBar()->getSuperpageCount(link.id);
326-
auto available = superpageCount > link.superpageCounter;
327-
if (available) {
328-
uint32_t amountAvailable = superpageCount - link.superpageCounter;
329-
if (amountAvailable > link.queue.size()) {
330-
std::stringstream stream;
331-
stream << "FATAL: Firmware reported more superpages available (" << amountAvailable << ") than should be present in FIFO (" << link.queue.size() << "); "
332-
<< link.superpageCounter << " superpages received from link " << int(link.id) << " according to driver, "
333-
<< superpageCount << " pushed according to firmware";
334-
log(stream.str(), InfoLogger::InfoLogger::Error);
335-
BOOST_THROW_EXCEPTION(Exception()
336-
<< ErrorInfo::Message("FATAL: Firmware reported more superpages available than should be present in FIFO"));
337-
}
304+
for (auto& link : mLinks) {
305+
int32_t superpageCount = getBar()->getSuperpageCount(link.id);
306+
uint32_t amountAvailable = superpageCount - link.superpageCounter;
307+
if (amountAvailable > link.queue.size()) {
308+
309+
std::stringstream stream;
310+
stream << "FATAL: Firmware reported more superpages available (" << amountAvailable << ") than should be present in FIFO (" << link.queue.size() << "); "
311+
<< link.superpageCounter << " superpages received from link " << int(link.id) << " according to driver, "
312+
<< superpageCount << " pushed according to firmware";
313+
log(stream.str(), InfoLogger::InfoLogger::Error);
314+
BOOST_THROW_EXCEPTION(Exception()
315+
<< ErrorInfo::Message("FATAL: Firmware reported more superpages available than should be present in FIFO"));
316+
}
338317

339-
for (uint32_t i = 0; i < amountAvailable; ++i) {
340-
if (mReadyQueue.size() >= READY_QUEUE_CAPACITY) {
341-
break;
342-
}
343-
// Front superpage has arrived
344-
transferSuperpageFromLinkToReady(link);
318+
while (amountAvailable) {
319+
if (mReadyQueue.size() >= READY_QUEUE_CAPACITY) {
320+
break;
345321
}
322+
323+
transferSuperpageFromLinkToReady(link);
324+
amountAvailable--;
346325
}
347326
}
348327
}

0 commit comments

Comments
 (0)