putMemoryShipInDispatchMode() now puts both out and inCBD in infinite-recieve mode
[fleet.git] / src / edu / berkeley / fleet / loops / MemoryUtils.java
index 05d14a9..f8c5163 100644 (file)
@@ -18,6 +18,9 @@ public class MemoryUtils {
     public static void readMem(FleetProcess fp, Ship memory, long offset, BitVector[] vals) throws RuntimeException {
         doMem(true, fp, memory, offset, vals);
     }
+    public static void writeMem(FleetProcess fp, Ship memory, long offset, long[] vals) throws RuntimeException {
+        doMem(false, fp, memory, offset, long2bv(fp.getFleet(), vals));
+    }
     public static void writeMem(FleetProcess fp, Ship memory, long offset, BitVector[] vals) throws RuntimeException {
         doMem(false, fp, memory, offset, vals);
     }
@@ -104,6 +107,35 @@ public class MemoryUtils {
         System.out.println();
     }
 
+    private static BitVector[] long2bv(Fleet fleet, long[] initialValues) {
+        BitVector[] bv = new BitVector[initialValues.length];
+        for(int i=0; i<initialValues.length; i++)
+            bv[i] = new BitVector(fleet.getWordWidth()).set(initialValues[i]);
+        return bv;
+    }
+
+    public static void putMemoryShipInDispatchMode(FleetProcess fp, Ship memoryShip) {
+        Context ctx = new Context(fp.getFleet());
+        LoopFactory lf;
+
+        lf = new LoopFactory(ctx, memoryShip.getDock("out"), 0);
+        lf.abortLoopIfTorpedoPresent();
+        lf.collectPacket();
+        lf.sendWord(null);
+
+        lf = new LoopFactory(ctx, memoryShip.getDock("inCBD"), 0);
+        lf.abortLoopIfTorpedoPresent();
+        lf.recvWord();
+        lf.deliver();
+
+        ctx.dispatch(fp);
+    }
+
+    public static void removeMemoryShipFromDispatchMode(FleetProcess fp, Ship memoryShip) {
+        fp.sendToken(memoryShip.getDock("out").getInstructionDestination());
+        fp.sendToken(memoryShip.getDock("inCBD").getInstructionDestination());
+    }
+
     public static void main(String[] s) throws Exception {
         Random random = new Random(System.currentTimeMillis());
         Fleet fleet = new Fpga();