better debugging messages on ProperStopper
[fleet.git] / testCode / com / sun / vlsi / chips / marina / test / ProperStopper.java
index 2b21551..484ac8e 100644 (file)
@@ -7,6 +7,7 @@ import com.sun.async.test.ChainControl;
 import com.sun.async.test.ChipModel;
 import com.sun.async.test.Infrastructure;
 import com.sun.async.test.NanosimModel;
+import com.sun.async.test.VerilogModel;
 import com.sun.vlsi.chips.marina.test.MarinaUtils.StateWireState;
 
 public class ProperStopper {
@@ -25,14 +26,19 @@ public class ProperStopper {
     private static final int STOPPED_IN_NDX = 3;
         
     private final String name;
-    private final String captureClockRelPath = "fillStag@1.gaspFill@0.fillScan@1";
+    //private final String captureClockRelPath = "fillStag@1.gaspFill@0.fillScan@1";
+    private final String captureClockRelPath = "fillStag@1";
     // test library direct write mode doesn't understand per register write 
     // enables. We get simulation to work by toggling write clock.
     private final boolean clockHack;
-    private final String captureClockName = "si[4]";
+    private final String captureClockName = "sx[4]";
 
+    /*
     private boolean traceFill = true;
     private boolean traceDrain = true;
+    */
+    private boolean traceFill = false;
+    private boolean traceDrain = false;
         
     private final String controlChain, controlPath, 
         dataChain, dataPath, 
@@ -42,7 +48,7 @@ public class ProperStopper {
     private final ChipModel model;
     private final Indenter indenter;
 
-    protected static void fatal(boolean pred, String msg) { if (pred) Infrastructure.fatal(msg); }
+    protected static void fatal(boolean pred, String msg) { MarinaUtils.fatal(pred, msg); }
     private void prln(String msg) { indenter.prln(msg); }
     private void adjustIndent(int n) { indenter.adjustIndent(n); }
         
@@ -50,6 +56,8 @@ public class ProperStopper {
      * Each instance name in the path must begin with the character 'x'.
      * Return a path with the added X's. */
     private String prefixInstNamesInPathWithX(String path) {
+        if (model==null) throw new RuntimeException();
+        if (!(model instanceof NanosimModel)) return path;
         StringBuffer sb = new StringBuffer();
         sb.append('x');
         for (int i=0; i<path.length(); i++) {
@@ -61,9 +69,12 @@ public class ProperStopper {
     }
   
     private void shiftControl(boolean readEnable, boolean writeEnable) {
+        //System.out.println("start shiftcontrol");
         cc.shift(controlChain, readEnable, writeEnable);
+        //System.out.println("  end shiftcontrol");
     }
     private void shiftData(boolean readEnable, boolean writeEnable) {
+        //System.out.println("start shiftdata");
         cc.shift(dataChain, readEnable, writeEnable);
         if (writeEnable) {
             if (clockHack && model instanceof NanosimModel) {
@@ -71,11 +82,19 @@ public class ProperStopper {
                 nanoModel.setNodeState(captureClock, 1);
                 nanoModel.waitNS(1);
                 nanoModel.setNodeState(captureClock, 0);
+            } else if (clockHack && model instanceof VerilogModel) {
+                VerilogModel nanoModel = (VerilogModel) model;
+                nanoModel.setNodeState(captureClock, 1);
+                nanoModel.waitNS(1);
+                nanoModel.setNodeState(captureClock, 0);
             }
         }
+        //System.out.println("  end shiftdata");
     }
     private void shiftReport(boolean readEnable, boolean writeEnable) {
+        //System.out.println("start shiftreport");
         cc.shift(reportChain, readEnable, writeEnable);
+        //System.out.println("  end shiftreport");
     }
 
     private StateWireState boolToState(boolean b) {
@@ -193,24 +212,25 @@ public class ProperStopper {
     }
 
     /** construct a ProperStopper */
-    public ProperStopper(String propInst,
+    public ProperStopper(String name,
+                         String propInst,
                          String controlChain, String dataChain, 
                          String reportChain,
                          ChainControls cc, ChipModel model,
                          boolean clockHack,
                          Indenter indenter) {
-        this.name = propInst;
+        this.name = name;
         this.controlChain = controlChain;
         this.controlPath = controlChain+'.'+propInst;
         this.dataChain = dataChain;
         this.dataPath = dataChain+'.'+propInst;
         this.reportChain = reportChain;
         this.reportPath = reportChain+'.'+propInst;
+        this.model = model;
         this.captureClock = 
             prefixInstNamesInPathWithX(propInst+'.'+captureClockRelPath)
             +'.'+captureClockName;
         this.cc = cc;
-        this.model = model;
         this.clockHack = clockHack;
         this.indenter = indenter;
     }
@@ -229,8 +249,7 @@ public class ProperStopper {
      * Fill stage must be empty. 
      * You must stop stopper before calling fill.
      * exit state: block */
-    public void fill(BitVector dta) {
-        if (traceFill) prln("Begin fill. stopper="+name);
+    private void fill_(BitVector dta) {
         adjustIndent(2);
         
         int n = dta.getNumBits();
@@ -240,8 +259,6 @@ public class ProperStopper {
         StateWireState myState = getFillStateWire();
         fatal(myState!=StateWireState.EMPTY, "fill: fill stage already full");
         
-        if (traceFill) prln("writing data: "+new MarinaPacket(dta));
-        
         idle();                                 // block = 1, go = 0
 
         BitVector wrEn = new BitVector(2, "write enable");
@@ -267,8 +284,16 @@ public class ProperStopper {
         if (traceFill) prln("End fill");
     }
 
+    public void fill(BitVector dat) {
+        if (traceFill) prln("Begin fill. stopper="+name);
+        if (traceFill) prln("writing data: "+new MarinaPacket(dat));
+        fill_(dat);
+    }
+
     public void fill(MarinaPacket mp) {
-        fill(mp.toSingleBitVector());
+        if (traceFill) prln("Begin fill. stopper="+name);
+        if (traceFill) prln("writing data: "+mp);
+        fill_(mp.toSingleBitVector());
     }
 
     /** Insert items from a list, one by one. 
@@ -304,7 +329,7 @@ public class ProperStopper {
      * Assume that an item is available. 
      * entry state: stop
      * exit state: stop */
-    protected BitVector drainNoCheck() {
+    private BitVector drainNoCheck() {
         shiftData(true, false);
 
         // strip the two write enable bits
@@ -330,7 +355,6 @@ public class ProperStopper {
      * drainStopperMany() will stop cleanly.
      * exit state: stop */
     public List<BitVector> drainMany(int maxNbItems) {
-        prln("begin drainMany. stopper="+name);
         adjustIndent(2);
         
         stop();
@@ -346,15 +370,21 @@ public class ProperStopper {
 
             if (myState==StateWireState.EMPTY || cnt>=maxNbItems) break;
                 
-            if (traceDrain) prln("drainMany: reading word number: "+cnt++);
-                
+            cnt++;
+            indenter.pr("  drain"+(maxNbItems==0?"":"Many")+
+                        ": reading word"+(maxNbItems==0?":":" number "+cnt+
+                        "/"+(maxNbItems==Integer.MAX_VALUE
+                             ?"unlimited":("at-most-"+maxNbItems))+": "));
+
             BitVector d = drainNoCheck();
+            if (maxNbItems>1)
+                prln("  got "+new MarinaPacket(d));
 
             ans.add(d);
         }
         
-        adjustIndent(-2);
         prln("end drainMany, got "+ans.size()+" items");
+        adjustIndent(-2);
         
         return ans;
     }