add FleetProcess.{flush,dispatchWord,dispatchToken}
authoradam <adam@megacz.com>
Mon, 27 Oct 2008 06:30:48 +0000 (07:30 +0100)
committeradam <adam@megacz.com>
Mon, 27 Oct 2008 06:30:48 +0000 (07:30 +0100)
src/edu/berkeley/fleet/api/FleetProcess.java
src/edu/berkeley/fleet/fpga/Client.java
src/edu/berkeley/fleet/interpreter/Interpreter.java

index ef9297c..2b8f9d7 100644 (file)
@@ -19,6 +19,9 @@ public abstract class FleetProcess {
 
     /** dispatch an instruction */
     public abstract void dispatchInstruction(Instruction i);
+    public abstract void dispatchWord(Destination d, BitVector word);
+    public void dispatchToken(Destination d) { throw new RuntimeException("not implemented"); }
+    public void flush() { }
 
     /** the dock used to read back data from the slave */
     public abstract Dock getDebugInputDock();
@@ -37,4 +40,6 @@ public abstract class FleetProcess {
 
     public final boolean isTerminated() { return terminated; }
     public synchronized void finalize() { terminate(); }
+
+    public abstract Fleet getFleet();
 }
index c563917..9a53410 100644 (file)
@@ -4,6 +4,7 @@ import static edu.berkeley.fleet.util.BitManipulations.*;
 import edu.berkeley.fleet.api.*;
 import java.io.*;
 import java.net.*;
+import edu.berkeley.fleet.util.*;
 import java.util.*;
 import java.util.concurrent.*;
 import static edu.berkeley.fleet.api.Instruction.Set.*;
@@ -26,6 +27,7 @@ public class Client extends FleetProcess {
         return val;
     }
                                     
+    public Fleet getFleet() { return fpga; }
     public Dock getDebugInputDock() {
         throw new RuntimeException();
     }
@@ -44,6 +46,15 @@ public class Client extends FleetProcess {
     }
 
     private Fpga fpga;
+    private DataOutputStream dos = null;
+
+    public void flush() {
+        try {
+            dos.flush();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
 
     public Client(Fpga fpga, String bitfile, Instruction[] instructions) throws Exception {
         this.fpga = fpga;
@@ -55,13 +66,13 @@ public class Client extends FleetProcess {
         pw.print(Server.pass_string+" "+bitfile+"\n");
         pw.flush();
 
-        DataOutputStream dos = new DataOutputStream(os);
+        this.dos = new DataOutputStream(os);
         for(Instruction inst : instructions)
-            fpga.writeInstruction(dos, fpga.debugShip.getDock("in"), inst);
-        dos.flush();
+            dispatchInstruction(inst);
+        flush();
 
         final InputStream is = new BufferedInputStream(s.getInputStream());
-        new Thread() {
+        Thread t = new Thread() {
             public void run() {
                 try {
                     while(true) {
@@ -84,10 +95,35 @@ public class Client extends FleetProcess {
                 } catch (Exception e) { throw new RuntimeException(e);
                 } finally { terminate(); }
             }
-        }.start();
+            };
+        t.setDaemon(true);
+        t.start();
+    }
+
+    public void dispatchToken(Destination d) { dispatchWord(d, new BitVector(fpga.getWordWidth()), true); }
+    public void dispatchWord(Destination d, BitVector word) { dispatchWord(d, word, false); }
+    private void dispatchWord(Destination d, BitVector word, boolean token) {
+        try {
+            Dock dispatchFrom = fpga.debugShip.getDock("in");
+            long out = 0;
+            out = PACKET_DATA.setval(out, word);
+            out = PACKET_TOKEN.setval(out, token ? 1 : 0);
+            out = PACKET_SIGNAL.setval(out, 0);
+            out = PACKET_DEST.setval(out, ((FpgaPath)dispatchFrom.getPath(d, null)).toLong());
+            synchronized(this) {
+                for(int i=7; i>=0; i--)
+                    dos.write(BitManipulations.getIntField(i*8+7, i*8, out));
+            }
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+    public void dispatchInstruction(Instruction inst) {
+        Dock dispatchFrom = fpga.debugShip.getDock("in");
+        dispatchWord(inst.dock.getInstructionDestination(),
+                     new BitVector(fpga.getWordWidth()).set(fpga.writeInstruction(inst, dispatchFrom)));
     }
 
-    public void dispatchInstruction(Instruction i) { throw new RuntimeException(); }
     private static Move discard(Dock dock)           { return new Move(dock, false, IgnoreOLC, false, null, false, true,  false, false, false, false); }
     private static Move deliver(Dock dock)           { return new Move(dock, false, IgnoreOLC, false, null, false, false, false, false, true,  false); }
     private static Move wait(Dock dock)              { return new Move(dock, false, IgnoreOLC, false, null, true,  false, false, false, false, false); }
index 7a9d83a..9f0f6af 100644 (file)
@@ -137,6 +137,9 @@ public class Interpreter extends FleetTwoFleet implements Parser.FleetWithDynami
 
     private class InterpreterProcess extends FleetProcess implements Runnable {
         private Instruction[] instructions;
+        public void dispatchWord(Destination d, BitVector word) {
+            throw new RuntimeException("not implemented");
+        }
         public InterpreterProcess(Instruction[] instructions) {
             this.instructions = instructions;
             for(Instruction i : instructions)