X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fatmel%2Ffpslic%2FFpslicRawUsb.java;h=d6fddeeac4348d8835a4b1c1a7412dae5c183869;hb=1cec762092d76024df66b5fe8f5612399e678e27;hp=276b4e54ed9c51047caaae655270250b47bd76dd;hpb=e72abc67b542792d74ac3bb63460d23b10b40a52;p=slipway.git diff --git a/src/com/atmel/fpslic/FpslicRawUsb.java b/src/com/atmel/fpslic/FpslicRawUsb.java index 276b4e5..d6fddee 100644 --- a/src/com/atmel/fpslic/FpslicRawUsb.java +++ b/src/com/atmel/fpslic/FpslicRawUsb.java @@ -7,130 +7,44 @@ import java.io.*; */ public class FpslicRawUsb implements FpslicRaw { - private FtdiUart ftdiuart; - - private int dmask = - (1<<0) | - (1<<1) | - (1<<2) | - //(1<<3) | - //(1<<4) | - (1<<5) | - (1<<6) | - (1<<7); - - public FpslicRawUsb() throws IOException { - this(new FtdiUart(0x6666, 0x3133, 1500 * 1000)); - } + private FpslicPins pins; + public FpslicRawUsb(FtdiUart ftdiuart) throws IOException { - this.ftdiuart = ftdiuart; + this.pins = new FpslicPinsUsb(ftdiuart); reset(); } - void flush() throws IOException { ftdiuart.getOutputStream().flush(); } - - protected int dbits = 0; - protected synchronized void dbang(int bit, boolean val) throws IOException { - dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); - ftdiuart.getOutputStream().write((byte)dbits); - } - public void reset() throws IOException { - dmask = - (1<<0) | - (1<<1) | - (1<<2) | - //(1<<3) | - //(1<<4) | - (1<<5) | - (1<<6) | - (1<<7); - avrrst(false); - - flush(); - //purge(); - - ftdiuart.dbus_mode(dmask); - flush(); - - clk(false); - data(false); - con(false); - flush(); - //try { Thread.sleep(500); } catch (Exception e) { } - - reset(false); - flush(); - try { Thread.sleep(500); } catch (Exception e) { } - if (initErr()) throw new RuntimeException("INIT was still high after pulling RESET low"); + pins.avrrstPin(false); + pins.configDataPin(false); + pins.resetPin(false); + pins.cclkPin(false); + + pins.conPin(false); + pins.flush(); - reset(true); - flush(); + pins.resetPin(false); try { Thread.sleep(500); } catch (Exception e) { } - if (!initErr()) throw new RuntimeException("INIT was still low after releasing RESET"); - - con(false); - } - - void config(boolean bit) throws IOException { config(bit?1:0, 1); } - void config(int dat) throws IOException { config(dat, 8); } - void config(int dat, int numbits) throws IOException { - for(int i=(numbits-1); i>=0; i--) { - boolean bit = (dat & (1<=0; i--) { - config((((in & 0xff) & (1< " + pin + " " + (pin ? green("good") : red("BAD"))); - - reset(); + pin = pins.initPin(); + System.out.print((pin ? green(" [pass]") : red(" [FAIL]"))); + + // preamble shifted one bit earlier than it should be + getConfigStream(); + sendConfigBits(Integer.parseInt("0000000", 2), 7); + sendConfigBits(Integer.parseInt("10110111", 2), 8); + sendConfigBits(0, 2); + pins.flush(); try { Thread.sleep(100); } catch (Exception e) { } - config(0,3); - con(); - config(0,6); - flush(); - //flush(); - config(Integer.parseInt("10110111", 2), 8); - config(0, 2); - flush(); + pin = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + + // preamble shifted one bit later than it should be + getConfigStream(); + sendConfigBits(Integer.parseInt("000000000", 2), 9); + sendConfigBits(Integer.parseInt("10110111", 2), 8); + //sendConfigBits(0, 1); + pins.flush(); try { Thread.sleep(100); } catch (Exception e) { } - pin = initErr(); - System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good"))); - - reset(); + pin = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + + // plain 'ol bogus preamble + getConfigStream(); + sendConfigBits(Integer.parseInt("00000000", 2), 8); + sendConfigBits(Integer.parseInt("11110111", 2), 8); + sendConfigBits(0, 1); + pins.flush(); try { Thread.sleep(100); } catch (Exception e) { } - config(0,3); - con(); - config(0,7); - flush(); - //flush(); - config(Integer.parseInt("11110111", 2), 8); - config(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 = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + + System.out.println(); } + + // Private ////////////////////////////////////////////////////////////////////////////// + + private void sendConfigBits(int dat, int numbits) throws IOException { + for(int i=(numbits-1); i>=0; i--) { + boolean bit = (dat & (1<