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

index e11b8f4..dedc4b0 100644 (file)
@@ -120,7 +120,9 @@ public class ChipImpl extends FtdiUart implements Chip {
         config(0,10);
         con();
         return new OutputStream() {
+                int bytes = 0;
                 public void write(int in) throws IOException {
+                    bytes++;
                     for(int i=7; i>=0; i--) {
                         config((((in & 0xff) & (1<<i))!=0)?1:0, 1);
                     }
@@ -131,6 +133,23 @@ public class ChipImpl extends FtdiUart implements Chip {
                 }
                 public void flush() throws IOException {
                     ChipImpl.this.flush();
+                    rcon();
+                }
+                public void close() throws IOException {
+                    flush();
+                    if (!initErr())
+                        throw new RuntimeException("initialization failed at " + bytes);
+                    for(int i=0; i<100; i++) {
+                        flush();
+                        if (!initErr())
+                            throw new RuntimeException("initialization failed at " + bytes);
+                        try { Thread.sleep(20); } catch (Exception e) { }
+                        config(0,1);
+                    }
+                    avrrst(false);
+                    try { Thread.sleep(100); } catch (Exception e) { }
+                    purge();
+                    uart_and_cbus_mode(1<<1, 1<<1);
                 }
             };
     }
index dafc38f..283a626 100644 (file)
@@ -56,37 +56,9 @@ public class FtdiBoard extends Board {
             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);
-
-        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);
-        }
-
-        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) {