]> AND Private Git Repository - blast.git/blobdiff - AbstractInterface.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
clkconvert OP compute done
[blast.git] / AbstractInterface.cpp
index 6b3d0092da463c1ec849cc05aa39d4c53feeb3c2..3fdd87ad152912f9a850b4ea96799c8f9a2ff6db 100644 (file)
@@ -2,10 +2,11 @@
 #include "BlockParameterPort.h"
 #include "AbstractBlock.h"
 #include "Parameters.h"
+#include "Graph.h"
 
 AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
 
-  owner = _owner;
+  owner = _owner;  
   name = "";
   width = "1";
   direction = Input;
@@ -13,6 +14,8 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner) {
   type = Boolean;
   endianess = LittleEndian;
   associatedIface = NULL;
+  clkIface = "";
+  clkIfaceType = 0;
 
 }
 
@@ -26,6 +29,8 @@ AbstractInterface::AbstractInterface(AbstractBlock* _owner, const QString& _name
   type = typeFromString(_type);
   endianess = _endianess;
   associatedIface = NULL;
+  clkIface = "";
+  clkIfaceType = 0;
 }
 
 AbstractInterface::AbstractInterface(AbstractInterface* other) {
@@ -37,6 +42,8 @@ AbstractInterface::AbstractInterface(AbstractInterface* other) {
   purpose = other->purpose;
   endianess = LittleEndian;
   associatedIface = NULL;
+  clkIface = other->clkIface;
+  clkIfaceType = other->clkIfaceType;
 }
 
 void AbstractInterface::setName(const QString& _name) {
@@ -186,36 +193,6 @@ QString AbstractInterface::getDirectionString() {
     return str;
 }
 
-double AbstractInterface::getDoubleWidth() throw(QException) {
-
-  static QString fctName = "AbstractInterface::getDoubleWidth()";
- #ifdef DEBUG_FCTNAME
-   cout << "call to " << qPrintable(fctName) << endl;
- #endif
-
-   /*
-    cout << "start AbstractInterface::getDoubleWidth()" << endl;
-    bool ok;
-    double width = getWidth().toDouble(&ok);
-
-    if(!ok){
-      ArithmeticEvaluator *evaluator = new ArithmeticEvaluator;
-      cout << "evaluator created!" << endl;
-      evaluator->setExpression(getWidth());
-      cout << "expression defined!" << endl;
-      foreach(BlockParameter *param, getOwner()->getParameters()){
-        evaluator->setVariableValue(param->getName(), param->getIntValue());
-        cout << "param : " << param->getName().toStdString() << " evaluated!" << endl;
-      }
-      width = evaluator->evaluate();
-      cout << "expression evaluated succefully!" << endl;
-    }
-    cout << "real width : " << width << endl;
-    return width;
-    */
-
-   return 1.0;
-}
 
 void AbstractInterface::setPurpose(int _purpose) {
   if ((_purpose>=Data) && (_purpose <= Wishbone)) {
@@ -237,6 +214,79 @@ bool AbstractInterface::setAssociatedIface(AbstractInterface* iface) {
   return true;
 }
 
+AbstractInterface* AbstractInterface::getClockIface() {
+  if (clkIfaceType == ClockName) {
+    return owner->getIfaceFromName(clkIface);
+  }
+  return NULL;
+}
+
+
+double AbstractInterface::getClockFrequency() throw(Exception) {
+
+  int idClock = -1;
+
+  if (clkIfaceType == ParameterName) {
+    BlockParameter* param = owner->getParameterFromName(clkIface);
+    if (!param->isUserParameter()) throw(Exception(IFACE_INVALID_CLKFREQ,this));
+    bool ok;
+    double freq = param->getDoubleValue(&ok);
+    if (!ok) throw(Exception(IFACE_INVALID_CLKFREQ,this));
+    return freq;
+  }
+  else {
+    try {
+      idClock = getClockDomain();
+    }
+    catch(Exception e) {
+      throw(e);
+    }
+    return owner->getGraph()->getClock(idClock);
+  }
+  return 0.0;
+}
+
+
+bool AbstractInterface::setClockIface(QString name) {
+  /* 2 cases :
+   *  - this is a Data interface
+   *  - this is a Clock output (from a clkrstgen)
+   *
+   *   iface must correspond to an existing clock interface name
+   * or a user parameter prepend with a $.
+   */
+  if ((purpose == Data) || ((purpose == Clock) && (direction == Output))) {
+    if (name.at(0) == '$') {
+      name.remove(0,1);
+      QList<BlockParameter* > params = owner->getUserParameters();
+      foreach(BlockParameter* p, params) {
+        if (p->getName() == name) {
+          clkIface = name;
+          clkIfaceType = ParameterName;
+          return true;
+        }
+      }
+      // error case: cannot found the input clock
+      return false;
+    }
+    else {
+      QList<AbstractInterface*> clocks = owner->getInterfaces(Input, Clock);
+      foreach(AbstractInterface* iface, clocks) {
+        if (iface->getName() == name) {
+          clkIface = name;
+          clkIfaceType = ClockName;
+          return true;
+        }
+      }
+      // error case: cannot found the user paramter
+      return false;
+    }
+  }
+  clkIface = "";
+  clkIfaceType = NoName;
+  return true;
+}
+
 
 int AbstractInterface::getIntDirection(QString str) {
     if(str == "input") return Input;