Skip to content

Commit

Permalink
[crorc] Add Register Sequence support for the CRORC
Browse files Browse the repository at this point in the history
  • Loading branch information
kostorr committed May 7, 2020
1 parent a6e5eb9 commit 6c65d4e
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 76 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The services are DIM RPC services. Every RPC is called with a string and expects

* Example:
* DIM input `reset\n0x0000000000badc0ffee,write\nread\n0xbadf00d,write\n4,read`
* DIM output `0\n0x0000000000badc0ffee\n0x000000000000badf00d\n`
* DIM output `0\n0x0000000000badc0ffee\n0\n0x000000000000badf00d\n`

#### IC_SEQUENCE

Expand Down
40 changes: 23 additions & 17 deletions apps/Alf.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,39 +87,45 @@ class Alf : public AliceO2::Common::Program
AlfServer alfServer = AlfServer();

std::vector<roc::CardDescriptor> cardsFound = roc::findCards();
int cruSequence = -1;
int cardSequence = -1;
for (auto const& card : cardsFound) {
std::vector<AlfLink> links;

std::shared_ptr<roc::BarInterface> bar2;
std::shared_ptr<roc::BarInterface> bar;

// Make the RPC services for every card & link
if (card.cardType == roc::CardType::Cru) {

if (!mOptions.noFirmwareCheck) {
try {
roc::FirmwareChecker().checkFirmwareCompatibility(card.pciAddress);
} catch (const roc::Exception& e) {
getWarningLogger() << boost::diagnostic_information(e) << endm;
continue;
}
if (!mOptions.noFirmwareCheck) {
try {
roc::FirmwareChecker().checkFirmwareCompatibility(card.pciAddress);
} catch (const roc::Exception& e) {
getWarningLogger() << boost::diagnostic_information(e) << endm;
continue;
}
}

cruSequence++;
cardSequence++;

getLogger() << "CRU #" << cruSequence << " : " << card.pciAddress << endm;
bar2 = roc::ChannelFactory().getBar(card.pciAddress, 2);
if (card.cardType == roc::CardType::Cru) {

getLogger() << "CRU #" << cardSequence << " : " << card.pciAddress << endm;
bar = roc::ChannelFactory().getBar(card.pciAddress, 2);
for (int linkId = 0; linkId < CRU_NUM_LINKS; linkId++) {
links.push_back({ alfId, cruSequence, linkId, bar2 });
links.push_back({ alfId, cardSequence, linkId, bar, roc::CardType::Cru });
}

} else if (card.cardType == roc::CardType::Crorc) {
getLogger() << "CRORC #" << cardSequence << " : " << card.pciAddress << endm;
for (int linkId = 0; linkId < CRORC_NUM_LINKS; linkId++) {
bar = roc::ChannelFactory().getBar(card.pciAddress, linkId);
links.push_back({ alfId, cardSequence, linkId, bar, roc::CardType::Crorc });
}
} else {
getLogger() << InfoLogger::InfoLogger::Severity::Warning << card.pciAddress << " is not a CRU. Skipping..." << endm;
getLogger() << InfoLogger::InfoLogger::Severity::Warning << card.pciAddress << " is not a CRU or a CRORC. Skipping..." << endm;
}

if (isVerbose()) {
for (auto const& link : links) {
getLogger() << link.alfId << " " << link.cruSequence << " " << link.linkId << endm;
getLogger() << link.alfId << " " << link.cardSequence << " " << link.linkId << endm;
}
}

Expand Down
31 changes: 25 additions & 6 deletions apps/AlfClient.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ class AlfClient : public AliceO2::Common::Program
options.add_options()("dim-dns-node",
po::value<std::string>(&mOptions.dimDnsNode)->default_value(""),
"The DIM DNS node to connect to if the env var is not set");
options.add_options()("cru-sequence",
po::value<int>(&mOptions.cruSequence),
"CRU sequence number");
options.add_options()("card-sequence",
po::value<int>(&mOptions.cardSequence),
"Card sequence number");
options.add_options()("link",
po::value<int>(&mOptions.link),
"Link number");
options.add_options()("alf-id",
po::value<std::string>(&mOptions.alfId)->default_value(""),
"Hostname of node running the ALF server(required)");
options.add_options()("crorc",
po::bool_switch(&mOptions.crorc)->default_value(false),
"Flag enabling the test of the crorc (exclusive)");
options.add_options()("ic",
po::bool_switch(&mOptions.ic)->default_value(false),
"Flag enabling the ic tests");
Expand Down Expand Up @@ -109,11 +112,26 @@ class AlfClient : public AliceO2::Common::Program
std::string alfId = mOptions.alfId;
boost::to_upper(alfId);

getLogger() << "Starting the DIM Client using ALF ID=" << alfId << ", cru #=" << mOptions.cruSequence << " and link=" << mOptions.link << endm;
getLogger() << "Starting the DIM Client using ALF ID=" << alfId << ", card #=" << mOptions.cardSequence << " and link=" << mOptions.link << endm;

AlfLink link = AlfLink{ alfId, mOptions.cruSequence, mOptions.link, nullptr };
AlfLink link = AlfLink{ alfId, mOptions.cardSequence, mOptions.link, nullptr, roc::CardType::Cru };

ServiceNames names(link);

if (mOptions.crorc) {
link.cardType = roc::CardType::Crorc;
Alf::RegisterSequenceRpc registerSequence(names.registerSequence());
auto regOut = registerSequence.write({ std::make_pair("0x19c", ""),
std::make_pair("0xa0", ""),
std::make_pair("0x1f0", ""),
std::make_pair("0x1f0", "0x00080000"),
std::make_pair("0x1f0", "") });
getLogger() << "[REGISTER SEQUENCE] output: " << regOut << endm;

return;
}

// Only CRU from this point forward
Alf::RegisterReadRpc registerReadRpc(names.registerRead());
Alf::RegisterWriteRpc registerWriteRpc(names.registerWrite());
Alf::PatternPlayerRpc patternPlayerRpc(names.patternPlayer());
Expand Down Expand Up @@ -214,9 +232,10 @@ class AlfClient : public AliceO2::Common::Program
private:
struct OptionsStruct {
std::string dimDnsNode = "";
int cruSequence = -1;
int cardSequence = -1;
int link = -1;
std::string alfId = "";
bool crorc = false;
bool ic = false;
bool sca = false;
bool swt = false;
Expand Down
39 changes: 39 additions & 0 deletions src/AlfClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,45 @@ class ScaSequenceRpc : DimRpcInfoWrapper
}
};

class RegisterSequenceRpc : DimRpcInfoWrapper
{
public:
RegisterSequenceRpc(const std::string& serviceName)
: DimRpcInfoWrapper(serviceName)
{
}

std::string write(const std::string& buffer)
{
std::cout << "Setting: " << buffer << std::endl;
setString(buffer);
std::string ret;
try {
ret = getString();
} catch (const AlfException& e) {
getErrorLogger() << "RegisterSequence: " << boost::diagnostic_information(e, true) << endm;
return errString;
}
return ret;
}

std::string write(const std::vector<std::pair<std::string, std::string>>& sequence)
{
std::stringstream buffer;
for (size_t i = 0; i < sequence.size(); ++i) {
if (sequence[i].second == "") { // It's a read
buffer << sequence[i].first;
} else { //It's a write
buffer << sequence[i].first << pairSeparator() << sequence[i].second;
}
if (i + 1 < sequence.size()) {
buffer << argumentSeparator();
}
}
return write(buffer.str());
}
};

class SwtSequenceRpc : DimRpcInfoWrapper
{
public:
Expand Down
115 changes: 82 additions & 33 deletions src/AlfServer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ AlfServer::AlfServer() : mRpcServers()
{
}

std::string AlfServer::registerRead(const std::string& parameter, std::shared_ptr<roc::BarInterface> bar2)
std::string AlfServer::registerRead(const std::string& parameter, std::shared_ptr<roc::BarInterface> bar)
{
uint32_t address = Util::stringToHex(parameter); // Error from here will get picked up by the StringRpcServer try clause
//Util::checkAddress(address);

uint32_t value = bar2->readRegister(address / 4);
uint32_t value = bar->readRegister(address / 4);
return Util::formatValue(value);
}

std::string AlfServer::registerWrite(const std::string& parameter, std::shared_ptr<roc::BarInterface> bar2)
std::string AlfServer::registerWrite(const std::string& parameter, std::shared_ptr<roc::BarInterface> bar)
{
std::vector<std::string> params = Util::split(parameter, pairSeparator());

Expand All @@ -54,10 +54,32 @@ std::string AlfServer::registerWrite(const std::string& parameter, std::shared_p
//Util::checkAddress(address);
uint32_t value = Util::stringToHex(params[1]);

bar2->writeRegister(address / 4, value);
bar->writeRegister(address / 4, value);
return "";
}

std::string AlfServer::registerBlobWrite(const std::string& parameter, AlfLink link)
{
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
std::vector<std::vector<uint32_t>> registerPairs = parseStringToRegisterPairs(stringPairs);
std::stringstream resultBuffer;
uint32_t value;
uint32_t address;
for (const auto& registerPair : registerPairs) {
address = registerPair.at(0);
if (registerPair.size() == 1) {
value = link.bar->readRegister(address / 4);
resultBuffer << Util::formatValue(value) << "\n";
} else if (registerPair.size() == 2) {
value = registerPair.at(1);
link.bar->writeRegister(address / 4, value);
resultBuffer << "0"
<< "\n";
}
}
return resultBuffer.str();
}

std::string AlfServer::scaBlobWrite(const std::string& parameter, AlfLink link)
{
std::vector<std::string> stringPairs = Util::split(parameter, argumentSeparator());
Expand Down Expand Up @@ -177,6 +199,16 @@ roc::PatternPlayer::Info AlfServer::parseStringToPatternPlayerInfo(const std::ve
return ppInfo;
}

std::vector<uint32_t> AlfServer::stringToRegisterPair(const std::string stringPair)
{
std::vector<uint32_t> registers;
auto stringRegisters = Util::split(stringPair, pairSeparator());
for (const auto& stringRegister : stringRegisters) {
registers.push_back(Util::stringToHex(stringRegister));
}
return registers;
}

std::pair<Sca::Data, Sca::Operation> AlfServer::stringToScaPair(const std::string stringPair)
{
std::vector<std::string> scaPair = Util::split(stringPair, pairSeparator());
Expand Down Expand Up @@ -209,7 +241,6 @@ std::pair<Sca::Data, Sca::Operation> AlfServer::stringToScaPair(const std::strin
/// Converts a 76-bit hex number string
std::pair<Swt::Data, Swt::Operation> AlfServer::stringToSwtPair(const std::string stringPair)
{
std::cout << "trigger" << std::endl;
std::vector<std::string> swtPair = Util::split(stringPair, pairSeparator());
if (swtPair.size() < 1 || swtPair.size() > 2) {
BOOST_THROW_EXCEPTION(
Expand Down Expand Up @@ -346,6 +377,17 @@ std::pair<Ic::IcData, Ic::Operation> AlfServer::stringToIcPair(const std::string
return std::make_pair(icData, icOperation);
}

std::vector<std::vector<uint32_t>> AlfServer::parseStringToRegisterPairs(std::vector<std::string> stringPairs)
{
std::vector<std::vector<uint32_t>> pairs;
for (const auto& stringPair : stringPairs) {
if (stringPair.find('#') == std::string::npos) {
pairs.push_back(stringToRegisterPair(stringPair));
}
}
return pairs;
}

std::vector<std::pair<Sca::Data, Sca::Operation>> AlfServer::parseStringToScaPairs(std::vector<std::string> stringPairs)
{
std::vector<std::pair<Sca::Data, Sca::Operation>> pairs;
Expand Down Expand Up @@ -394,35 +436,42 @@ void AlfServer::makeRpcServers(std::vector<AlfLink> links)
ServiceNames names(link);

// Start the RPC Servers
auto& servers = mRpcServers[link.cruSequence][link.linkId];
std::shared_ptr<roc::BarInterface> bar2 = link.bar2;

if (link.linkId == 0) { // Register Read / Write services are per card; register them as soon as possible
// Register Read
servers.push_back(makeServer(names.registerRead(),
[bar2](auto parameter) { return registerRead(parameter, bar2); }));
// Register Write
servers.push_back(makeServer(names.registerWrite(),
[bar2](auto parameter) { return registerWrite(parameter, bar2); }));

// Register Write
servers.push_back(makeServer(names.patternPlayer(),
[bar2](auto parameter) { return patternPlayer(parameter, bar2); }));
}
auto& servers = mRpcServers[link.cardSequence][link.linkId];
std::shared_ptr<roc::BarInterface> bar = link.bar;

if (link.cardType == roc::CardType::Cru) {
if (link.linkId == 0) { // Register Read / Write services are per card; register them as soon as possible
// Register Read
servers.push_back(makeServer(names.registerRead(),
[bar](auto parameter) { return registerRead(parameter, bar); }));
// Register Write
servers.push_back(makeServer(names.registerWrite(),
[bar](auto parameter) { return registerWrite(parameter, bar); }));

// Pattern Player
servers.push_back(makeServer(names.patternPlayer(),
[bar](auto parameter) { return patternPlayer(parameter, bar); }));
}

// SCA Sequence
servers.push_back(makeServer(names.scaSequence(),
[link](auto parameter) { return scaBlobWrite(parameter, link); }));
// SWT Sequence
servers.push_back(makeServer(names.swtSequence(),
[link](auto parameter) { return swtBlobWrite(parameter, link); }));
// IC Sequence
servers.push_back(makeServer(names.icSequence(),
[link](auto parameter) { return icBlobWrite(parameter, link); }));

// IC GBT I2C write
servers.push_back(makeServer(names.icGbtI2cWrite(),
[link](auto parameter) { return icGbtI2cWrite(parameter, link); }));
// SCA Sequence
servers.push_back(makeServer(names.scaSequence(),
[link](auto parameter) { return scaBlobWrite(parameter, link); }));
// SWT Sequence
servers.push_back(makeServer(names.swtSequence(),
[link](auto parameter) { return swtBlobWrite(parameter, link); }));
// IC Sequence
servers.push_back(makeServer(names.icSequence(),
[link](auto parameter) { return icBlobWrite(parameter, link); }));

// IC GBT I2C write
servers.push_back(makeServer(names.icGbtI2cWrite(),
[link](auto parameter) { return icGbtI2cWrite(parameter, link); }));

} else if (link.cardType == roc::CardType::Crorc) {
// Register Sequence
servers.push_back(makeServer(names.registerSequence(),
[link](auto parameter) { return registerBlobWrite(parameter, link); }));
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/AlfServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ class AlfServer
static std::string icBlobWrite(const std::string& parameter, AlfLink link);
static std::string icGbtI2cWrite(const std::string& parameter, AlfLink link);
static std::string patternPlayer(const std::string& parameter, std::shared_ptr<roc::BarInterface>);
static std::string registerBlobWrite(const std::string& parameter, AlfLink link);

static std::vector<uint32_t> stringToRegisterPair(const std::string stringPair);
static std::pair<Sca::Data, Sca::Operation> stringToScaPair(const std::string stringPair);
static std::pair<Swt::Data, Swt::Operation> stringToSwtPair(const std::string stringPair);
static std::pair<Ic::IcData, Ic::Operation> stringToIcPair(const std::string stringPair);
static std::vector<std::vector<uint32_t>> parseStringToRegisterPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Sca::Data, Sca::Operation>> parseStringToScaPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Swt::Data, Swt::Operation>> parseStringToSwtPairs(std::vector<std::string> stringPairs);
static std::vector<std::pair<Ic::IcData, Ic::Operation>> parseStringToIcPairs(std::vector<std::string> stringPairs);
static roc::PatternPlayer::Info parseStringToPatternPlayerInfo(const std::vector<std::string> sringsPairs);

/// cruSequence -> link -> vector of RPC servers
/// cardSequence -> link -> vector of RPC servers
std::map<int, std::map<int, std::vector<std::unique_ptr<StringRpcServer>>>> mRpcServers;
};

Expand Down
6 changes: 4 additions & 2 deletions src/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <chrono>
#include "ReadoutCard/BarInterface.h"
#include "ReadoutCard/CardType.h"

namespace AliceO2
{
Expand All @@ -33,9 +34,10 @@ static constexpr auto CHANNEL_BUSY_TIMEOUT = std::chrono::milliseconds(10);

struct AlfLink {
std::string alfId;
int cruSequence;
int cardSequence;
int linkId;
std::shared_ptr<roc::BarInterface> bar2;
std::shared_ptr<roc::BarInterface> bar;
roc::CardType::type cardType;
};

} // namespace Alf
Expand Down
Loading

0 comments on commit 6c65d4e

Please sign in to comment.