package edu.berkeley.fleet.fpga;
import static edu.berkeley.fleet.util.BitManipulations.*;
-import java.util.concurrent.Semaphore;
import edu.berkeley.fleet.api.*;
import java.io.*;
import java.net.*;
private Socket s;
private BlockingQueue<BitVector> queue = new LinkedBlockingQueue<BitVector>();
- public static long signExtend(long val) {
- if ((val & (1L << 36)) != 0)
- val = val | (0xffffffffffffffffL << 36);
- return val;
- }
-
public Fleet getFleet() { return fpga; }
public Dock getDebugInputDock() {
return fpga.getShip("Debug",0).getDock("in");
protected void _terminate() {
try {
- closed = true;
s.close();
} catch (Exception e) { e.printStackTrace(); }
}
private Fpga fpga;
- private DataOutputStream dos = null;
+ private OutputStream os = null;
public void flush() {
try {
- synchronized(this) {
- dos.flush();
- }
+ os.flush();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
- /** the 16550 has a 16-byte FIFO buffer */
- private final Semaphore sem = new Semaphore(15);
- private boolean closed = false;
-
public Client(Fpga fpga, String bitfile, Instruction[] instructions) throws Exception {
this.fpga = fpga;
s = new Socket(InetAddress.getByName("goliath.megacz.com"), 3133);
//s = new Socket(InetAddress.getByName("localhost"), 3133);
- OutputStream os = new BufferedOutputStream(s.getOutputStream());
+ this.os = new BufferedOutputStream(s.getOutputStream());
+ final InputStream is = new BufferedInputStream(s.getInputStream());
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
pw.print(Server.pass_string+" "+bitfile+"\n");
pw.flush();
- this.dos = new DataOutputStream(os);
-
- dos.write( (3<<6) | 9);
- dos.flush();
- Thread.sleep(1000);
-
- final InputStream is0 = s.getInputStream();
- while(is0.available() > 0) {
- int i = is0.read();
- //System.out.println("reset code: " + (i & ~(-1 << 6)));
- }
-
- final InputStream is = new BufferedInputStream(is0);
-
- dos.write( (1<<6) | 15);
-
- Thread t;
- /*
- t = new Thread() {
+ // goofy reset sequence
+ new Thread() {
public void run() {
try {
- while(true) {
- int count = sem.availablePermits();
- if (count >= (1<<6)) count = (1<<6)-1;
- if (count < 1) count = 1;
- sem.acquire(count);
- if (closed) return;
- synchronized(this) {
- dos.write( (1<<6) | count );
- if (sem.availablePermits()==0) dos.flush();
- }
- }
+ for(int i=0; i<255; i++) os.write( (3<<6) | 0);
+ for(int i=0; i<60; i++) os.write( (3<<6) | i);
+ os.flush();
} catch (Exception e) { throw new RuntimeException(e); }
}
- };
- t.setDaemon(true);
- t.start();
- */
+ }.start();
+ int k = 1;
+ while(k<60) {
+ int i = is.read();
+ if ( (i & (3<<6)) != (3<<6) ) { k=1; continue; }
+ i = i & ~((-1)<<6);
+ if (i==k) k++; else k = 1;
+ }
+
+ // initial flow-control credits
+ os.write( (1<<6) | 15);
- t = new Thread() {
+ Thread t = new Thread() {
public void run() {
try {
- while(true) {
+ OUTER: while(true) {
long result = 0;
- int val = 0;
for(int i=0; i<8; i++) {
- val = is.read();
- if (val==-1) break;
- sem.release();
- long val2 = (val & 0xffL);
- val2 = val2 << (i * 6);
- result |= val2;
+ int val = is.read();
+ if (val==-1) break OUTER;
+ result |= ((val & 0xffL) << (i * 6L));
}
- if (val==-1) break;
BitVector bs = new BitVector(37);
for(int i=0; i<37; i++)
bs.set(i, ((result >> i) & 1L)!=0);
for(Instruction inst : instructions) sendInstruction(inst);
flush();
-
}
public void sendToken(Destination d) { sendWord(d, new BitVector(fpga.getWordWidth()), true); }
out = fpga.PACKET_DEST.setval(out, ((FpgaPath)dispatchFrom.getPath(d, null)).toLong());
synchronized(this) {
for(int i=9; i>=0; i--)
- dos.write(BitManipulations.getIntField(i*6+5, i*6, out));
- dos.flush();
+ os.write(BitManipulations.getIntField(i*6+5, i*6, out));
+ os.flush();
}
} catch (Exception e) {
throw new RuntimeException(e);