THIS WORKS RELIABLY
authoradam <adam@megacz.com>
Wed, 20 Sep 2006 08:20:07 +0000 (09:20 +0100)
committeradam <adam@megacz.com>
Wed, 20 Sep 2006 08:20:07 +0000 (09:20 +0100)
src/edu/berkeley/obits/device/atmel/ChipImpl.java
src/edu/berkeley/obits/device/atmel/FtdiBoard.java

index 8917817..c2c7752 100644 (file)
@@ -5,7 +5,7 @@ import java.io.*;
 public class ChipImpl extends FtdiChip implements Chip {
 
     private int dmask =
-        //(1<<0) |
+        (1<<0) |
         (1<<1) |
         (1<<2) |
         //(1<<3) |
@@ -30,6 +30,7 @@ public class ChipImpl extends FtdiChip implements Chip {
             (1<<5) |
             (1<<6) |
             (1<<7);
+        avrrst(false);
 
         flush();
         //purge();
@@ -46,10 +47,15 @@ public class ChipImpl extends FtdiChip implements Chip {
         reset(false);
         flush();
         try { Thread.sleep(500); } catch (Exception e) { }
+        if (initErr()) throw new RuntimeException("INIT was still high after pulling RESET low");
+        //System.out.println("0 con() = " + con());
 
         reset(true);
         flush();
         try { Thread.sleep(500); } catch (Exception e) { }
+        if (!initErr()) throw new RuntimeException("INIT was still low after releasing RESET");
+        //System.out.println("1 con() = " + con());
+        con(false);
     }
 
     int porte = 0;
@@ -77,14 +83,13 @@ public class ChipImpl extends FtdiChip implements Chip {
     //         let it float upward from either mode.
     public void reset(boolean on) {
         bits = on ? (1<<1) : 0;
-        mask = ((1<<0) | (1<<1));
+        mask = (1<<1);
         uart();
         flush();
         if (on) {
-            mask = (1<<0);
-            uart();
-            flush();
-            try { Thread.sleep(100); } catch (Exception e) { }
+            //mask = 0;
+            //uart();
+            //flush();
             dbangmode(dmask);
             flush();
         }
@@ -95,16 +100,17 @@ public class ChipImpl extends FtdiChip implements Chip {
     public void data(boolean on)   { dbang(5, on); }
 
     public boolean initErr()       { flush(); return (readPins() & (1<<4))!=0; }
+
     public boolean con() {
         flush();
-        dmask &= ~(1<<0);
+        //dmask &= ~(1<<0);
         dbangmode(dmask);
         return (readPins() & (1<<0)) != 0;
     }
     public void con(boolean on) {
         flush();
         dmask |= (1<<0);
-        dbangmode(dmask);
         dbang(0, on);
+        dbangmode(dmask);
     }
 }
index 63771d1..08b5e98 100644 (file)
@@ -39,9 +39,10 @@ public class FtdiBoard extends Board {
         //d.buffered(false);
         for(int i=0; i<1000; i++) {
         d.doReset();
-        d.config(0,10);
-        d.flush();
+        d.config(0,3);
         d.con();
+        d.config(0,7);
+        d.flush();
         //d.flush();
         d.config(Integer.parseInt("10110111", 2), 8);
         d.config(0,1);
@@ -52,9 +53,10 @@ public class FtdiBoard extends Board {
 
         d.doReset();
         try { Thread.sleep(100); } catch (Exception e) { }
-        d.config(0,9);
-        d.flush();
+        d.config(0,3);
         d.con();
+        d.config(0,6);
+        d.flush();
         //d.flush();
         d.config(Integer.parseInt("10110111", 2), 8);
         d.config(0, 2);
@@ -65,9 +67,10 @@ public class FtdiBoard extends Board {
 
         d.doReset();
         try { Thread.sleep(100); } catch (Exception e) { }
-        d.config(0,10);
-        d.flush();
+        d.config(0,3);
         d.con();
+        d.config(0,7);
+        d.flush();
         //d.flush();
         d.config(Integer.parseInt("11110111", 2), 8);
         d.config(0, 1);