#include "SpecialBlock.h"\r
+#include "FunctionalInterface.h"\r
\r
-SpecialBlock::SpecialBlock(SpecialType _type, GroupBlock* _parent, ReferenceBlock* _reference, bool createIfaces) throw(Exception) : FunctionalBlock(_parent, _reference, createIfaces) {\r
- type = _type; \r
+SpecialBlock::SpecialBlock(Graph *_graph, int _type, GroupBlock* _parent, ReferenceBlock* _reference, bool createIfaces) throw(Exception) : FunctionalBlock(_graph, _parent, _reference, createIfaces) {\r
+ specialType = _type;\r
}\r
\r
SpecialBlock::~SpecialBlock() {\r
}\r
\r
+bool SpecialBlock::isSpecialBlock() {\r
+ return true;\r
+}\r
+\r
void SpecialBlock::checkInputPatternCompatibility() throw(Exception) {\r
try {\r
- switch(type) {\r
- case ClockConvert :\r
+ switch(specialType) {\r
+ case Source :\r
+ checkInputPatternCompatibilitySource();\r
+ break;\r
+ case Sink :\r
+ checkInputPatternCompatibilitySink();\r
+ break;\r
+ case ClkConvert :\r
checkInputPatternCompatibilityClockConvert();\r
break;\r
- case ClkRstGen:\r
- checkInputPatternCompatibilityClkRstGen();\r
+ default:\r
break;\r
}\r
}\r
\r
void SpecialBlock::computeOutputPattern(int nbExec) throw(Exception) {\r
try {\r
- switch(type) {\r
- case ClockConvert :\r
- computeOutputPatternClockConvert(nbExec);\r
+ switch(specialType) {\r
+ case Source :\r
+ computeOutputPatternSource(nbExec);\r
+ break;\r
+ case Sink :\r
+ computeOutputPatternSink(nbExec);\r
break;\r
- case ClkRstGen:\r
- computeOutputPatternClkRstGen(nbExec);\r
+ case ClkConvert :\r
+ computeOutputPatternClockConvert(nbExec);\r
+ break; \r
+ default:\r
break;\r
}\r
}\r
}\r
}\r
\r
-void SpecialBlock::checkInputPatternCompatibilityClockConvert() throw(Exception) {\r
+void SpecialBlock::checkInputPatternCompatibilitySource() throw(Exception) {\r
}\r
-void SpecialBlock::computeOutputPatternClockConvert(int nbExec) throw(Exception) {\r
+void SpecialBlock::computeOutputPatternSource(int nbExec) throw(Exception) {\r
+\r
+ cout << "computing output pattern of special block " << qPrintable(name) << " for " << nbExec << " executions" << endl;\r
+ foreach(AbstractInterface* iface, getControlOutputs()) {\r
+ FunctionalInterface* connIface = AI_TO_FUN(iface);\r
+ // create output pattern\r
+ QList<char>* pp = productionPattern.value(connIface);\r
+ QList<char>* pattern = new QList<char>(*pp);\r
+ for(int i=1;i<nbExec;i++) pattern->append(*pp);\r
+ // assign pattern to interface\r
+ connIface->setOutputPattern(pattern);\r
+ // store it in QMap\r
+ outputPattern.insert(connIface,pattern); \r
+ }\r
+ setOutputPatternComputed(true);\r
}\r
\r
+void SpecialBlock::checkInputPatternCompatibilitySink() throw(Exception) {\r
+}\r
+void SpecialBlock::computeOutputPatternSink(int nbExec) throw(Exception) {\r
+}\r
\r
-void SpecialBlock::checkInputPatternCompatibilityClkRstGen() throw(Exception) {\r
+void SpecialBlock::checkInputPatternCompatibilityClockConvert() throw(Exception) {\r
+ static QString fctName = "SpecialBlock::checkInputPatternCompatibilityClockConvert()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ // just create input pattern\r
+ try {\r
+ createInputPattern();\r
+ }\r
+ catch(Exception e) {\r
+ throw(e);\r
+ }\r
}\r
-void SpecialBlock::computeOutputPatternClkRstGen(int nbExec) throw(Exception) {\r
+\r
+void SpecialBlock::computeOutputPatternClockConvert(int nbExec) throw(Exception) {\r
+ static QString fctName = "SpecialBlock::computeOutputPatternClockConvert()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ cout << "computing output pattern of special block " << qPrintable(name) << endl;\r
+\r
+ /* CAUTION: it is assumed that all clock domain converters are using\r
+ * a clk_in and clk_out signals for input and output clocks.\r
+ */\r
+ AbstractInterface* clkIn = getIfaceFromName("clk_in");\r
+ AbstractInterface* clkOut = getIfaceFromName("clk_out");\r
+ cout << "freq clk_in = " << clkIn->getClockFrequency() << endl;\r
+ cout << "freq clk_out = " << clkOut->getClockFrequency() << endl; \r
+ double periodIn = 1000.0/clkIn->getClockFrequency();\r
+ double periodOut = 1000.0/clkOut->getClockFrequency();\r
+ cout << "period clk_in = " << periodIn << endl;\r
+ cout << "period clk_out = " << periodOut << endl;\r
+ // starts with 1 data in FIFO\r
+ int latency = 1+(int)((periodIn+5.0*periodOut)/periodOut);\r
+ QList<char> pattern;\r
+ for(int i=0;i<latency;i++) {\r
+ pattern.append(0);\r
+ }\r
+ int inFifo = 1;\r
+ int idIn = 1;\r
+ int idOut = 1;\r
+ while (idIn < lengthIP) {\r
+ double tIn = (double)idIn * periodIn;\r
+ double tOut = (double)idOut * periodOut;\r
+ if (fabs(tIn-tOut) < 0.001) {\r
+ if (inFifo > 0) {\r
+ pattern.append(1);\r
+ }\r
+ else {\r
+ pattern.append(0);\r
+ inFifo ++;\r
+ }\r
+ idIn ++;\r
+ idOut ++;\r
+ }\r
+ else if (tIn < tOut) {\r
+ inFifo++;\r
+ idIn ++;\r
+ }\r
+ else {\r
+ if (inFifo > 0) {\r
+ pattern.append(1);\r
+ inFifo--;\r
+ }\r
+ else {\r
+ pattern.append(0);\r
+ }\r
+ idOut++;\r
+ }\r
+ }\r
+ foreach(char c, pattern) cout << (int)c;\r
+ cout << endl;\r
+\r
+ // initialize the output pattern\r
+ lengthOP = pattern.size();\r
+ foreach(AbstractInterface* iface, getControlOutputs()) {\r
+ FunctionalInterface* connIface = AI_TO_FUN(iface); \r
+ QList<char>* pat = new QList<char>(pattern);\r
+ connIface->setOutputPattern(pat);\r
+ outputPattern.insert(connIface,pat);\r
+ }\r
+ cout << "output pattern computed" << endl;\r
}\r
+\r
+\r