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.*;
return val;
}
+ public Fleet getFleet() { return fpga; }
public Dock getDebugInputDock() {
throw new RuntimeException();
}
}
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;
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) {
} 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); }