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 {
44 OutputStream os = d.getConfigStream();
46 BufferedReader br = new BufferedReader(r);
51 String s = br.readLine();
53 int in = Integer.parseInt(s, 2);
56 if ((bytes % 1000)==0) {
58 System.out.print("wrote " + bytes + " bytes\r");
65 throw new RuntimeException("initialization failed at " + bytes);
67 for(int i=0; i<100; i++) {
70 throw new RuntimeException("initialization failed at " + bytes);
71 try { Thread.sleep(20); } catch (Exception e) { }
76 System.out.println("avr reset => false");
78 try { Thread.sleep(500); } catch (Exception e) { }
79 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
83 //System.out.println("avr reset => true");
84 ((ChipImpl)chip).purge();
85 ((ChipImpl)chip).uart_and_cbus_mode(1<<1, 1<<1);
88 //try { Thread.sleep(500); } catch (Exception e) { }
89 //System.out.println("cts="+""+" pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
92 public static String pad(String s, int i) {
93 if (s.length() >= i) return s;
94 return "0"+pad(s, i-1);