X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/blast.git/blobdiff_plain/756baf5c8eaf003e8271dab9c395de2b0e704857..015e6979cd7d336f6bbebfbdb7916af3ba23c096:/AbstractBlock.cpp diff --git a/AbstractBlock.cpp b/AbstractBlock.cpp index cdde69f..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 = normalizeName(_name); + name = Parameters::normalizeName(_name); parent = NULL; } +*/ AbstractBlock::~AbstractBlock() { @@ -25,7 +31,7 @@ AbstractBlock::~AbstractBlock() { } void AbstractBlock::setName(const QString& str) { - name = normalizeName(str); + name = Parameters::normalizeName(str); } void AbstractBlock::setParent(AbstractBlock* _parent) { @@ -53,10 +59,12 @@ bool AbstractBlock::isSourceBlock() { } /* 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; } @@ -235,11 +243,51 @@ QList AbstractBlock::getWishboneParameters() { return lst; } -QString AbstractBlock::normalizeName(const QString &name) { - QString s = name; - s.replace(QRegularExpression("[^a-zA-Z0-9_]"),"_"); - s.replace(QRegularExpression("[_]+"),"_"); - return s; + + +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); + } + + } +