1 package edu.berkeley.fleet.fpga;
3 import static edu.berkeley.fleet.util.BitManipulations.*;
4 import edu.berkeley.fleet.api.*;
7 import edu.berkeley.fleet.util.*;
9 import java.util.concurrent.*;
10 import static edu.berkeley.fleet.api.Instruction.Set.*;
11 import static edu.berkeley.fleet.api.Predicate.*;
12 import static edu.berkeley.fleet.api.Instruction.*;
15 public class Client extends FleetProcess {
18 private BlockingQueue<BitVector> queue = new LinkedBlockingQueue<BitVector>();
20 public void invokeInstruction(Instruction i) {
21 throw new RuntimeException("not implemented");
24 public static long signExtend(long val) {
25 if ((val & (1L << 36)) != 0)
26 val = val | (0xffffffffffffffffL << 36);
30 public Fleet getFleet() { return fpga; }
31 public Dock getDebugInputDock() {
32 throw new RuntimeException();
34 public BitVector readWord() {
36 throw new RuntimeException("this fleet has been terminated");
39 } catch (InterruptedException e) { throw new RuntimeException(e); }
42 protected void _terminate() {
45 } catch (Exception e) { e.printStackTrace(); }
49 private DataOutputStream dos = null;
54 } catch (Exception e) {
55 throw new RuntimeException(e);
59 public Client(Fpga fpga, String bitfile, Instruction[] instructions) throws Exception {
62 s = new Socket(InetAddress.getByName("goliath.megacz.com"), 3133);
63 //s = new Socket(InetAddress.getByName("localhost"), 3133);
64 OutputStream os = new BufferedOutputStream(s.getOutputStream());
65 PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
66 pw.print(Server.pass_string+" "+bitfile+"\n");
69 this.dos = new DataOutputStream(os);
70 for(Instruction inst : instructions)
71 dispatchInstruction(inst);
74 final InputStream is = new BufferedInputStream(s.getInputStream());
75 Thread t = new Thread() {
81 for(int i=0; i<6; i++) {
84 long val2 = (val & 0xffL);
85 val2 = val2 << (i * 8);
89 BitVector bs = new BitVector(37);
90 for(int i=0; i<37; i++)
91 bs.set(i, ((result >> i) & 1L)!=0);
94 } catch (SocketException e) {
95 } catch (Exception e) { throw new RuntimeException(e);
96 } finally { terminate(); }
103 public void dispatchToken(Destination d) { dispatchWord(d, new BitVector(fpga.getWordWidth()), true); }
104 public void dispatchWord(Destination d, BitVector word) { dispatchWord(d, word, false); }
105 private void dispatchWord(Destination d, BitVector word, boolean token) {
107 Dock dispatchFrom = fpga.debugShip.getDock("in");
109 out = PACKET_DATA.setval(out, word);
110 out = PACKET_TOKEN.setval(out, token ? 1 : 0);
111 out = PACKET_SIGNAL.setval(out, 0);
112 out = PACKET_DEST.setval(out, ((FpgaPath)dispatchFrom.getPath(d, null)).toLong());
114 for(int i=7; i>=0; i--)
115 dos.write(BitManipulations.getIntField(i*8+7, i*8, out));
117 } catch (Exception e) {
118 throw new RuntimeException(e);
121 public void dispatchInstruction(Instruction inst) {
122 Dock dispatchFrom = fpga.debugShip.getDock("in");
123 dispatchWord(inst.dock.getInstructionDestination(),
124 new BitVector(fpga.getWordWidth()).set(fpga.writeInstruction(inst, dispatchFrom)));
127 private static Move discard(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, true, false, false, false, false); }
128 private static Move deliver(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, false, false, false, false, true, false); }
129 private static Move wait(Dock dock) { return new Move(dock, false, IgnoreOLC, false, null, true, false, false, false, false, false); }
130 private static Move sendto(Dock dock, Path path) { return new Move(dock, false, IgnoreOLC, false, path, false, false, false, false, true, false); }