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

index 3bc97e8..ae77448 100644 (file)
@@ -17,6 +17,9 @@ public interface Chip {
     public boolean rcon() throws IOException;
 
     //remove
-    public void flush() throws IOException;
-    public int readPins() throws IOException;
+    public void    flush() throws IOException;
+    public InputStream getInputStream();
+    public OutputStream getOutputStream();
+    public void selfTest() throws Exception;
+
 }
index 84a41c5..9123f15 100644 (file)
@@ -19,11 +19,7 @@ public class ChipImpl extends FtdiUart implements Chip {
         doReset();
     }
 
-    public void flush() throws IOException {
-        try {
-            getOutputStream().flush();
-        } catch (Exception e) { throw new RuntimeException(e); }
-    }
+    public void flush() throws IOException { getOutputStream().flush(); }
 
     protected int dbits = 0;
     protected synchronized void dbang(int bit, boolean val) throws IOException {
@@ -62,13 +58,12 @@ public class ChipImpl extends FtdiUart implements Chip {
         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);
     }
 
@@ -119,4 +114,51 @@ public class ChipImpl extends FtdiUart implements Chip {
         dbang(0, on);
         dbus_mode(dmask);
     }
+
+    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 {
+        ChipImpl d = this;
+        boolean pin;
+        d.doReset();
+        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);
+        d.flush();
+        try { Thread.sleep(100); } catch (Exception e) { }
+        pin = d.initErr();
+        System.out.println("good preamble   => " + pin + " " + (pin ? green("good") : red("BAD")));
+
+        d.doReset();
+        try { Thread.sleep(100); } catch (Exception e) { }
+        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);
+        d.flush();
+        try { Thread.sleep(100); } catch (Exception e) { }
+        pin = d.initErr();
+        System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good")));
+
+        d.doReset();
+        try { Thread.sleep(100); } catch (Exception e) { }
+        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);
+        d.flush();
+        try { Thread.sleep(100); } catch (Exception e) { }
+        pin = d.initErr();
+        System.out.println("bad preamble #1 => " + pin + " " + (pin ? red("BAD") : green("good")));
+    }
 }
index a2a2123..fc705a7 100644 (file)
@@ -13,7 +13,7 @@ public class FtdiBoard extends Board {
         System.load(new File("build/"+System.mapLibraryName("FtdiUartNative")).getAbsolutePath());
     }
 
-    private final ChipImpl chip;
+    private final Chip chip;
     private final InputStream in;
     private final OutputStream out;
 
@@ -37,51 +37,11 @@ public class FtdiBoard extends Board {
     }
 
     public void boot(Reader r) throws Exception {
-        boolean pin;
         Chip d = chip;
 
         //d.buffered(false);
 
-        d.doReset();
-        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);
-        d.flush();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        pin = d.initErr();
-        System.out.println("good preamble   => " + pin + " " + (pin ? green("good") : red("BAD")));
-
-        d.doReset();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        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);
-        d.flush();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        pin = d.initErr();
-        System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good")));
-
-        d.doReset();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        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);
-        d.flush();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        pin = d.initErr();
-        System.out.println("bad preamble #1 => " + pin + " " + (pin ? red("BAD") : green("good")));
+        d.selfTest();
 
         d.doReset();
 
@@ -134,11 +94,11 @@ public class FtdiBoard extends Board {
         try { Thread.sleep(500); } catch (Exception e) { }
         //System.out.println("cts="+""+"  pins=" + pad(Integer.toString(d.readPins()&0xff,2),8));
 
-        //((ChipImpl)d).avr();
+        //((Chip)d).avr();
 
         //System.out.println("avr reset => true");
-        chip.purge();
-        chip.uart_and_cbus_mode(1<<1, 1<<1);
+        ((ChipImpl)chip).purge();
+        ((ChipImpl)chip).uart_and_cbus_mode(1<<1, 1<<1);
         
         //d.avrrst(true);
         //try { Thread.sleep(500); } catch (Exception e) { }
@@ -149,6 +109,4 @@ public class FtdiBoard extends Board {
         if (s.length() >= i) return s;
         return "0"+pad(s, i-1);
     }
-    public static String red(Object o) { return "\033[31m"+o+"\033[0m"; }
-    public static String green(Object o) { return "\033[32m"+o+"\033[0m"; }
 }
index 967a57b..3c13dc8 100644 (file)
@@ -584,7 +584,6 @@ int ftdi_write_data(struct ftdi_context *ftdi, unsigned char *buf, int size)
             write_size = size-offset;
 
         ret = usb_bulk_write(ftdi->usb_dev, ftdi->in_ep, buf+offset, write_size, ftdi->usb_write_timeout);
-        printf("write => %d\n", ret);
         if (ret < 0)
             ftdi_error_return(ret, "usb bulk write failed");