X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/0d3590739ff5a4ca9e87c052ac142f5d1d3a68ab..9bfa0c13066918f440ac2b5461fb3f8847f43fd6:/AbstractBlock.cpp diff --git a/AbstractBlock.cpp b/AbstractBlock.cpp index ba1c179..b78a1e1 100644 --- a/AbstractBlock.cpp +++ b/AbstractBlock.cpp @@ -3,16 +3,22 @@ #include #include "AbstractInterface.h" #include "BlockParameter.h" +#include "Parameters.h" +#include "GroupBlock.h" +#include "ConnectedInterface.h" + AbstractBlock::AbstractBlock() { name = ""; parent = NULL; } +/* AbstractBlock::AbstractBlock(const QString& _name) { - name = _name; + name = Parameters::normalizeName(_name); parent = NULL; } +*/ AbstractBlock::~AbstractBlock() { @@ -25,7 +31,7 @@ AbstractBlock::~AbstractBlock() { } void AbstractBlock::setName(const QString& str) { - name = str; + name = Parameters::normalizeName(str); } void AbstractBlock::setParent(AbstractBlock* _parent) { @@ -44,6 +50,24 @@ bool AbstractBlock::isGroupBlock() { return false; } +bool AbstractBlock::isTopGroupBlock() { + return false; +} + +bool AbstractBlock::isSourceBlock() { + return false; +} +/* NB: a generator is a block that has no data inputs + * and has at least one data output. + * By the way, blokcs that have no data input/output + * (like clkrstgen) are not generators ! + */ +bool AbstractBlock::isGeneratorBlock() { + if (getDataInputs().size() > 0) return false; + if (getDataOutputs().size() == 0) return false; + return true; +} + void AbstractBlock::addParameter(BlockParameter *param) { params.append(param); } @@ -111,22 +135,58 @@ void AbstractBlock::defineBlockParam(BlockParameter *param) param->setValue(value); } -QList AbstractBlock::getInterfaces() { +QList AbstractBlock::getInterfaces(int direction, int purpose) { QList list; - list.append(inputs); - list.append(outputs); - list.append(bidirs); + bool selIn = false; + bool selOut = false; + bool selInOut = false; + + if (direction == AbstractInterface::AnyDirection) { + selIn = true; + selOut = true; + selInOut = true; + } + else if (direction == AbstractInterface::Input) { + selIn = true; + } + else if (direction == AbstractInterface::Output) { + selOut = true; + } + else if (direction == AbstractInterface::InOut) { + selInOut = true; + } + if (selIn) { + foreach(AbstractInterface* iface, inputs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } + if (selOut) { + foreach(AbstractInterface* iface, outputs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } + if (selInOut) { + foreach(AbstractInterface* iface, bidirs) { + if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); + } + } return list; } QList AbstractBlock::getDataInputs() { - QList list; - foreach(AbstractInterface* iface, inputs) { - if (iface->getPurpose() == AbstractInterface::Data) { - list.append(iface); - } - } - return list; + return getInterfaces(AbstractInterface::Input, AbstractInterface::Data); +} + +QList AbstractBlock::getDataOutputs() { + return getInterfaces(AbstractInterface::Output, AbstractInterface::Data); +} + +QList AbstractBlock::getControlInputs() { + return getInterfaces(AbstractInterface::Input, AbstractInterface::Control); +} + +QList AbstractBlock::getControlOutputs() { + return getInterfaces(AbstractInterface::Output, AbstractInterface::Control); } AbstractInterface* AbstractBlock::getIfaceFromName(QString name) { @@ -182,3 +242,52 @@ QList AbstractBlock::getWishboneParameters() { } return lst; } + + + +void AbstractBlock::connectClkReset() throw(Exception) { + + GroupBlock* parentBlock = AB_TO_GRP(parent); + + cout << "connecting clk/rst for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl; + + QList lstClk = getInterfaces(AbstractInterface::Input,AbstractInterface::Clock); + QList lstRst = getInterfaces(AbstractInterface::Input,AbstractInterface::Reset); + + if ((lstClk.isEmpty()) || (lstRst.isEmpty())) { + throw(Exception(IFACE_GROUP_NOCLKRST,this)); + } + + ConnectedInterface* toClk = AI_TO_CON(lstClk.at(0)); + ConnectedInterface* toRst = AI_TO_CON(lstRst.at(0)); + + ConnectedInterface* fromClk = NULL; + ConnectedInterface* fromRst = NULL; + + if (parentBlock->isTop()) { + AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName("clkrstgen"); + if (clkrstgen == NULL) { + throw(Exception(IFACE_TOP_NOCLKRSTGEN,this)); + } + else { + fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk")); + fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset")); + } + } + else { + fromClk = AI_TO_CON(parentBlock->getIfaceFromName("clk")); + fromRst = AI_TO_CON(parentBlock->getIfaceFromName("reset")); + } + if ((fromClk == NULL) || (fromRst == NULL)) { + throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock)); + } + else { + fromClk->connectTo(toClk); + fromRst->connectTo(toRst); + } + + +} + + +