Skip to content

Commit 120c4d6

Browse files
committed
[crorc] Improve data generator and loopback control
1 parent 9123c2b commit 120c4d6

File tree

5 files changed

+65
-48
lines changed

5 files changed

+65
-48
lines changed

src/Crorc/Constants.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/// \file Crorc/Constants.h
1212
/// \brief Definitions of RORC related constants
1313
/// Based on ddl_def.h and rorc.h
14+
1415
/// \author Pascal Boeschoten ([email protected])
1516
/// \author Kostas Alexopoulos ([email protected])
1617

@@ -356,39 +357,43 @@ static constexpr Register I2C_CMD(0x000000D0);
356357
// Register to control CRORC configuration
357358
// [15-4] -> CRORC ID
358359
// [0] -> FIXED/DYNAMIC OFFSET
359-
static constexpr Register CFG_CONTROL(0x000001f0);
360+
static constexpr Register CFG_CONTROL(0x000001F0);
360361

361362
// Register that contains the firmware hash
362-
static constexpr Register FIRMWARE_HASH(0x0000019c);
363+
static constexpr Register FIRMWARE_HASH(0x000001Cc);
363364

364365
// CRORC Control & Status Register
365366
static constexpr Register CRORC_CSR(0x00000000);
366367

367368
// CHANNEL Control & Status Register
368-
// [9] -> data receive ON / OFF
369-
// [23] -> FIFO NOT EMPTY
370-
static constexpr Register CHAN_CSR(0x00000010);
371-
static constexpr uint32_t DATA_RX_ON_OFF(0x00000200);
372-
static constexpr uint32_t RXSTAT_NOT_EMPTY(0x00800000);
373-
374-
// Channel Control & Status Register
375369
// [1] -> CRORC
376370
// [2] -> CHANNEL (can be used together - e.g. 0x3)
371+
// [9] -> data receive ON / OFF
372+
// [12] -> LOOPBACK ON OFF
373+
// [23] -> FIFO NOT EMPTY
377374
static constexpr Register CHANNEL_CSR(0x00000010);
378375
static constexpr uint32_t CRORC_RESET(0x00000003);
376+
static constexpr uint32_t DATA_RX_ON_OFF(0x00000200);
377+
static constexpr uint32_t RXSTAT_NOT_EMPTY(0x00800000);
378+
static constexpr uint32_t LOOPBACK_ON_OFF = 0x00001000;
379379

380380
// Channel Receive Report Base Address
381381
static constexpr Register CHANNEL_RRBAR(0x00000034);
382382
// Channel Receive Report Base Address Extension
383383
static constexpr Register CHANNEL_RRBARX(0x00000084);
384384

385-
// Register to send DDL commands
386-
static constexpr Register DDL_COMMAND(0x00000018); //TODO: Find a better name
385+
// Registers to send DDL commands
386+
static constexpr Register DDL_COMMAND(0x00000018);
387387
static constexpr Register DDL_STATUS(0x0000001C);
388388
static constexpr uint32_t SIU_RESET(0x000000F1);
389389
static constexpr uint32_t RDYRX(0x00000014);
390390
static constexpr uint32_t STBRD(0x00000054);
391391
static constexpr uint32_t EOBTR(0x000000B4);
392+
static constexpr uint32_t DIU_LOOPBACK(0x00000091);
393+
static constexpr uint32_t SIU_LOOPBACK(0x00000092);
394+
// Read & Clear Interface Status Word
395+
static constexpr uint32_t DIU_RANDCIFST(0x00000001);
396+
static constexpr uint32_t SIU_RANDCIFST(0x00000002);
392397

393398
// At bit 13
394399
static constexpr uint32_t LINK_DOWN(0x00002000);
@@ -401,6 +406,12 @@ static constexpr IntervalRegister OPT_POWER_QSFP1(0x00000158, 0x4);
401406
static constexpr Register RX_FIFO_ADDR_LOW(0x00000038);
402407
static constexpr Register RX_FIFO_ADDR_HIGH(0x0000003c);
403408
static constexpr Register RX_FIFO_ADDR_EXT(0x00000080);
409+
410+
// Data transmission status word
411+
static constexpr uint32_t DTSW(0x00000082);
412+
413+
// Register to configure the Data Generator
414+
static constexpr Register DATA_GENERATOR_CFG(0x00000020);
404415
} // namespace Registers
405416
} //namespace Crorc
406417

src/Crorc/CrorcBar.cxx

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ void CrorcBar::getOpticalPowers(std::map<int, Crorc::Link>& linkMap)
204204
}
205205
}
206206

207-
void CrorcBar::sendDdlCommand(uint32_t address, uint32_t command) // TODO: Is the address here always Crorc::Registers::DDL_COMMAND?
207+
void CrorcBar::sendDdlCommand(uint32_t address, uint32_t command)
208208
{
209209
writeRegister(address / 4, command);
210210

211211
auto checkFifoEmpty = [&]() {
212-
return readRegister(Crorc::Registers::CHAN_CSR.index) & Crorc::Registers::RXSTAT_NOT_EMPTY;
212+
return readRegister(Crorc::Registers::CHANNEL_CSR.index) & Crorc::Registers::RXSTAT_NOT_EMPTY;
213213
};
214214

215215
auto timeOut = std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
@@ -270,15 +270,15 @@ void CrorcBar::startDataReceiver(uintptr_t readyFifoBusAddress)
270270
writeRegister(Crorc::Registers::CHANNEL_RRBARX.index, 0x0);
271271
}
272272

273-
if (!(readRegister(Crorc::Registers::CHAN_CSR.index) & Crorc::Registers::DATA_RX_ON_OFF)) {
274-
writeRegister(Crorc::Registers::CHAN_CSR.index, Crorc::Registers::DATA_RX_ON_OFF);
273+
if (!(readRegister(Crorc::Registers::CHANNEL_CSR.index) & Crorc::Registers::DATA_RX_ON_OFF)) {
274+
writeRegister(Crorc::Registers::CHANNEL_CSR.index, Crorc::Registers::DATA_RX_ON_OFF);
275275
}
276276
}
277277

278278
void CrorcBar::stopDataReceiver()
279279
{
280-
if (readRegister(Crorc::Registers::CHAN_CSR.index) & Crorc::Registers::DATA_RX_ON_OFF) {
281-
writeRegister(Crorc::Registers::CHAN_CSR.index, Crorc::Registers::DATA_RX_ON_OFF);
280+
if (readRegister(Crorc::Registers::CHANNEL_CSR.index) & Crorc::Registers::DATA_RX_ON_OFF) {
281+
writeRegister(Crorc::Registers::CHANNEL_CSR.index, Crorc::Registers::DATA_RX_ON_OFF);
282282
}
283283
}
284284

@@ -289,14 +289,34 @@ void CrorcBar::pushRxFreeFifo(uintptr_t blockAddress, uint32_t blockLength, uint
289289
writeRegister(Crorc::Registers::RX_FIFO_ADDR_LOW.index, (blockLength << 8) | readyFifoIndex);
290290
}
291291

292-
/*void CrorcBar::startDataGenerator()
292+
void CrorcBar::startDataGenerator()
293293
{
294+
modifyRegister(Crorc::Registers::DATA_GENERATOR_CFG.index, 31, 1, 0x1);
294295
}
295296

296297
void CrorcBar::stopDataGenerator()
297298
{
299+
modifyRegister(Crorc::Registers::DATA_GENERATOR_CFG.index, 31, 1, 0x0);
300+
}
301+
302+
void CrorcBar::setLoopback()
303+
{
304+
if ((readRegister(Crorc::Registers::CHANNEL_CSR.index) & Crorc::Registers::LOOPBACK_ON_OFF) == 0x0) {
305+
writeRegister(Crorc::Registers::CHANNEL_CSR.index, Crorc::Registers::LOOPBACK_ON_OFF);
306+
}
307+
}
308+
309+
void CrorcBar::setDiuLoopback()
310+
{
311+
sendDdlCommand(Crorc::Registers::DDL_COMMAND.address, Crorc::Registers::DIU_LOOPBACK);
312+
// sendDdlCommand(Crorc::Registers::DDL_COMMAND.address, Crorc::Registers::DIU_RANDCIFST);
313+
}
314+
315+
void CrorcBar::setSiuLoopback()
316+
{
317+
sendDdlCommand(Crorc::Registers::DDL_COMMAND.address, Crorc::Registers::SIU_LOOPBACK);
318+
// sendDdlCommand(Crorc::Registers::DDL_COMMAND.address, Crorc::Registers::SIU_RANDCIFST);
298319
}
299-
*/
300320

301321
} // namespace roc
302322
} // namespace AliceO2

src/Crorc/CrorcBar.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#define ALICEO2_SRC_READOUTCARD_CRORC_CRORCBAR_H_
1919

2020
#include "BarInterfaceBase.h"
21-
#include "Crorc.h"
2221
#include "Crorc/Common.h"
2322
#include "Crorc/Constants.h"
2423
#include "Utilities/Util.h"
@@ -53,12 +52,17 @@ class CrorcBar final : public BarInterfaceBase
5352
void resetDevice(bool withSiu);
5453
void startDataReceiver(uintptr_t readyFifoBusAddress);
5554
void stopDataReceiver();
55+
void startDataGenerator();
56+
void stopDataGenerator();
5657
void startTrigger(uint32_t command);
5758
void stopTrigger();
5859
bool isLinkUp(int barIndex);
5960
bool checkLinkUp();
6061
void assertLinkUp();
6162
void pushRxFreeFifo(uintptr_t blockAddress, uint32_t blockLength, uint32_t readyFifoIndex);
63+
void setLoopback();
64+
void setDiuLoopback();
65+
void setSiuLoopback();
6266

6367
private:
6468
std::map<int, Crorc::Link> initializeLinkMap();

src/Crorc/CrorcDmaChannel.cxx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ CrorcDmaChannel::~CrorcDmaChannel()
112112

113113
void CrorcDmaChannel::deviceStartDma()
114114
{
115-
mDiuConfig = getCrorc().initDiuVersion(); //does nothing
116115
startDataReceiving();
117116

118117
log("DMA start deferred until enough superpages available");
@@ -144,7 +143,8 @@ void CrorcDmaChannel::startPendingDma()
144143

145144
if (mGeneratorEnabled) {
146145
log("Starting data generator");
147-
startDataGenerator(); //TODO: To be removed completely? Updated with instructions from PiPPo
146+
//getBar()->startDataGenerator();
147+
startDataGenerator();
148148
} else {
149149
if (mRDYRX || mSTBRD) {
150150
log("Starting trigger");
@@ -167,7 +167,7 @@ void CrorcDmaChannel::startPendingDma()
167167
void CrorcDmaChannel::deviceStopDma()
168168
{
169169
if (mGeneratorEnabled) {
170-
getCrorc().stopDataGenerator();
170+
getBar()->stopDataGenerator();
171171
} else {
172172
if (mRDYRX || mSTBRD) {
173173
// Sending EOBTR to FEE.
@@ -201,28 +201,19 @@ void CrorcDmaChannel::deviceResetChannel(ResetLevel::type resetLevel)
201201

202202
void CrorcDmaChannel::startDataGenerator() //TODO: Update this
203203
{
204-
getCrorc().armDataGenerator(mPageSize); //TODO: To be simplified
205-
206204
if (DataSource::Internal == mDataSource) {
207-
getCrorc().setLoopbackOn();
208-
std::this_thread::sleep_for(100ms); // XXX Why???
205+
getBar()->setLoopback(); //TODO: Is there a way to test this?
209206
}
210207

211-
if (DataSource::Siu == mDataSource) {
212-
getCrorc().setSiuLoopback(mDiuConfig);
213-
std::this_thread::sleep_for(100ms); // XXX Why???
214-
getCrorc().assertLinkUp();
215-
getCrorc().siuCommand(Ddl::RandCIFST); //TODO: To be removed
216-
getCrorc().diuCommand(Ddl::RandCIFST);
208+
if (DataSource::Diu == mDataSource) {
209+
getBar()->setDiuLoopback();
217210
}
218211

219-
if (DataSource::Diu == mDataSource) {
220-
getCrorc().setDiuLoopback(mDiuConfig);
221-
std::this_thread::sleep_for(100ms);
222-
getCrorc().diuCommand(Ddl::RandCIFST);
212+
if (DataSource::Siu == mDataSource) {
213+
getBar()->setSiuLoopback();
223214
}
224215

225-
getCrorc().startDataGenerator();
216+
getBar()->startDataGenerator();
226217
}
227218

228219
void CrorcDmaChannel::startDataReceiving()
@@ -360,7 +351,7 @@ CrorcDmaChannel::DataArrivalStatus::type CrorcDmaChannel::dataArrived(int index)
360351
return DataArrivalStatus::NoneArrived;
361352
} else if (status == 0) {
362353
return DataArrivalStatus::PartArrived;
363-
} else if ((status & 0xff) == Ddl::DTSW) {
354+
} else if ((status & 0xff) == Crorc::Registers::DTSW) {
364355
// Note: when internal loopback is used, the length of the event in words is also stored in the status word.
365356
// For example, the status word could be 0x400082 for events of size 4 kiB
366357
if ((status & (1 << 31)) != 0) {

src/Crorc/CrorcDmaChannel.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <unordered_map>
2222
#include <boost/scoped_ptr.hpp>
2323
#include "DmaChannelPdaBase.h"
24-
#include "Crorc.h"
2524
#include "CrorcBar.h"
2625
#include "ReadoutCard/Parameters.h"
2726
#include "ReadyFifo.h"
@@ -99,12 +98,6 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
9998
};
10099
};
101100

102-
/// C-RORC function helper
103-
Crorc::Crorc getCrorc()
104-
{
105-
return { *(getBar()) };
106-
}
107-
108101
ReadyFifo* getReadyFifoUser()
109102
{
110103
return reinterpret_cast<ReadyFifo*>(mReadyFifoAddressUser);
@@ -195,8 +188,6 @@ class CrorcDmaChannel final : public DmaChannelPdaBase
195188

196189
/// Enables the data generator
197190
bool mGeneratorEnabled;
198-
199-
Crorc::Crorc::DiuConfig mDiuConfig;
200191
};
201192

202193
} // namespace roc

0 commit comments

Comments
 (0)