1 #include "SpecialBlock.h"
\r
2 #include "FunctionalInterface.h"
\r
4 SpecialBlock::SpecialBlock(Graph *_graph, int _type, GroupBlock* _parent, ReferenceBlock* _reference, bool createIfaces) throw(Exception) : FunctionalBlock(_graph, _parent, _reference, createIfaces) {
\r
8 SpecialBlock::~SpecialBlock() {
\r
11 bool SpecialBlock::isSpecialBlock() {
\r
15 void SpecialBlock::checkInputPatternCompatibility() throw(Exception) {
\r
17 switch(specialType) {
\r
19 checkInputPatternCompatibilitySource();
\r
22 checkInputPatternCompatibilitySink();
\r
25 checkInputPatternCompatibilityClockConvert();
\r
31 catch(Exception e) {
\r
36 void SpecialBlock::computeOutputPattern(int nbExec) throw(Exception) {
\r
38 switch(specialType) {
\r
40 computeOutputPatternSource(nbExec);
\r
43 computeOutputPatternSink(nbExec);
\r
46 computeOutputPatternClockConvert(nbExec);
\r
52 catch(Exception e) {
\r
57 void SpecialBlock::checkInputPatternCompatibilitySource() throw(Exception) {
\r
59 void SpecialBlock::computeOutputPatternSource(int nbExec) throw(Exception) {
\r
61 cout << "computing output pattern of special block " << qPrintable(name) << " for " << nbExec << " executions" << endl;
\r
62 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
63 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
64 // create output pattern
\r
65 QList<char>* pp = productionPattern.value(connIface);
\r
66 QList<char>* pattern = new QList<char>(*pp);
\r
67 for(int i=1;i<nbExec;i++) pattern->append(*pp);
\r
68 // assign pattern to interface
\r
69 connIface->setOutputPattern(pattern);
\r
71 outputPattern.insert(connIface,pattern);
\r
73 setOutputPatternComputed(true);
\r
76 void SpecialBlock::checkInputPatternCompatibilitySink() throw(Exception) {
\r
78 void SpecialBlock::computeOutputPatternSink(int nbExec) throw(Exception) {
\r
81 void SpecialBlock::checkInputPatternCompatibilityClockConvert() throw(Exception) {
\r
82 static QString fctName = "SpecialBlock::checkInputPatternCompatibilityClockConvert()";
\r
83 #ifdef DEBUG_FCTNAME
\r
84 cout << "call to " << qPrintable(fctName) << endl;
\r
86 // just create input pattern
\r
88 createInputPattern();
\r
90 catch(Exception e) {
\r
95 void SpecialBlock::computeOutputPatternClockConvert(int nbExec) throw(Exception) {
\r
96 static QString fctName = "SpecialBlock::computeOutputPatternClockConvert()";
\r
97 #ifdef DEBUG_FCTNAME
\r
98 cout << "call to " << qPrintable(fctName) << endl;
\r
100 cout << "computing output pattern of special block " << qPrintable(name) << endl;
\r
102 /* CAUTION: it is assumed that all clock domain converters are using
\r
103 * a clk_in and clk_out signals for input and output clocks.
\r
105 AbstractInterface* clkIn = getIfaceFromName("clk_in");
\r
106 AbstractInterface* clkOut = getIfaceFromName("clk_out");
\r
107 cout << "freq clk_in = " << clkIn->getClockFrequency() << endl;
\r
108 cout << "freq clk_out = " << clkOut->getClockFrequency() << endl;
\r
109 double periodIn = 1000.0/clkIn->getClockFrequency();
\r
110 double periodOut = 1000.0/clkOut->getClockFrequency();
\r
111 cout << "period clk_in = " << periodIn << endl;
\r
112 cout << "period clk_out = " << periodOut << endl;
\r
113 // starts with 1 data in FIFO
\r
114 int latency = 1+(int)((periodIn+5.0*periodOut)/periodOut);
\r
115 QList<char> pattern;
\r
116 for(int i=0;i<latency;i++) {
\r
122 while (idIn < lengthIP) {
\r
123 double tIn = (double)idIn * periodIn;
\r
124 double tOut = (double)idOut * periodOut;
\r
125 if (fabs(tIn-tOut) < 0.001) {
\r
136 else if (tIn < tOut) {
\r
151 foreach(char c, pattern) cout << (int)c;
\r
154 // initialize the output pattern
\r
155 lengthOP = pattern.size();
\r
156 foreach(AbstractInterface* iface, getControlOutputs()) {
\r
157 FunctionalInterface* connIface = AI_TO_FUN(iface);
\r
158 QList<char>* pat = new QList<char>(pattern);
\r
159 connIface->setOutputPattern(pat);
\r
160 outputPattern.insert(connIface,pat);
\r
162 setOutputPatternComputed(true);
\r
163 cout << "output pattern computed" << endl;
\r