+double Parameters::getFeedingClockFrequency(AbstractInterface *iface) {\r
+\r
+ int idClock = 0;\r
+\r
+ if (iface->isReferenceInterface()) return 0.0;\r
+\r
+ if (iface->getClockIfaceType() == AbstractInterface::ParameterName) {\r
+ BlockParameter* param = iface->getOwner()->getParameterFromName(iface->getClockIfaceString());\r
+ if (!param->isUserParameter()) return 0.0;\r
+ bool ok;\r
+ double freq = param->getDoubleValue(&ok);\r
+ if (!ok) {\r
+ cerr << "Abnormal case: cannot retrieve clock id from parameter " << qPrintable(param->getName()) << endl;\r
+ }\r
+ return freq;\r
+ }\r
+ else if ( (iface->getClockIfaceType() == AbstractInterface::ClockName) || ((iface->getDirection() == AbstractInterface::Input) && (iface->getPurpose() == AbstractInterface::Clock))) {\r
+\r
+ // if iface is not clock, retrieve the clock related to it\r
+ if (iface->getClockIfaceType() == AbstractInterface::ClockName) {\r
+ iface = iface->getClockIface();\r
+ }\r
+ // if iface is a group interface, then iface name is ext_clk_X, thus extract the X\r
+ if (iface->isGroupInterface()) {\r
+ QString name = iface->getName();\r
+ name.remove(0,8);\r
+ bool ok;\r
+ idClock = name.toInt(&ok);\r
+ if (!ok) {\r
+ cerr << "Abnormal case: cannot retrieve clock id from iface name " << qPrintable(iface->getName()) << endl;\r
+ return 0.0;\r
+ }\r
+ }\r
+ // if iface is a functional interface, it is connected to clkrstgen_X (in top group) or to ext_clk_X (in subgroup)\r
+ else if (iface->isFunctionalInterface()) {\r
+ FunctionalInterface* funIface = AI_TO_FUN(iface);\r
+ ConnectedInterface* connFrom = funIface->getConnectedFrom();\r
+ if (connFrom == NULL) {\r
+ cerr << "Abnormal case: input clock " << qPrintable(iface->getName()) << " is not connected" << endl;\r
+ return 0.0;\r
+ }\r
+ if (iface->getOwner()->isTopGroupBlock()) {\r
+ QString name = connFrom->getOwner()->getName();\r
+ name.remove(0,10);\r
+ bool ok;\r
+ idClock = name.toInt(&ok);\r
+ if (!ok) {\r
+ cerr << "Abnormal case: cannot retrieve clock id for " << qPrintable(iface->getName()) << endl;\r
+ return 0.0;\r
+ }\r
+ }\r
+ else {\r
+ QString name = connFrom->getName();\r
+ name.remove(0,8);\r
+ bool ok;\r
+ idClock = name.toInt(&ok);\r
+ if (!ok) {\r
+ cerr << "Abnormal case: cannot retrieve clock id for " << qPrintable(iface->getName()) << endl;\r
+ return 0.0;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ return graph->getClock(idClock);\r
+}\r
+\r
+void Parameters::createDelayBlock() {\r
+ delayRef = new ReferenceBlock("no.xml");\r
+ delayRef->addCategory(100);\r
+ delayRef->setName("delay");\r
+\r
+ BlockCategory* cat = categoryTree->searchCategory(100);\r
+ cat->blocks.append(delayRef);\r
+\r
+ AbstractInterface* interIn = new ReferenceInterface(delayRef,"data_in",AbstractInterface::Input, AbstractInterface::Data, "expression","$in_width");\r
+ delayRef->addInterface(interIn);\r
+ AbstractInterface* interInCtl = new ReferenceInterface(delayRef,"data_in_enb",AbstractInterface::Input, AbstractInterface::Control, "boolean","1");\r
+ delayRef->addInterface(interInCtl);\r
+ interInCtl->setAssociatedIface(interIn);\r
+ AbstractInterface* interOut = new ReferenceInterface(delayRef,"data_out",AbstractInterface::Output, AbstractInterface::Data, "expression","$in_width");\r
+ delayRef->addInterface(interOut);\r
+ AbstractInterface* interOutCtl = new ReferenceInterface(delayRef,"data_out_enb",AbstractInterface::Output, AbstractInterface::Control, "boolean","1");\r
+ delayRef->addInterface(interOutCtl);\r
+ interOutCtl->setAssociatedIface(interOut);\r
+ BlockParameter* param1 = new BlockParameterGeneric(delayRef,"in_width","natural","8");\r
+ BlockParameter* param2 = new BlockParameterGeneric(delayRef,"dly_length","natural","1");\r
+ delayRef->addParameter(param1);\r
+ delayRef->addParameter(param2);\r
+ delayImpl = new BlockImplementation("no.xml");\r
+ delayImpl->setDelta("1");\r
+ QHash<QString,QString> consPattern;\r
+ consPattern.insert("data_in_enb","1");\r
+ delayImpl->setConsumptionPattern(consPattern);\r
+ QHash<QString,QString> prodPattern;\r
+ prodPattern.insert("data_out_enb","O{$dly_length}1");\r
+ delayImpl->setProductionPattern(prodPattern);\r
+ delayImpl->setProductionCounter("1");\r
+ delayRef->addImplementation(delayImpl);\r
+ delayImpl->setReference(delayRef);\r
+ if (! delayImpl->checkPatterns()) {\r
+ cout << "Delay block creation: failure" << endl;\r
+ }\r
+ else {\r
+ cout << "Delay block creation: success" << endl;\r
+ }\r
+\r
+}\r
+\r