1 package edu.berkeley.fleet.fpga;
2 import edu.berkeley.fleet.fpga.*;
3 import edu.berkeley.fleet.api.*;
9 import java.util.concurrent.Semaphore;
11 public class Bee2 extends Fpga {
13 public Bee2() throws IOException {
14 for(int i=0; i<2; i++) createShip("Alu");
15 for(int i=0; i<1; i++) createShip("Memory");
16 for(int i=0; i<2; i++) createShip("Fifo");
18 createShip("Counter");
19 //createShip("CarrySaveAdder");
20 createShip("Rotator");
23 for(int i=0; i<2; i++) createShip("Memory");
24 for(int i=0; i<6; i++) createShip("Alu");
25 for(int i=0; i<1; i++) createShip("Fifo");
26 for(int i=0; i<12; i++) createShip("Counter");
28 //createShip("CarrySaveAdder");
29 //createShip("Rotator");
38 // Server //////////////////////////////////////////////////////////////////////////////
40 private static class Gobbler extends Thread {
41 private final BufferedReader br;
42 public Gobbler(InputStream is) {
43 this.br = new BufferedReader(new InputStreamReader(is));
47 for(String s = br.readLine(); s!=null; s=br.readLine())
48 System.err.println(s);
49 } catch (Exception e) { throw new RuntimeException(e); }
53 private static RandomAccessFile raf;
54 private static OutputStream fos;
55 private static InputStream fis;
57 public static String pass_string = "password=security_is_for_wimps ";
59 public static void main(String[] args) throws Exception {
60 int idx = Integer.parseInt(args[0]);
63 System.err.println("== unprogramming fpga " + idx);
64 proc = Runtime.getRuntime().exec("user_unprogram "+idx);
65 new Gobbler(proc.getInputStream()).start();
67 System.err.println("== programming fpga " + idx);
68 proc = Runtime.getRuntime().exec("user_program "+idx+" main.bit");
69 new Gobbler(proc.getInputStream()).start();
70 int ret = proc.waitFor();
71 if (ret!=0) System.exit(ret);
73 raf = new RandomAccessFile(new File("/dev/selectmap"+idx), "rw");
74 fos = new FileOutputStream(raf.getFD());
75 fis = new BufferedInputStream(new FileInputStream(raf.getFD()));
76 ServerSocket ss = new ServerSocket(3133);
79 System.out.println("listening...");
80 Socket socket = ss.accept();
82 socket.setKeepAlive(true);
83 System.out.println("accept!");
85 //final InputStream is = new BufferedInputStream(socket.getInputStream());
86 final InputStream is = socket.getInputStream();
87 final OutputStream os = socket.getOutputStream(); //new BufferedOutputStream(socket.getOutputStream());
90 byte[] buf = new byte[1024];
91 StringBuffer sb = new StringBuffer();
95 if (((char)i)=='\n') break;
98 System.err.println("login string: " + sb.toString());
99 if (!sb.toString().startsWith(pass_string)) return;
101 socket.setSoTimeout(10);
104 while (fis.available() > 0) {
106 int val = fis.read();
108 System.err.println("fpga->host: 0x"+Integer.toString(val & 0xff, 16));
109 if ((val & (3<<6)) == 0)
110 fos.write( (1<<6) | 1);
118 System.err.println("host->fpga: 0x"+Integer.toString(r & 0xff, 16));
120 } catch (SocketTimeoutException _) { }
122 if (socket.isOutputShutdown() || socket.isInputShutdown() || socket.isClosed() || !socket.isConnected()) {
126 System.err.println("flushing os...");
128 System.err.println("flushing fos...");
130 System.err.println("sleeping...");
134 } catch (IOException e) {