Skip to content

Commit f88c35f

Browse files
committed
Handle debug register when running with the DG for the CRU
1 parent 197336e commit f88c35f

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

src/Cru/Constants.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ static constexpr uint32_t DATA_SOURCE_SELECT_INTERNAL = 0x1;
8585
/// * Write a 2 to reset data generator counter
8686
static constexpr Register RESET_CONTROL(0x00000400);
8787

88+
/// Debug register
89+
/// * Write 0x2 to set debug mode
90+
/// * Write 0x0 to unset
91+
static constexpr Register DEBUG(0x00000c00);
92+
8893
///*** bar2 ***///
8994

9095
///////////////////////////////////////////////////////////////////////////////////////////////////

src/Cru/CruBar.cxx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,5 +566,24 @@ void CruBar::disableDataTaking()
566566
modifyRegister(Cru::Registers::BSP_USER_CONTROL.index, 0, 1, 0x0);
567567
}
568568

569+
void CruBar::setDebugModeEnabled(bool enabled)
570+
{
571+
if (enabled) {
572+
writeRegister(Cru::Registers::DEBUG.index, 0x2);
573+
} else {
574+
writeRegister(Cru::Registers::DEBUG.index, 0x0);
575+
}
576+
}
577+
578+
bool CruBar::getDebugModeEnabled()
579+
{
580+
uint32_t debugMode = readRegister(Cru::Registers::DEBUG.index);
581+
if (debugMode == 0x0) {
582+
return false;
583+
} else {
584+
return true;
585+
}
586+
}
587+
569588
} // namespace roc
570589
} // namespace AliceO2

src/Cru/CruBar.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ class CruBar final : public BarInterfaceBase
7373
void configure() override;
7474
Cru::ReportInfo report();
7575

76+
void setDebugModeEnabled(bool enabled);
77+
bool getDebugModeEnabled();
78+
7679
private:
7780
uint32_t getSerialNumber();
7881
uint32_t getTemperatureRaw();

src/Cru/CruDmaChannel.cxx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ CruDmaChannel::~CruDmaChannel()
9696
{
9797
setBufferNonReady();
9898
if (mReadyQueue.size() > 0) {
99-
log((format("Remaining superpages in the ready queue: %1%") % mReadyQueue.size()).str()); }
99+
log((format("Remaining superpages in the ready queue: %1%") % mReadyQueue.size()).str());
100+
}
101+
102+
if (mLoopbackMode == LoopbackMode::Internal) {
103+
resetDebugMode();
104+
}
105+
100106
}
101107

102108
void CruDmaChannel::deviceStartDma()
@@ -110,6 +116,7 @@ void CruDmaChannel::deviceStartDma()
110116
uint32_t dataSourceSelection = 0x0;
111117
if (mGeneratorEnabled) {
112118
if (mLoopbackMode == LoopbackMode::Internal) {
119+
enableDebugMode();
113120
dataSourceSelection = Cru::Registers::DATA_SOURCE_SELECT_INTERNAL;
114121
} else if (mLoopbackMode == LoopbackMode::Ddg) {
115122
dataSourceSelection = Cru::Registers::DATA_SOURCE_SELECT_GBT;
@@ -337,6 +344,19 @@ bool CruDmaChannel::injectError()
337344
}
338345
}
339346

347+
void CruDmaChannel::enableDebugMode() {
348+
if(!getBar()->getDebugModeEnabled()) {
349+
getBar()->setDebugModeEnabled(true);
350+
mDebugRegisterReset = true;
351+
}
352+
}
353+
354+
void CruDmaChannel::resetDebugMode() {
355+
if (mDebugRegisterReset) {
356+
getBar()->setDebugModeEnabled(false);
357+
}
358+
}
359+
340360
boost::optional<int32_t> CruDmaChannel::getSerial()
341361
{
342362
if (mFeatures.serial) {

src/Cru/CruDmaChannel.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ class CruDmaChannel final : public DmaChannelPdaBase
106106
/// Mark the front superpage of a link ready and transfer it to the ready queue
107107
void transferSuperpageFromLinkToReady(Link& link);
108108

109+
/// Enable debug mode by writing to the appropriate CRU register
110+
void enableDebugMode();
111+
112+
/// Reset debug mode to the state it was in prior to the start of execution
113+
void resetDebugMode();
114+
109115
/// BAR 0 is needed for DMA engine interaction and various other functions
110116
std::shared_ptr<CruBar> cruBar;
111117

@@ -155,6 +161,9 @@ class CruDmaChannel final : public DmaChannelPdaBase
155161

156162
/// Length of data written to each page
157163
const size_t mGeneratorDataSize;
164+
165+
/// Flag to know if we should reset the debug register after we fiddle with it
166+
bool mDebugRegisterReset = false;
158167
};
159168

160169
} // namespace roc

0 commit comments

Comments
 (0)