+void FunctionalBlock::computeAdmittanceDelays() throw(Exception) {\r
+ static QString fctName = "FunctionalBlock::computeAdmittanceDelays()";\r
+#ifdef DEBUG_FCTNAME\r
+ cout << "call to " << qPrintable(fctName) << endl;\r
+#endif\r
+ QList<int> inClock;\r
+ QList<int> delays;\r
+\r
+ clearAdmittanceDelays();\r
+\r
+ // trying to synchronize the first one in AP\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterAP(admittance);\r
+ QMapIterator<AbstractInterface*,QList<char>* > iterIP(inputPattern);\r
+\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterIP.next();\r
+ QList<char>* ap = iterAP.value();\r
+ QList<char>* ip = iterIP.value();\r
+ int first = 0;\r
+ while ((first < lengthIP) && (ip->at(first) == 0)) first++;\r
+ while ((first < lengthAP) && (ap->at(first) == 0)) first--;\r
+ delays.append(first);\r
+ inClock.append(0);\r
+ QList<int>* delays = new QList<int>();\r
+ admittanceDelays.insert(iterAP.key(), delays);\r
+ }\r
+\r
+ QMapIterator<AbstractInterface*,QList<int>* > iterDelays(admittanceDelays);\r
+\r
+ // get the delay to apply\r
+ int maxDelay = 0;\r
+ for(int i=0;i<delays.size();i++) {\r
+ if (delays[i] > maxDelay) maxDelay = delays[i];\r
+ }\r
+ // adding the delays to IP\r
+ iterIP.toFront();\r
+ int i = 0;\r
+ while (iterIP.hasNext()) {\r
+ iterIP.next();\r
+ iterDelays.next();\r
+ QList<char>* ip = iterIP.value();\r
+ QList<int>* d = iterDelays.value();\r
+ d->append(maxDelay-delays[i]);\r
+ cout << "prependind " << qPrintable(iterIP.key()->getName()) << " with " << (maxDelay-delays[i]) << " 0" << endl;\r
+ for(int j=0;j<maxDelay-delays[i];j++) {\r
+ ip->prepend(0);\r
+ }\r
+ for(int j=0;j<delays[i];j++) {\r
+ ip->append(0);\r
+ }\r
+ i++;\r
+ }\r
+ lengthIP += maxDelay;\r
+\r
+ cout << "IP length = " << lengthIP << ", AP length = " << lengthAP << endl;\r
+ bool stop = false;\r
+ int apIndex = 0;\r
+ int ipIndex = 0;\r
+ while (!stop) {\r
+\r
+ // if AP is a valid group, search for the next valid group in IP\r
+ if (isValidDataGroup(admittance,apIndex)) {\r
+\r
+ while ((ipIndex < lengthIP) && (! isValidDataGroup(inputPattern,ipIndex))) ipIndex++;\r
+ if (ipIndex == lengthIP) {\r
+ stop = true;\r
+ continue;\r
+ }\r
+ }\r
+\r
+ iterAP.toFront();\r
+ iterIP.toFront();\r
+ iterDelays.toFront();\r
+\r
+ if (samePatterns(inputPattern,ipIndex,admittance,apIndex)) {\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterDelays.next();\r
+ QList<char>* ap = iterAP.value();\r
+ if (ap->at(apIndex) == 1) {\r
+ QList<int>* d = iterDelays.value();\r
+ d->append(0); // the 1 is at its good place, so no delay\r
+ }\r
+ }\r
+ }\r
+ else {\r
+ cout << "diff between IP and AP at " << apIndex << endl;\r
+ // search for the next 1 in IP for every input that has a 1 in AP\r
+\r
+ while (iterAP.hasNext()) {\r
+ iterAP.next();\r
+ iterIP.next();\r
+ iterDelays.next();\r
+ QList<char>* ap = iterAP.value();\r
+ QList<char>* ip = iterIP.value();\r
+ QList<int>* d = iterDelays.value();\r
+ // case 1: 1 in IP is too late\r
+ if ((ap->at(apIndex) == 1) && (ip->at(ipIndex) == 0)) {\r
+ int delay = 1;\r
+ while ( ((ipIndex+delay) < lengthIP) && (ip->at(ipIndex+delay) == 0) ) delay++;\r
+ cout << "found a delay of " << (-delay) << " for iface " << qPrintable(iterAP.key()->getName()) << endl;\r
+ // moving the 1 to its normal pos.\r
+ ip->replace(ipIndex,1);\r
+ ip->replace(ipIndex+delay,0);\r
+ d->append(-delay);\r
+ }\r
+ // case 2: 1 in IP is too soon\r
+ else if ((ap->at(apIndex) == 0) && (ip->at(ipIndex) == 1)) {\r
+ int delay = 1;\r
+ while ( ((apIndex+delay) < lengthAP) && (ap->at(apIndex+delay) == 0) ) delay++;\r
+ cout << "found a delay of " << delay << " for iface " << qPrintable(iterAP.key()->getName()) << endl;\r
+ // search for next 0 in IP to put the 1\r
+ int k = ipIndex+delay;\r
+ while ((k < lengthIP) && (ip->at(k) == 1)) k++;\r
+ ip->replace(ipIndex,0);\r
+ ip->replace(k,1);\r
+ d->append(delay);\r
+ }\r
+ }\r
+ if (! samePatterns(inputPattern,inClock,admittance,apIndex)) {\r
+ cout << "Abnormal case while searching for delays" << endl;\r
+ }\r
+ }\r
+\r
+ apIndex++;\r
+ ipIndex++;\r
+ if ((apIndex >= lengthAP) || (ipIndex >= lengthIP)) stop = true;\r
+ }\r
+ iterDelays.toFront();\r
+ while (iterDelays.hasNext()) {\r
+ iterDelays.next();\r
+ QList<int>* d = iterDelays.value();\r
+ foreach(int v, *d) {\r
+ cout << v << " ";\r
+ }\r
+ cout << endl;\r
+ }\r
+\r
+}\r
+\r