1 package edu.berkeley.slipway;
3 import com.atmel.fpslic.*;
4 import edu.berkeley.obits.*;
5 import org.ibex.util.Log;
10 public class FtdiBoard extends Board {
13 System.load(new File("build/"+System.mapLibraryName("FtdiUartNative")).getAbsolutePath());
16 private final Chip chip;
17 private final InputStream in;
18 private final OutputStream out;
20 public InputStream getInputStream() { return in; }
21 public OutputStream getOutputStream() { return out; }
23 public FtdiBoard() throws Exception {
24 chip = new ChipImpl();
25 String bstFile = this.getClass().getName();
26 bstFile = bstFile.substring(0, bstFile.lastIndexOf('.'));
27 bstFile = bstFile.replace('.', '/')+"/slipway_drone.bst";
28 boot(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(bstFile)));
29 in = chip.getInputStream();
30 out = chip.getOutputStream();
31 for(int i=0; i<255; i++) out.write(0);
35 public void reset() throws IOException {
39 public void boot(Reader r) throws Exception {
50 //d.config(Integer.parseInt("10110111", 2));
53 BufferedReader br = new BufferedReader(r);
56 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
58 String s = br.readLine();
60 int in = Integer.parseInt(s, 2);
62 for(int i=7; i>=0; i--) {
63 d.config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
64 boolean init = true; // d.initErr()
65 if (bytes < 100 || (bytes % 1000)==0) {
68 System.out.print("wrote " + bytes + " bytes, init="+init+" \r");
72 throw new RuntimeException("initialization failed at byte " + bytes + ", bit " + i);
79 throw new RuntimeException("initialization failed at " + bytes);
80 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
83 for(int i=0; i<100; i++) {
86 throw new RuntimeException("initialization failed at " + bytes);
87 try { Thread.sleep(20); } catch (Exception e) { }
92 System.out.println("avr reset => false");
94 try { Thread.sleep(500); } catch (Exception e) { }
95 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
99 //System.out.println("avr reset => true");
100 ((ChipImpl)chip).purge();
101 ((ChipImpl)chip).uart_and_cbus_mode(1<<1, 1<<1);
104 //try { Thread.sleep(500); } catch (Exception e) { }
105 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
108 public static String pad(String s, int i) {
109 if (s.length() >= i) return s;
110 return "0"+pad(s, i-1);