add FpgaDestination.getPathLength() for measuring hop counts
[fleet.git] / src / edu / berkeley / fleet / fpga / FunnelModule.java
index bda75e8..7593133 100644 (file)
@@ -15,12 +15,14 @@ import static edu.berkeley.fleet.fpga.verilog.Verilog.*;
 
 public class FunnelModule extends Module {
 
-    public FunnelModule() {
+    public FunnelModule(Fpga fpga) {
         super("funnel");
-        Module.SinkPort    outp = createOutputPort("out", WIDTH_PACKET, "");
-        Module.SourcePort  in1p = createInputPort("in1", WIDTH_PACKET);
-        Module.SourcePort  in2p = createInputPort("in2", WIDTH_PACKET);
-        new Event(new Object[] { in1p, outp },
+        Module.SinkPort    outp = createOutputPort("out", fpga.WIDTH_PACKET);
+        Module.SourcePort  in1p = createInputPort("in1", fpga.WIDTH_PACKET);
+        Module.SourcePort  in2p = createInputPort("in2", fpga.WIDTH_PACKET);
+
+        // FIXME: biased towards in2p side
+        new Event(new Object[] { in1p, outp, "!"+in2p.isFull() },
                   new Action[] { in1p, outp,
                                  new AssignAction(outp, in1p) });
         new Event(new Object[] { in2p, outp },
@@ -32,15 +34,15 @@ public class FunnelModule extends Module {
         private FabricElement in1 = null;
         private FabricElement in2 = null;
         public FabricElement out = null;
-        public Module.Port getOutputPort() { return getOutputPort("out"); }
+        public Module.SourcePort getOutputPort() { return getOutputPort("out"); }
         public Module.Port getInputPort()  { throw new RuntimeException("funnel has multiple inputs"); }
-        public FunnelInstance(Module thisModule, Module.Port p1, Module.Port p2) {
-            super(thisModule, new FunnelModule());
-            p1.connect(this.getInputPort("in1"));
-            p2.connect(this.getInputPort("in2"));
+        public FunnelInstance(Fpga fpga, Module thisModule, Module.SourcePort p1, Module.SourcePort p2) {
+            super(thisModule, new FunnelModule(fpga));
+            if (p1 != null) p1.connect(this.getInputPort("in1"));
+            if (p2 != null) p2.connect(this.getInputPort("in2"));
         }
-        public FunnelInstance(Module thisModule, FabricElement in1, FabricElement in2) {
-            super(thisModule, new FunnelModule());
+        public FunnelInstance(Fpga fpga, Module thisModule, FabricElement in1, FabricElement in2) {
+            super(thisModule, new FunnelModule(fpga));
             this.in1 = in1;
             this.in2 = in2;
             in1.addOutput(this, this.getInputPort("in1"));
@@ -53,7 +55,8 @@ public class FunnelModule extends Module {
         public void addInput(FabricElement in, Module.Port source) {
             throw new RuntimeException("cannot add inputs to a funnel once constructed");
         }
-        public FpgaPath getPath(FabricElement dest, BitVector signal) {
+        public int      getPathLength(FpgaDestination dest) { return out.getPathLength(dest)+1; }
+        public FpgaPath getPath(FpgaDestination dest, BitVector signal) {
             return out.getPath(dest, signal);
         }
     }