From cddd782397e118024c4b428263f969c57c0c2c29 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 22 Sep 2006 03:48:52 +0100 Subject: [PATCH] checkpoint --- src/com/atmel/fpslic/FpslicRawUsb.java | 115 +++++++++++--------- src/edu/berkeley/obits/AtmelSerial.java | 2 +- .../berkeley/obits/device/atmel/AtmelDevice.java | 2 +- src/edu/berkeley/obits/device/atmel/AvrDrone.java | 6 +- src/edu/berkeley/slipway/FtdiBoard.java | 10 +- src/org/ibex/util/ProgressInputStream.java | 54 +++++++++ src/org/ibex/util/ProgressOutputStream.java | 53 +++++++++ 7 files changed, 182 insertions(+), 60 deletions(-) create mode 100644 src/org/ibex/util/ProgressInputStream.java create mode 100644 src/org/ibex/util/ProgressOutputStream.java diff --git a/src/com/atmel/fpslic/FpslicRawUsb.java b/src/com/atmel/fpslic/FpslicRawUsb.java index 9bc3393..63842ae 100644 --- a/src/com/atmel/fpslic/FpslicRawUsb.java +++ b/src/com/atmel/fpslic/FpslicRawUsb.java @@ -37,24 +37,19 @@ public class FpslicRawUsb implements FpslicRaw { (1<<7); ftdiuart.dbus_mode(dmask); - avrrst(false); - clk(false); - data(false); - + clearDBusLines(); flush(); - dmask |= (1<<0); - dbang(0, false); ftdiuart.dbus_mode(dmask); - reset(false); + resetPin(false); try { Thread.sleep(500); } catch (Exception e) { } - if (initErr()) throw new RuntimeException("INIT was still high after pulling RESET low"); + if (initPin()) throw new RuntimeException("INIT was still high after pulling RESET low"); - reset(true); + resetPin(true); try { Thread.sleep(500); } catch (Exception e) { } - if (!initErr()) throw new RuntimeException("INIT was still low after releasing RESET"); + if (!initPin()) throw new RuntimeException("INIT was still low after releasing RESET"); - config(0,2); + sendConfigBits(0,2); flush(); } @@ -66,7 +61,7 @@ public class FpslicRawUsb implements FpslicRaw { public void write(int in) throws IOException { for(int i=7; i>=0; i--) { bits++; - config((((in & 0xff) & (1< " + pin + " " + (pin ? green("good") : red("BAD"))); + pin = initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + // preamble shifted one bit later than it should be getConfigStream(); - config(Integer.parseInt("0000000", 2), 7); - config(Integer.parseInt("10110111", 2), 8); - config(0, 2); + sendConfigBits(Integer.parseInt("000000000", 2), 9); + sendConfigBits(Integer.parseInt("10110111", 2), 8); + //sendConfigBits(0, 1); flush(); try { Thread.sleep(100); } catch (Exception e) { } - pin = initErr(); - System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good"))); + pin = initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + // plain 'ol bogus preamble getConfigStream(); - config(Integer.parseInt("00000000", 2), 8); - config(Integer.parseInt("11110111", 2), 8); - config(0, 1); + sendConfigBits(Integer.parseInt("00000000", 2), 8); + sendConfigBits(Integer.parseInt("11110111", 2), 8); + sendConfigBits(0, 1); flush(); try { Thread.sleep(100); } catch (Exception e) { } - pin = initErr(); - System.out.println("bad preamble #1 => " + pin + " " + (pin ? red("BAD") : green("good"))); + pin = initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + + System.out.println(); } // Private ////////////////////////////////////////////////////////////////////////////// @@ -141,18 +153,23 @@ public class FpslicRawUsb implements FpslicRaw { private void flush() throws IOException { ftdiuart.getOutputStream().flush(); } private int dbits = 0; - private void dbang(int bit, boolean val) throws IOException { - dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); + private void setDBusLine() throws IOException { ftdiuart.getOutputStream().write((byte)dbits); } + private void clearDBusLines() throws IOException { + dbits = 0; + setDBusLine(); + } + private void setDBusLine(int bit, boolean val) throws IOException { + dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); + setDBusLine(); + } - private void config(boolean bit) throws IOException { config(bit?1:0, 1); } - private void config(int dat) throws IOException { config(dat, 8); } - private void config(int dat, int numbits) throws IOException { + private void sendConfigBits(int dat, int numbits) throws IOException { for(int i=(numbits-1); i>=0; i--) { boolean bit = (dat & (1<> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0)); count++; - if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets"); } flush(); + in.close(); } public void writeMode4(Writer w) throws IOException { diff --git a/src/edu/berkeley/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/obits/device/atmel/AvrDrone.java index 6776b8b..5e5489b 100644 --- a/src/edu/berkeley/obits/device/atmel/AvrDrone.java +++ b/src/edu/berkeley/obits/device/atmel/AvrDrone.java @@ -30,7 +30,7 @@ public class AvrDrone extends AtmelDevice { } private void init() throws IOException { - Log.debug(this, "waiting for device to identify itself"); + //Log.debug(this, "waiting for device to identify itself"); /* if (in.readByte() != (byte)'O') throw new RuntimeException("didn't get the proper signature"); if (in.readByte() != (byte)'B') throw new RuntimeException("didn't get the proper signature"); @@ -43,10 +43,10 @@ public class AvrDrone extends AtmelDevice { byte[] bytes = new byte[6]; for(int i=0; i<6; i++) { bytes[i] = in.readByte(); - System.out.println("got " + (i+1) + " header bytes: " + (bytes[i] & 0xff) + " '" + ((char)bytes[i]) + "'"); + //System.out.println("got " + (i+1) + " header bytes: " + (bytes[i] & 0xff) + " '" + ((char)bytes[i]) + "'"); // FIXME } - Log.info(this, "device correctly identified itself; ready for operation"); + //Log.info(this, "device correctly identified itself; ready for operation"); } public synchronized void scanFPGA(boolean on) throws DeviceException { diff --git a/src/edu/berkeley/slipway/FtdiBoard.java b/src/edu/berkeley/slipway/FtdiBoard.java index d84afa1..ee29066 100644 --- a/src/edu/berkeley/slipway/FtdiBoard.java +++ b/src/edu/berkeley/slipway/FtdiBoard.java @@ -3,7 +3,7 @@ package edu.berkeley.slipway; import com.ftdi.usb.*; import com.atmel.fpslic.*; import edu.berkeley.obits.*; -import org.ibex.util.Log; +import org.ibex.util.*; import java.io.*; import java.util.*; import gnu.io.*; @@ -41,7 +41,8 @@ public class FtdiBoard extends Board { chip.selfTest(); - OutputStream os = chip.getConfigStream(); + int total = 75090/9; + OutputStream os = new ProgressOutputStream("bootstrap bitstream:", chip.getConfigStream(), total); BufferedReader br = new BufferedReader(r); int bytes = 0; @@ -50,10 +51,7 @@ public class FtdiBoard extends Board { if (s==null) break; bytes++; os.write((byte)Integer.parseInt(s, 2)); - if ((bytes % 1000)==0) { - os.flush(); - System.out.print("wrote " + bytes + " bytes\r"); - } + if ((bytes % 1000)==0) os.flush(); } os.close(); } diff --git a/src/org/ibex/util/ProgressInputStream.java b/src/org/ibex/util/ProgressInputStream.java new file mode 100644 index 0000000..9908071 --- /dev/null +++ b/src/org/ibex/util/ProgressInputStream.java @@ -0,0 +1,54 @@ +package org.ibex.util; +import java.io.*; + +public class ProgressInputStream extends FilterInputStream { + + private int size = -1; + private int bytes = 0; + private String title; + + public ProgressInputStream(String title, InputStream o) { this(title, o, -1); } + + public ProgressInputStream(String title, InputStream o, int size) { + super(o); + this.size = size; + this.title = title; + } + + public int read() throws IOException { + int ret = super.read(); + if (ret != -1) bytes++; + return ret; + } + + public int read(byte[] b, int off, int len) throws IOException { + int ret = super.read(b, off, len); + if (ret != -1) bytes += ret; + update(); + return ret; + } + + private void update() { + System.out.print("\r \r"); + System.out.print(title); + if (size != -1) { + int frac = (100 * bytes) / size; + String fracs = frac+""; + while(fracs.length()<3) fracs = " "+fracs; + System.out.print(" "); + System.out.print("\033[32m"); + System.out.print(fracs+"%"); + System.out.print("\033[0m"); + } + System.out.print(" "); + System.out.print(bytes); + System.out.print(" bytes "); + } + + public void close() throws IOException { + super.close(); + bytes = size; + update(); + System.out.println(); + } +} diff --git a/src/org/ibex/util/ProgressOutputStream.java b/src/org/ibex/util/ProgressOutputStream.java new file mode 100644 index 0000000..a671f3a --- /dev/null +++ b/src/org/ibex/util/ProgressOutputStream.java @@ -0,0 +1,53 @@ +package org.ibex.util; +import java.io.*; + +public class ProgressOutputStream extends FilterOutputStream { + + private int size = -1; + private int bytes = 0; + private String title; + + public ProgressOutputStream(String title, OutputStream o) { this(title, o, -1); } + + public ProgressOutputStream(String title, OutputStream o, int size) { + super(o); + this.size = size; + this.title = title; + } + + public void write(int i) throws IOException { + super.write(i); + bytes++; + update(); + } + + public void write(byte[] b, int off, int len) throws IOException { + super.write(b, off, len); + bytes += len; + update(); + } + + private void update() { + System.out.print("\r \r"); + System.out.print(title); + if (size != -1) { + int frac = (100 * bytes) / size; + String fracs = frac+""; + while(fracs.length()<3) fracs = " "+fracs; + System.out.print(" "); + System.out.print("\033[32m"); + System.out.print(fracs+"%"); + System.out.print("\033[0m"); + } + System.out.print(" "); + System.out.print(bytes); + System.out.print(" bytes "); + } + + public void close() throws IOException { + super.close(); + bytes = size; + update(); + System.out.println(); + } +} -- 1.7.10.4