if ((purpose == Clock) || (purpose == Reset)) {
type = Boolean;
}
+ clkIfaceType = InheritedName;
}
bool GroupInterface::isGroupInterface() {
return w;
}
-bool GroupInterface::canConnectTo(AbstractInterface *iface) {
+bool GroupInterface::canConnectTo(AbstractInterface *iface, bool testClock) {
/* NOTE :
necessary conditions :
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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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 :
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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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) && (purpose == iface->getPurpose())) return true;
- if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) 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()->isStimuliBlock())) {
- if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) return true;
+ 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;
-
- GroupInterface* iface = NULL;
- if (clkIfaceType == ClockName) {
- iface = AI_TO_GRP(getClockIface());
- }
- else if ((direction == Input) && (purpose == Clock)) {
- iface = this;
- }
-
- if ( iface != NULL) {
-
- QString name = iface->getName();
- name.remove(0,8);
+ if ((purpose == Clock) || (purpose == Reset)) {
+ QString domName = name;
+ domName.remove(0,8);
bool ok;
- idClock = name.toInt(&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<ConnectedInterface*> 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<ConnectedInterface*> GroupInterface::getForwardFunctionalInterfaces(GroupInterface* groupIface) {
+ QList<ConnectedInterface*> 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<AbstractInterface*> *interfacetoValidate, QList<AbstractInterface*> *validatedInterfaces) throw(Exception) {
cout << "group interface connection validation" << endl;