X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/3bbc311e444c1ef9ac66dd6861fb0acb13ddb72a..HEAD:/GroupInterface.cpp diff --git a/GroupInterface.cpp b/GroupInterface.cpp index 934ad08..db80b91 100644 --- a/GroupInterface.cpp +++ b/GroupInterface.cpp @@ -2,10 +2,15 @@ #include "FunctionalInterface.h" #include "GroupBlock.h" -GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,"inherited","",_direction,_purpose) { +GroupInterface::GroupInterface(AbstractBlock* _owner, const QString& _name, int _direction, int _purpose) throw(Exception) : ConnectedInterface(_owner,_name,_direction,_purpose,"inherited","") { if (! _owner->isGroupBlock()) throw(Exception(BLOCK_INVALID_TYPE)); connectedFrom = NULL; + // force clock and reset to boolean width type instead of inherited + if ((purpose == Clock) || (purpose == Reset)) { + type = Boolean; + } + clkIfaceType = InheritedName; } bool GroupInterface::isGroupInterface() { @@ -18,8 +23,29 @@ AbstractInterface *GroupInterface::clone() { return inter; } +int GroupInterface::getWidth() { + + bool ok; + int w = -1; + + QString expr = width; -bool GroupInterface::canConnectTo(AbstractInterface *iface) { + if (type == Boolean) { + return 1; + } + else if (type == Inherited) { + // must search from which iface it is connected. + ConnectedInterface* fromIface = connectedFrom; + while ((fromIface != NULL) && (fromIface->getType() == Inherited)) { + fromIface = fromIface->getConnectedFrom(); + } + if (fromIface == NULL) return -1; + w = fromIface->getWidth(); + } + return w; +} + +bool GroupInterface::canConnectTo(AbstractInterface *iface, bool testClock) { /* NOTE : necessary conditions : @@ -37,31 +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; - if (iface->getConnectedFrom() != NULL) 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 : @@ -80,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; }