X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/48f48e6a26a54751ecd0ab90b10ab972cc5e89cd..HEAD:/FunctionalInterface.cpp?ds=sidebyside diff --git a/FunctionalInterface.cpp b/FunctionalInterface.cpp index 145b86a..3a225c7 100644 --- a/FunctionalInterface.cpp +++ b/FunctionalInterface.cpp @@ -5,7 +5,6 @@ #include "FunctionalBlock.h" #include "GroupBlock.h" - FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterface *_reference) throw(Exception) : ConnectedInterface(_owner) { if (_owner == NULL) throw(Exception(BLOCK_NULL)); @@ -17,10 +16,14 @@ FunctionalInterface::FunctionalInterface(AbstractBlock* _owner, ReferenceInterfa reference = _reference; name = reference->getName(); - width = reference->getWidth(); + type = reference->getType(); + endianess = reference->getEndianess(); + width = reference->getWidthString(); direction = reference->getDirection(); purpose = reference->getPurpose(); - connectedFrom = NULL; + connectedFrom = NULL; + clkIfaceName = reference->getClockIfaceString(); + clkIfaceType = reference->getClockIfaceType(); } bool FunctionalInterface::isFunctionalInterface() { @@ -81,7 +84,12 @@ AbstractInterface *FunctionalInterface::clone() { return inter; } -bool FunctionalInterface::canConnectTo(AbstractInterface *iface) { +bool FunctionalInterface::canConnectTo(AbstractInterface *iface, bool testClock) { + static QString fctName = "FunctionalInterface::canConnectTo()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif + /* NOTE : necessary conditions : @@ -89,7 +97,7 @@ bool FunctionalInterface::canConnectTo(AbstractInterface *iface) { - iface type must be functional or group interface - iface->connectedFrom must be NULL - valid cases: + valid "normal" cases: 1 - iface is owned by a block (group or func) that is within the same group as the block that own this 1.1 - this is output and iface is input 1.2 - both are inout @@ -98,31 +106,71 @@ bool FunctionalInterface::canConnectTo(AbstractInterface *iface) { 2.2 - both are inout 3 - this is owned by a source block and iface is owned by the top group + + if testClock is true, must test if both ifaces are in the same clock domain. Note that a group interface + has always + special case : clk/reset from clkrstgen can connect to stimuli clk/reset + */ + bool ok = false; + if (direction == Input) return false; if (iface->isReferenceInterface()) return false; ConnectedInterface* connIface = AI_TO_CON(iface); if (connIface->getConnectedFrom() != NULL) return false; + + // special case, NB: never tests clocks + if ((getOwner()->getName().startsWith("clkrstgen")) && (iface->getOwner()->isStimuliBlock())) { + if ((direction == Output) && (iface->getDirection() == Input)) { + if ((purpose == AbstractInterface::Clock) && (iface->getPurpose() == AbstractInterface::Clock)) return true; + else if ((purpose == AbstractInterface::Reset) && (iface->getPurpose() == AbstractInterface::Reset)) return true; + } + } + // first case: interface of blocks within the same group if (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; } // second case: iface = interface of the group that contains owner of this else if (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; } - else if ((getOwner()->isSourceBlock()) && (iface->getOwner()->isTopGroupBlock())) { - if ((direction == Output) && (iface->getDirection() == Input)) return true; + else if ((getOwner()->isStimuliBlock()) && (iface->getOwner()->isTopGroupBlock())) { + if ((direction == Output) && (iface->getDirection() == Input) && (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(fctName) << " - " << 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 FunctionalInterface::canConnectFrom(AbstractInterface *iface) { +bool FunctionalInterface::canConnectFrom(AbstractInterface *iface, bool testClock) { + + static QString fctName = "FunctionalInterface::canConnectFrom()"; +#ifdef DEBUG_FCTNAME + cout << "call to " << qPrintable(fctName) << endl; +#endif /* NOTE : necessary conditions : @@ -137,24 +185,99 @@ bool FunctionalInterface::canConnectFrom(AbstractInterface *iface) { 2 - iface is owned by the parent group of the block that owns this 2.1 - this is an input, iface is an input of the group 2.2 - both are inout + + special case : clk/reset of stimuli can connect from clk/reset of clkrstgen */ + bool ok = false; + if (direction == Output) return false; if (iface->isReferenceInterface()) return false; if (connectedFrom != NULL) return false; - if (getOwner()->getParent() == iface->getOwner()->getParent()) { + // special case, NB: never tests clock + if ((iface->getOwner()->getName().startsWith("clkrstgen")) && (getOwner()->isStimuliBlock())) { + if ((direction == Input) && (iface->getDirection() == Output)) { + if ((purpose == AbstractInterface::Clock) && (iface->getPurpose() == AbstractInterface::Clock)) return true; + else if ((purpose == AbstractInterface::Reset) && (iface->getPurpose() == AbstractInterface::Reset)) return true; + } + } - if ((direction == Input) && (iface->getDirection() == Output)) return true; - if ((direction == InOut) && (iface->getDirection() == InOut)) return true; + if (getOwner()->getParent() == iface->getOwner()->getParent()) { + if ((direction == Input) && (iface->getDirection() == Output) && (purpose == iface->getPurpose())) ok = true; + if ((direction == InOut) && (iface->getDirection() == InOut) && (purpose == iface->getPurpose())) ok = true; } else if (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; + } + + 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 interfaces that are in different clock domains" << endl; + return false; + } + } + return true; } return false; } +int FunctionalInterface::getClockDomain() throw(Exception) { + + int idClock = -1; + + FunctionalInterface* iface = NULL; + if (clkIfaceType == ClockName) { + iface = AI_TO_FUN(getClockIface()); + } + else if ((direction == Input) && (purpose == Clock)) { + iface = this; + } + + if ( iface != NULL) { + + // if iface is a functional interface, it is connected to clkrstgen_X (in top group) or to ext_clk_X (in subgroup) + ConnectedInterface* connFrom = iface->getConnectedFrom(); + if (connFrom == NULL) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + + if (connFrom->getOwner()->isFunctionalBlock()) { + QString domName = connFrom->getOwner()->getName(); + domName.remove(0,10); + cout << "conn from clkrstgen: searching for clkdomain in " << qPrintable(domName) << endl; + + bool ok = true; + idClock = domName.toInt(&ok); + cout << "id clock = " << idClock << endl; + if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + } + else if (connFrom->getOwner()->isGroupBlock()) { + QString domName = connFrom->getName(); + domName.remove(0,8); + cout << "conn from group: searching for clkdomain in " << qPrintable(domName) << endl; + + bool ok = true; + idClock = domName.toInt(&ok); + if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this)); + } + else { + cout << "abnormal case while searching for clkdomain" << endl; + } + } + + return idClock; +} + void FunctionalInterface::connectionsValidation(QStack *interfacetoValidate, QList *validatedInterfaces) throw(Exception) {