return *_baseSlavePort;
}
+void
+BaseMasterPort::bind(Port &peer)
+{
+ _baseSlavePort = dynamic_cast<BaseSlavePort *>(&peer);
+ fatal_if(!_baseSlavePort, "Attempt to bind port %s to non-master port %s.",
+ name(), peer.name());
+ Port::bind(peer);
+}
+
+void
+BaseMasterPort::unbind()
+{
+ _baseSlavePort = nullptr;
+ Port::unbind();
+}
+
BaseSlavePort::BaseSlavePort(const std::string &name, PortID _id)
: Port(name, _id), _baseMasterPort(NULL)
{
return *_baseMasterPort;
}
+void
+BaseSlavePort::bind(Port &peer)
+{
+ _baseMasterPort = dynamic_cast<BaseMasterPort *>(&peer);
+ fatal_if(!_baseMasterPort, "Attempt to bind port %s to non-slave port %s.",
+ name(), peer.name());
+ Port::bind(peer);
+}
+
+void
+BaseSlavePort::unbind()
+{
+ _baseMasterPort = nullptr;
+ Port::unbind();
+}
+
/**
* Master port
*/
fatal("Attempt to bind port %s to non-slave port %s.",
name(), peer.name());
}
- // bind on the level of the base ports
- _baseSlavePort = slave_port;
-
// master port keeps track of the slave port
_slavePort = slave_port;
- _connected = true;
+ BaseMasterPort::bind(peer);
// slave port also keeps track of master port
_slavePort->slaveBind(*this);
}
panic("Attempting to unbind master port %s that is not connected\n",
name());
_slavePort->slaveUnbind();
- _slavePort = NULL;
- _connected = false;
- _baseSlavePort = NULL;
+ _slavePort = nullptr;
+ BaseMasterPort::unbind();
}
AddrRangeList
void
SlavePort::slaveUnbind()
{
- _baseMasterPort = NULL;
_masterPort = NULL;
- _connected = false;
+ BaseSlavePort::unbind();
}
void
SlavePort::slaveBind(MasterPort& master_port)
{
- _baseMasterPort = &master_port;
_masterPort = &master_port;
- _connected = true;
+ BaseSlavePort::bind(master_port);
}
Tick
public:
BaseSlavePort& getSlavePort() const;
+ void bind(Port &peer) override;
+ void unbind() override;
};
/**
public:
BaseMasterPort& getMasterPort() const;
+ void bind(Port &peer) override;
+ void unbind() override;
};
/** Forward declaration */
#include "sim/port.hh"
Port::Port(const std::string& _name, PortID _id) :
- portName(_name), id(_id), _connected(false)
+ portName(_name), id(_id), _peer(nullptr), _connected(false)
{}
Port::~Port() {}
* to InvalidPortID in case this port is not part of a vector.
*/
const PortID id;
+
+ /**
+ * A pointer to this port's peer.
+ */
+ Port *_peer;
+
+
/**
* Whether this port is currently connected to a peer port.
*/
public:
+ /** Return a reference to this port's peer. */
+ Port &getPeer() { return *_peer; }
+
/** Return port name (for DPRINTF). */
const std::string name() const { return portName; }
PortID getId() const { return id; }
/** Attach to a peer port. */
- virtual void bind(Port &peer) = 0;
+ virtual void
+ bind(Port &peer)
+ {
+ _peer = &peer;
+ _connected = true;
+ }
/** Dettach from a peer port. */
- virtual void unbind() = 0;
+ virtual void
+ unbind()
+ {
+ _peer = nullptr;
+ _connected = false;
+ }
/** Is this port currently connected to a peer? */
bool isConnected() const { return _connected; }
fatal("Attempt to bind sc_port %s to incompatible port %s.",
name(), peer.name());
}
+ Port::bind(peer);
}
private:
// Don't bind to peer otherwise we may have error messages saying that
// this interface has already be bound since the peer may already did
// that. Just let sc_port or sc_export do the binding
+ Port::bind(peer);
}
private:
name(), peer.name());
port_.bind(iface->interface());
+ Port::bind(peer);
}
private:
"incompatible port %s.", name(), peer.name());
initiator().bind(target->target());
+ Port::bind(peer);
}
void
{
// Ignore attempts to bind a target socket. The initiator will
// handle it.
+ Port::bind(peer);
}
void