From 47bd186f5ef9fcf0103c963d8e66d53f0c514aa4 Mon Sep 17 00:00:00 2001 From: Daniel Krebs Date: Mon, 4 Jun 2018 17:28:40 +0200 Subject: [PATCH] ip-node: move stream graph to IpNode and add easy-to-use connect interface --- fpga/include/villas/fpga/ip_node.hpp | 22 ++++++++++++++++------ fpga/include/villas/fpga/ips/dma.hpp | 8 ++++++++ fpga/lib/ip_node.cpp | 25 ++++++++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/fpga/include/villas/fpga/ip_node.hpp b/fpga/include/villas/fpga/ip_node.hpp index 00ce93a56..964070991 100644 --- a/fpga/include/villas/fpga/ip_node.hpp +++ b/fpga/include/villas/fpga/ip_node.hpp @@ -86,11 +86,6 @@ public: }; -extern StreamGraph streamGraph; - - -// TODO: reflect on interface that an IpNode exposes and how to design it to -// blend in with VILLASnode software nodes class IpNode : public IpCore { public: @@ -102,7 +97,6 @@ public: }; bool connect(const StreamVertex& from, const StreamVertex& to); - bool disconnect(std::string portName); const StreamVertex& getMasterPort(const std::string& name) const @@ -112,6 +106,20 @@ public: getSlavePort(const std::string& name) const { return *portsSlave.at(name); } + // easy-usage assuming that the slave IP to connect to only has one slave + // port and implements the getDefaultSlavePort() function + bool connect(const IpNode& slaveNode) + { return this->connect(this->getDefaultMasterPort(), slaveNode.getDefaultSlavePort()); } + + // used by easy-usage connect, will throw if not implemented by derived node + virtual const StreamVertex& + getDefaultSlavePort() const; + + // used by easy-usage connect, will throw if not implemented by derived node + virtual const StreamVertex& + getDefaultMasterPort() const; + + bool loopbackPossible() const; bool connectLoopback(); @@ -126,6 +134,8 @@ private: protected: std::map> portsMaster; std::map> portsSlave; + + static StreamGraph streamGraph; }; class IpNodeFactory : public IpCoreFactory { diff --git a/fpga/include/villas/fpga/ips/dma.hpp b/fpga/include/villas/fpga/ips/dma.hpp index a321d8ba4..963c20cda 100644 --- a/fpga/include/villas/fpga/ips/dma.hpp +++ b/fpga/include/villas/fpga/ips/dma.hpp @@ -60,6 +60,14 @@ public: hasScatterGather() const { return hasSG; } + const StreamVertex& + getDefaultSlavePort() const + { return getSlavePort(s2mmPort); } + + const StreamVertex& + getDefaultMasterPort() const + { return getMasterPort(mm2sPort); } + private: bool writeSG(const void* buf, size_t len); bool readSG(void* buf, size_t len); diff --git a/fpga/lib/ip_node.cpp b/fpga/lib/ip_node.cpp index d1d8b49a2..be5af573c 100644 --- a/fpga/lib/ip_node.cpp +++ b/fpga/lib/ip_node.cpp @@ -13,7 +13,8 @@ namespace fpga { namespace ip { -StreamGraph streamGraph; +StreamGraph +IpNode::streamGraph; bool IpNodeFactory::configureJson(IpCore& ip, json_t* json_ip) @@ -55,20 +56,20 @@ IpNodeFactory::configureJson(IpCore& ip, json_t* json_ip) const bool isMaster = (role == "master" or role == "initiator"); - auto thisVertex = streamGraph.getOrCreateStreamVertex( + auto thisVertex = IpNode::streamGraph.getOrCreateStreamVertex( ip.getInstanceName(), name_raw, isMaster); - auto connectedVertex = streamGraph.getOrCreateStreamVertex( + auto connectedVertex = IpNode::streamGraph.getOrCreateStreamVertex( tokens[0], tokens[1], not isMaster); if(isMaster) { - streamGraph.addDefaultEdge(thisVertex->getIdentifier(), - connectedVertex->getIdentifier()); + IpNode::streamGraph.addDefaultEdge(thisVertex->getIdentifier(), + connectedVertex->getIdentifier()); ipNode.portsMaster[name_raw] = thisVertex; } else /* slave */ { ipNode.portsSlave[name_raw] = thisVertex; @@ -143,6 +144,20 @@ bool IpNode::connect(const StreamVertex& from, const StreamVertex& to) return nextHopNodeIp->connect(*nextHopNode, to); } +const StreamVertex& +IpNode::getDefaultSlavePort() const +{ + logger->error("No default slave port available"); + throw std::exception(); +} + +const StreamVertex& +IpNode::getDefaultMasterPort() const +{ + logger->error("No default master port available"); + throw std::exception(); +} + bool IpNode::loopbackPossible() const {