+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<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;
+}
+