checkpoint
authoradam <adam@megacz.com>
Wed, 20 Sep 2006 13:21:40 +0000 (14:21 +0100)
committeradam <adam@megacz.com>
Wed, 20 Sep 2006 13:21:40 +0000 (14:21 +0100)
src/com/atmel/fpslic/Chip.java
src/com/atmel/fpslic/ChipImpl.java
src/edu/berkeley/slipway/FtdiBoard.java

index ae77448..57c9d98 100644 (file)
@@ -21,5 +21,6 @@ public interface Chip {
     public InputStream getInputStream();
     public OutputStream getOutputStream();
     public void selfTest() throws Exception;
+    public OutputStream getConfigStream() throws IOException;
 
 }
index 9123f15..e11b8f4 100644 (file)
@@ -115,6 +115,26 @@ public class ChipImpl extends FtdiUart implements Chip {
         dbus_mode(dmask);
     }
 
+    public OutputStream getConfigStream() throws IOException {
+        doReset();
+        config(0,10);
+        con();
+        return new OutputStream() {
+                public void write(int in) throws IOException {
+                    for(int i=7; i>=0; i--) {
+                        config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
+                    }
+                }
+                public void write(byte[] b, int off, int len) throws IOException {
+                    for(int i=off; i<off+len; i++)
+                        write(b[i]);
+                }
+                public void flush() throws IOException {
+                    ChipImpl.this.flush();
+                }
+            };
+    }
+
     public static String red(Object o) { return "\033[31m"+o+"\033[0m"; }
     public static String green(Object o) { return "\033[32m"+o+"\033[0m"; }
     public void selfTest() throws Exception {
index fc705a7..dafc38f 100644 (file)
@@ -39,46 +39,30 @@ public class FtdiBoard extends Board {
     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);
+        OutputStream os = d.getConfigStream();
 
         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);
+            os.write((byte)in);
+            if ((bytes % 1000)==0) {
+                os.flush();
+                System.out.print("wrote " + bytes + " bytes\r");
+                d.rcon();
             }
         }
 
-
         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();