checkpoint
[slipway.git] / src / edu / berkeley / slipway / FtdiBoard.java
index fc705a7..d1c582c 100644 (file)
@@ -1,8 +1,9 @@
 package edu.berkeley.slipway;
 
+import com.ftdi.usb.*;
 import com.atmel.fpslic.*;
 import edu.berkeley.obits.*;
-import org.ibex.util.Log;
+import org.ibex.util.*;
 import java.io.*;
 import java.util.*;
 import gnu.io.*;
@@ -13,7 +14,7 @@ public class FtdiBoard extends Board {
         System.load(new File("build/"+System.mapLibraryName("FtdiUartNative")).getAbsolutePath());
     }
 
-    private final Chip chip;
+    private final FpslicRaw chip;
     private final InputStream in;
     private final OutputStream out;
 
@@ -21,7 +22,7 @@ public class FtdiBoard extends Board {
     public OutputStream getOutputStream() { return out; }
 
     public FtdiBoard() throws Exception {
-        chip = new ChipImpl();
+        chip = new FpslicRaw(new FpslicPinsUsb(new FtdiUart(0x6666, 0x3133, 1500 * 1000)));
         String bstFile = this.getClass().getName();
         bstFile = bstFile.substring(0, bstFile.lastIndexOf('.'));
         bstFile = bstFile.replace('.', '/')+"/slipway_drone.bst";
@@ -33,76 +34,26 @@ public class FtdiBoard extends Board {
     }
 
     public void reset() throws IOException {
-        chip.doReset();
+        chip.reset();
     }
 
     public void boot(Reader r) throws Exception {
-        Chip d = chip;
 
-        //d.buffered(false);
-
-        d.selfTest();
-
-        d.doReset();
-
-        d.config(0,10);
-        d.con();
-        //d.config(Integer.parseInt("10110111", 2));
-        //d.config(0);
+        chip.selfTest();
 
+        int total = 75090/9;
+        OutputStream os = new ProgressOutputStream("bootstrap bitstream:", chip.getConfigStream(), total);
         BufferedReader br = new BufferedReader(r);
-        br.readLine();
+
         int bytes = 0;
-        //System.out.println("cts="+""+"  pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
         while(true) {
             String s = br.readLine();
             if (s==null) break;
-            int in = Integer.parseInt(s, 2);
             bytes++;
-            for(int i=7; i>=0; i--) {
-                d.config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
-                boolean init = true; // d.initErr()
-                if (bytes < 100 || (bytes % 1000)==0) {
-                    d.flush();
-                    init = d.initErr();
-                    System.out.print("wrote " + bytes + " bytes, init="+init+"      \r");
-                    d.rcon();
-                }
-                if (!init)
-                    throw new RuntimeException("initialization failed at byte " + bytes + ", bit " + i);
-            }
-        }
-
-
-        d.flush();
-        if (!d.initErr())
-            throw new RuntimeException("initialization failed at " + bytes);
-        //System.out.println("cts="+""+"  pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
-
-
-        for(int i=0; i<100; i++) {
-            d.flush();
-            if (!d.initErr())
-                throw new RuntimeException("initialization failed at " + bytes);
-            try { Thread.sleep(20); } catch (Exception e) { }
-            d.config(0,1);
+            os.write((byte)Integer.parseInt(s, 2));
+            if ((bytes % 1000)==0) os.flush();
         }
-
-        System.out.println();
-        System.out.println("avr reset => false");
-        d.avrrst(false);
-        try { Thread.sleep(500); } catch (Exception e) { }
-        //System.out.println("cts="+""+"  pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
-
-        //((Chip)d).avr();
-
-        //System.out.println("avr reset => true");
-        ((ChipImpl)chip).purge();
-        ((ChipImpl)chip).uart_and_cbus_mode(1<<1, 1<<1);
-        
-        //d.avrrst(true);
-        //try { Thread.sleep(500); } catch (Exception e) { }
-        //System.out.println("cts="+""+"  pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
+        os.close();
     }
 
     public static String pad(String s, int i) {