X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/abbc64cf04a35ab3549d5c516f44c7c5921baa63..HEAD:/FunctionalInterface.cpp diff --git a/FunctionalInterface.cpp b/FunctionalInterface.cpp index cc9f765..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,11 +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(); - level = reference->getLevel(); + purpose = reference->getPurpose(); connectedFrom = NULL; + clkIfaceName = reference->getClockIfaceString(); + clkIfaceType = reference->getClockIfaceType(); } bool FunctionalInterface::isFunctionalInterface() { @@ -65,10 +67,10 @@ int FunctionalInterface::getInterfaceMultiplicity() { return -1; } else if ( reference->getMultiplicity() == -1) { - return ifaceCount+1; + return ifaceCount; } - else if ( reference->getMultiplicity() > ifaceCount) { - return ifaceCount+1; + else if ( ifaceCount < reference->getMultiplicity()) { + return ifaceCount; } return -1; } @@ -77,16 +79,17 @@ AbstractInterface *FunctionalInterface::clone() { int id = getInterfaceMultiplicity(); if (id < 0) return NULL; FunctionalInterface *inter = new FunctionalInterface(owner, reference); - inter->setWidth(width); - inter->setDirection(direction); - inter->setPurpose(purpose); - inter->setLevel(level); - inter->connectFrom(NULL); - inter->setName(reference->getName()+"_"+QString::number(id)); + inter->setWidth(width); + inter->setName(reference->getName()+"_"+QString::number(id+1)); 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 : @@ -94,34 +97,80 @@ 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 2 - iface is owned by the parent group of the block that owns this 2.1 - this is an output, iface is an output of the group 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; - if (iface->getConnectedFrom() != NULL) 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()->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 : @@ -136,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) {