mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fpga: fix configCrossBar crashing if src or dest are nullptr
Signed-off-by: Niklas Eiling <niklas.eiling@eonerc.rwth-aachen.de>
This commit is contained in:
parent
c62a0fb95b
commit
26a4d0a1ee
5 changed files with 29 additions and 8 deletions
|
@ -42,7 +42,7 @@ public:
|
|||
ConnectString(std::string &connectString, int maxPortNum = 7);
|
||||
void parseString(std::string &connectString);
|
||||
int portStringToInt(std::string &str) const;
|
||||
void configCrossBar(std::shared_ptr<villas::fpga::Card> card) const;
|
||||
bool configCrossBar(std::shared_ptr<villas::fpga::Card> card) const;
|
||||
bool isBidirectional() const { return bidirectional; };
|
||||
bool isDmaLoopback() const { return srcType == ConnectType::LOOPBACK; };
|
||||
bool isSrcStdin() const { return srcType == ConnectType::DMA; };
|
||||
|
|
|
@ -65,7 +65,10 @@ villasfpga_handle villasfpga_init(const char *configFile) {
|
|||
|
||||
// Configure Crossbar switch
|
||||
const fpga::ConnectString parsedConnectString(connectStr);
|
||||
parsedConnectString.configCrossBar(handle->card);
|
||||
if (!parsedConnectString.configCrossBar(handle->card)) {
|
||||
logger->error("Failed to configure crossbar");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return handle;
|
||||
} catch (const RuntimeError &e) {
|
||||
|
|
|
@ -130,20 +130,20 @@ int fpga::ConnectString::portStringToInt(std::string &str) const {
|
|||
}
|
||||
|
||||
// parses a string like "1->2" or "1<->stdout" and configures the crossbar accordingly
|
||||
void fpga::ConnectString::configCrossBar(
|
||||
bool fpga::ConnectString::configCrossBar(
|
||||
std::shared_ptr<villas::fpga::Card> card) const {
|
||||
|
||||
auto dma = std::dynamic_pointer_cast<fpga::ip::Dma>(
|
||||
card->lookupIp(fpga::Vlnv("xilinx.com:ip:axi_dma:")));
|
||||
if (dma == nullptr) {
|
||||
logger->error("No DMA found on FPGA ");
|
||||
throw std::runtime_error("No DMA found on FPGA");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isDmaLoopback()) {
|
||||
log->info("Configuring DMA loopback");
|
||||
dma->connectLoopback();
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
auto aurora_channels = getAuroraChannels(card);
|
||||
|
@ -176,7 +176,12 @@ void fpga::ConnectString::configCrossBar(
|
|||
} else if (aurora_channels->size() > 0) {
|
||||
src = (*aurora_channels)[srcAsInt];
|
||||
} else {
|
||||
throw std::runtime_error("No Aurora channels found on FPGA");
|
||||
logger->error("No Aurora channels found on FPGA");
|
||||
return false;
|
||||
}
|
||||
if (!src) {
|
||||
logger->error("Source does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dinoDac && dstType == ConnectType::DINO) {
|
||||
|
@ -185,6 +190,13 @@ void fpga::ConnectString::configCrossBar(
|
|||
dest = dma;
|
||||
} else if (aurora_channels->size() > 0) {
|
||||
dest = (*aurora_channels)[dstAsInt];
|
||||
} else {
|
||||
logger->error("No Aurora channels found on FPGA");
|
||||
return false;
|
||||
}
|
||||
if (!dest) {
|
||||
logger->error("Destination does not exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
src->connect(src->getDefaultMasterPort(), dest->getDefaultSlavePort());
|
||||
|
|
|
@ -186,7 +186,10 @@ int main(int argc, char *argv[]) {
|
|||
// Configure Crossbar switch
|
||||
for (std::string str : connectStr) {
|
||||
const fpga::ConnectString parsedConnectString(str);
|
||||
parsedConnectString.configCrossBar(card);
|
||||
if (!parsedConnectString.configCrossBar(card)) {
|
||||
logger->error("Failed to configure crossbar");
|
||||
return -1;
|
||||
}
|
||||
if (parsedConnectString.isSrcStdin()) {
|
||||
readFromStdin = true;
|
||||
if (parsedConnectString.isBidirectional()) {
|
||||
|
|
|
@ -69,7 +69,10 @@ int FpgaNode::prepare() {
|
|||
// Configure Crossbar switch
|
||||
for (std::string str : connectStrings) {
|
||||
const fpga::ConnectString parsedConnectString(str);
|
||||
parsedConnectString.configCrossBar(card);
|
||||
if (!parsedConnectString.configCrossBar(card)) {
|
||||
logger->error("Failed to configure crossbar");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
auto reg = std::dynamic_pointer_cast<fpga::ip::Register>(
|
||||
|
|
Loading…
Add table
Reference in a new issue