X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fatmel%2Ffpslic%2FFpslicRawUsb.java;h=d6fddeeac4348d8835a4b1c1a7412dae5c183869;hb=d44022802297d495dfb0de032251f62d0021a1f6;hp=ca3737e3a029b1311128919b8d614f02f71edc05;hpb=5aeb7bdf450ed5f7848218e1e33494ce4edd7858;p=slipway.git diff --git a/src/com/atmel/fpslic/FpslicRawUsb.java b/src/com/atmel/fpslic/FpslicRawUsb.java index ca3737e..d6fddee 100644 --- a/src/com/atmel/fpslic/FpslicRawUsb.java +++ b/src/com/atmel/fpslic/FpslicRawUsb.java @@ -7,73 +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); + private FpslicPins pins; public FpslicRawUsb(FtdiUart ftdiuart) throws IOException { - this.ftdiuart = ftdiuart; + this.pins = new FpslicPinsUsb(ftdiuart); reset(); } 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(); + pins.avrrstPin(false); + pins.configDataPin(false); + pins.resetPin(false); + pins.cclkPin(false); + + pins.conPin(false); + pins.flush(); + + pins.resetPin(false); try { Thread.sleep(500); } catch (Exception e) { } - if (initErr()) throw new RuntimeException("INIT was still high after pulling RESET low"); + if (pins.initPin()) throw new RuntimeException("INIT was still high after pulling RESET low"); - reset(true); - flush(); + pins.resetPin(true); try { Thread.sleep(500); } catch (Exception e) { } - if (!initErr()) throw new RuntimeException("INIT was still low after releasing RESET"); + if (!pins.initPin()) throw new RuntimeException("INIT was still low after releasing RESET"); - con(false); + sendConfigBits(0,2); + pins.flush(); } public OutputStream getConfigStream() throws IOException { reset(); - config(0,3); - con(); - config(0,7); - flush(); return new OutputStream() { int bytes = 0; int bits = 0; public void write(int in) throws IOException { for(int i=7; i>=0; i--) { - config((((in & 0xff) & (1< " + pin + " " + (pin ? green("good") : red("BAD"))); + pin = pins.initPin(); + System.out.print((pin ? green(" [pass]") : red(" [FAIL]"))); - reset(); - try { Thread.sleep(100); } catch (Exception e) { } - config(0,3); - con(); - config(0,6); - flush(); - // one too many - config(Integer.parseInt("10110111", 2), 8); - config(0, 2); - flush(); + // 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) { } - pin = initErr(); - System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good"))); + pin = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); - reset(); + // 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 = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); + + // plain 'ol bogus preamble getConfigStream(); - config(Integer.parseInt("11110111", 2), 8); - config(0, 1); - flush(); + sendConfigBits(Integer.parseInt("00000000", 2), 8); + sendConfigBits(Integer.parseInt("11110111", 2), 8); + sendConfigBits(0, 1); + pins.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 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))); - ftdiuart.getOutputStream().write((byte)dbits); - } - - 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<