#include <QMessageBox>\r
#include "AbstractInterface.h"\r
#include "BlockParameter.h"\r
+#include "Parameters.h"\r
+#include "GroupBlock.h"\r
+#include "ConnectedInterface.h"\r
+\r
\r
AbstractBlock::AbstractBlock() {\r
name = "";\r
parent = NULL;\r
}\r
\r
+/*\r
AbstractBlock::AbstractBlock(const QString& _name) {\r
- name = _name;\r
+ name = Parameters::normalizeName(_name);\r
parent = NULL;\r
}\r
+*/\r
\r
AbstractBlock::~AbstractBlock() {\r
\r
}\r
\r
void AbstractBlock::setName(const QString& str) {\r
- name = str;\r
+ name = Parameters::normalizeName(str);\r
}\r
\r
void AbstractBlock::setParent(AbstractBlock* _parent) {\r
return false;\r
}\r
\r
+bool AbstractBlock::isTopGroupBlock() { \r
+ return false;\r
+}\r
+\r
+bool AbstractBlock::isSourceBlock() {\r
+ return false;\r
+}\r
+/* NB: a generator is a block that has no data inputs\r
+ * and has at least one data output.\r
+ * By the way, blokcs that have no data input/output\r
+ * (like clkrstgen) are not generators !\r
+ */\r
+bool AbstractBlock::isGeneratorBlock() {\r
+ if (getDataInputs().size() > 0) return false;\r
+ if (getDataOutputs().size() == 0) return false;\r
+ return true;\r
+}\r
+\r
void AbstractBlock::addParameter(BlockParameter *param) {\r
params.append(param);\r
}\r
param->setValue(value); \r
}\r
\r
-QList<AbstractInterface *> AbstractBlock::getInterfaces() {\r
+QList<AbstractInterface *> AbstractBlock::getInterfaces(int direction, int purpose) {\r
QList<AbstractInterface *> list;\r
- list.append(inputs);\r
- list.append(outputs);\r
- list.append(bidirs);\r
+ bool selIn = false;\r
+ bool selOut = false;\r
+ bool selInOut = false;\r
+ \r
+ if (direction == AbstractInterface::AnyDirection) {\r
+ selIn = true;\r
+ selOut = true;\r
+ selInOut = true;\r
+ }\r
+ else if (direction == AbstractInterface::Input) {\r
+ selIn = true; \r
+ }\r
+ else if (direction == AbstractInterface::Output) {\r
+ selOut = true; \r
+ }\r
+ else if (direction == AbstractInterface::InOut) {\r
+ selInOut = true; \r
+ }\r
+ if (selIn) {\r
+ foreach(AbstractInterface* iface, inputs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
+ if (selOut) {\r
+ foreach(AbstractInterface* iface, outputs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
+ if (selInOut) {\r
+ foreach(AbstractInterface* iface, bidirs) {\r
+ if ((iface->getPurpose() == purpose) || (purpose == AbstractInterface::AnyPurpose)) list.append(iface); \r
+ }\r
+ }\r
return list;\r
}\r
\r
+QList<AbstractInterface *> AbstractBlock::getDataInputs() {\r
+ return getInterfaces(AbstractInterface::Input, AbstractInterface::Data); \r
+}\r
+\r
+QList<AbstractInterface *> AbstractBlock::getDataOutputs() {\r
+ return getInterfaces(AbstractInterface::Output, AbstractInterface::Data); \r
+}\r
+\r
+QList<AbstractInterface *> AbstractBlock::getControlInputs() {\r
+ return getInterfaces(AbstractInterface::Input, AbstractInterface::Control); \r
+}\r
+\r
+QList<AbstractInterface *> AbstractBlock::getControlOutputs() {\r
+ return getInterfaces(AbstractInterface::Output, AbstractInterface::Control); \r
+}\r
+\r
AbstractInterface* AbstractBlock::getIfaceFromName(QString name) {\r
\r
foreach(AbstractInterface* iface, inputs) {\r
}\r
return lst;\r
}\r
+\r
+\r
+\r
+void AbstractBlock::connectClkReset() throw(Exception) {\r
+\r
+ GroupBlock* parentBlock = AB_TO_GRP(parent);\r
+\r
+ cout << "connecting clk/rst for child " << qPrintable(name) << " of " << qPrintable(parentBlock->getName()) << endl;\r
+\r
+ QList<AbstractInterface* > lstClk = getInterfaces(AbstractInterface::Input,AbstractInterface::Clock);\r
+ QList<AbstractInterface* > lstRst = getInterfaces(AbstractInterface::Input,AbstractInterface::Reset);\r
+\r
+ if ((lstClk.isEmpty()) || (lstRst.isEmpty())) {\r
+ throw(Exception(IFACE_GROUP_NOCLKRST,this));\r
+ }\r
+\r
+ ConnectedInterface* toClk = AI_TO_CON(lstClk.at(0));\r
+ ConnectedInterface* toRst = AI_TO_CON(lstRst.at(0));\r
+\r
+ ConnectedInterface* fromClk = NULL;\r
+ ConnectedInterface* fromRst = NULL;\r
+\r
+ if (parentBlock->isTop()) {\r
+ AbstractBlock* clkrstgen = parentBlock->getFunctionalBlockByName("clkrstgen");\r
+ if (clkrstgen == NULL) {\r
+ throw(Exception(IFACE_TOP_NOCLKRSTGEN,this));\r
+ }\r
+ else {\r
+ fromClk = AI_TO_CON(clkrstgen->getIfaceFromName("clk"));\r
+ fromRst = AI_TO_CON(clkrstgen->getIfaceFromName("reset"));\r
+ }\r
+ }\r
+ else {\r
+ fromClk = AI_TO_CON(parentBlock->getIfaceFromName("clk"));\r
+ fromRst = AI_TO_CON(parentBlock->getIfaceFromName("reset"));\r
+ }\r
+ if ((fromClk == NULL) || (fromRst == NULL)) {\r
+ throw(Exception(IFACE_GROUP_NOCLKRST,parentBlock));\r
+ }\r
+ else {\r
+ fromClk->connectTo(toClk);\r
+ fromRst->connectTo(toRst);\r
+ }\r
+\r
+\r
+}\r
+\r
+\r
+\r