X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/6e2b3026c6a496e81642c373796bd39dad33d2a6..HEAD:/GroupInterface.cpp diff --git a/GroupInterface.cpp b/GroupInterface.cpp index c611ecf..db80b91 100644 --- a/GroupInterface.cpp +++ b/GroupInterface.cpp @@ -10,6 +10,7 @@ GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int if ((purpose == Clock) || (purpose == Reset)) { type = Boolean; } + clkIfaceType = InheritedName; } bool GroupInterface::isGroupInterface() { @@ -44,7 +45,7 @@ int GroupInterface::getWidth() { return w; } -bool GroupInterface::canConnectTo(AbstractInterface *iface) { +bool GroupInterface::canConnectTo(AbstractInterface *iface, bool testClock) { /* NOTE : necessary conditions : @@ -62,32 +63,53 @@ bool GroupInterface::canConnectTo(AbstractInterface *iface) { 2.1 - this is an output, iface is an output of the group 2.2 - both are inout - + NB: testClock is useless since a group interface has always a clkIfaceType inherited. + Thus, it is always possible */ + bool ok = false; + if (iface->isReferenceInterface()) return false; ConnectedInterface* connIface = AI_TO_CON(iface); if (connIface->getConnectedFrom() != NULL) return false; if (this->getOwner() == iface->getOwner()->getParent()) { - if ((direction == Input) && (iface->getDirection() == Input)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) { - if ((direction == Output) && (iface->getDirection() == Input)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Output) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } else if (this->getOwner()->getParent() == iface->getOwner()) { - if ((direction == Output) && (iface->getDirection() == Output)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } + if (ok) { + if (testClock) { + int dom1 = -1,dom2 = -2; + try { + dom1 = getClockDomain(); + dom2 = iface->getClockDomain(); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + return false; + } + if (dom1 != dom2) { + cout << "cannot connect interface that are in different clock domains" << endl; + return false; + } + } + return true; + } return false; } -bool GroupInterface::canConnectFrom(AbstractInterface *iface) { +bool GroupInterface::canConnectFrom(AbstractInterface *iface, bool testClock) { /* NOTE : necessary conditions : @@ -106,29 +128,107 @@ bool GroupInterface::canConnectFrom(AbstractInterface *iface) { 2.2 - both are inout 4 - this is owned by top group and iface is an output of a source block */ + bool ok = false; + if (iface->isReferenceInterface()) return false; if (getConnectedFrom() != NULL) return false; if (this->getOwner() == iface->getOwner()->getParent()) { - if ((direction == Output) && (iface->getDirection() == Output)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Output) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } else if (this->getOwner()->getParent() == iface->getOwner()->getParent()) { - if ((direction == Input) && (iface->getDirection() == Output)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } else if (this->getOwner()->getParent() == iface->getOwner()) { - if ((direction == Input) && (iface->getDirection() == Input)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if ((direction == Input) && (iface->getDirection() == Input) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } - else if ((getOwner()->isTopGroupBlock()) && (iface->getOwner()->isSourceBlock())) { - if ((direction == Input) && (iface->getDirection() == Output)) return true; + else if ((getOwner()->isTopGroupBlock()) && (iface->getOwner()->isStimuliBlock())) { + if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true; + } + + if (ok) { + if (testClock) { + int dom1 = -1,dom2 = -2; + try { + dom1 = getClockDomain(); + dom2 = iface->getClockDomain(); + } + catch(Exception e) { + cerr << qPrintable(e.getMessage()) << endl; + return false; + } + if (dom1 != dom2) { + cout << "cannot connect interface that are in different clock domains" << endl; + return false; + } + } + return true; } return false; } +int GroupInterface::getClockDomain() throw(Exception) { + + /* For clk/rst interfaces, the clock domain can be deduced + from the interface name. + Otherwise, we can search backward/forward for a functional + interface. Since a group interface cannot exist if it is not + connected to and/or from a functional interface (either directly + or through a sequence of subgroups) there is at least such a functional + interface. + */ + int idClock = -1; + if ((purpose == Clock) || (purpose == Reset)) { + QString domName = name; + domName.remove(0,8); + bool ok; + idClock = domName.toInt(&ok); + if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + } + else { + // start by searching backward + ConnectedInterface* connFrom = connectedFrom; + while ((connFrom != NULL) && (connFrom->isGroupInterface())) { + connFrom = connFrom->getConnectedFrom(); + } + if (connFrom != NULL) { + idClock = connFrom->getClockDomain(); + } + //searching forward + else { + QList lstIfaces = getForwardFunctionalInterfaces(this); + if (lstIfaces.isEmpty()) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + foreach(ConnectedInterface* iface, lstIfaces) { + // test if all ifaces are in the same clock domain + if (idClock == -1) { + idClock = iface->getClockDomain(); + } + else if (idClock != iface->getClockDomain()) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + } + } + } + + return idClock; +} + +QList GroupInterface::getForwardFunctionalInterfaces(GroupInterface* groupIface) { + QList lstIfaces; + foreach(ConnectedInterface* iface, groupIface->getConnectedTo()) { + if (iface->isFunctionalInterface()) { + lstIfaces.append(iface); + } + else if (iface->isGroupInterface()) { + lstIfaces.append(getForwardFunctionalInterfaces(AI_TO_GRP(iface))); + } + } + return lstIfaces; +} + void GroupInterface::connectionsValidation(QStack *interfacetoValidate, QList *validatedInterfaces) throw(Exception) { cout << "group interface connection validation" << endl; }