checkpoint
authoradam <adam@megacz.com>
Mon, 11 Sep 2006 13:43:38 +0000 (14:43 +0100)
committeradam <adam@megacz.com>
Mon, 11 Sep 2006 13:43:38 +0000 (14:43 +0100)
src/edu/berkeley/obits/device/atmel/FtdiBoard.java
src/edu/berkeley/obits/device/atmel/FtdiChip.java

index 43cbf10..ffa0514 100644 (file)
@@ -21,10 +21,7 @@ public class FtdiBoard extends Board {
 
     public FtdiBoard() throws Exception {
         chip = new ChipImpl();
-        chip.porte(4, true);
-
         boot(new InputStreamReader(new FileInputStream("bitstreams/usbdrone.bst")));
-
         in = chip.getInputStream();
         out = chip.getOutputStream();
         for(int i=0; i<255; i++) out.write(0);
@@ -38,33 +35,41 @@ public class FtdiBoard extends Board {
     public void boot(Reader r) throws Exception {
         boolean pin;
         Chip d = chip;
+        d.buffered(true);
         d.doReset();
         d.config(0,10);
         d.con();
+        d.flush();
         d.config(Integer.parseInt("10110111", 2), 8);
         d.config(0,1);
+        d.flush();
         pin = d.initErr();
         System.out.println("good preamble   => " + pin + " " + (pin ? green("good") : red("BAD")));
 
         d.doReset();
         d.config(0,9);
         d.con();
+        d.flush();
         d.config(Integer.parseInt("10110111", 2), 8);
         d.config(0, 2);
+        d.flush();
         pin = d.initErr();
         System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good")));
 
         d.doReset();
         d.config(0,10);
         d.con();
+        d.flush();
         d.config(Integer.parseInt("11110111", 2), 8);
         d.config(0, 1);
+        d.flush();
         pin = d.initErr();
         System.out.println("bad preamble #1 => " + pin + " " + (pin ? red("BAD") : green("good")));
 
 
         d.doReset();
 
+
         d.config(0,10);
         d.con();
         //d.config(Integer.parseInt("10110111", 2));
index fd96c64..4b8820a 100644 (file)
@@ -24,7 +24,6 @@ public class FtdiChip {
         return b[0];
     }
 
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
     public void flush() {
         try {
             getOutputStream().flush();
@@ -51,9 +50,12 @@ public class FtdiChip {
 
     protected int dbits = 0;
 
-    public boolean buffered = false;
+    public boolean buffered = true;
     public void buffered() { buffered = true; }
-    public void buffered(boolean buf) { buffered = buf; }
+    public void buffered(boolean buf) {
+        if (!buf) flush();
+        buffered = buf;
+    }
 
     protected synchronized void dbang(int bit, boolean val) {
         dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit)));