X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fatmel%2Ffpslic%2FFpslicRawUsb.java;h=d6fddeeac4348d8835a4b1c1a7412dae5c183869;hb=d44022802297d495dfb0de032251f62d0021a1f6;hp=689dde59a8f17ca05ec764a9876bf1d06300db0c;hpb=45ad003d8b01b78557d37e408f31658c87e57810;p=slipway.git diff --git a/src/com/atmel/fpslic/FpslicRawUsb.java b/src/com/atmel/fpslic/FpslicRawUsb.java index 689dde5..d6fddee 100644 --- a/src/com/atmel/fpslic/FpslicRawUsb.java +++ b/src/com/atmel/fpslic/FpslicRawUsb.java @@ -7,66 +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); - ftdiuart.dbus_mode(dmask); - - avrrst(false); - clk(false); - data(false); - con(false); - - 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,2); - flush(); return new OutputStream() { int bytes = 0; int bits = 0; 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 = pins.initPin(); + System.out.print((pin ? green(" [pass]") : red(" [FAIL]"))); + // preamble shifted one bit earlier than it should be getConfigStream(); - config(0,1); - con(); - config(0,6); - flush(); - config(Integer.parseInt("10110111", 2), 8); - config(0, 2); - flush(); + 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]"))); + // preamble shifted one bit later than it should be getConfigStream(); - config(0,1); - con(); - config(0,7); - config(Integer.parseInt("11110111", 2), 8); - config(0, 1); - flush(); + 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 #1 => " + pin + " " + (pin ? red("BAD") : green("good"))); - } - - // Private ////////////////////////////////////////////////////////////////////////////// + pin = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); - private void flush() throws IOException { ftdiuart.getOutputStream().flush(); } + // 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) { } + pin = pins.initPin(); + System.out.print((pin ? red(" [FAIL]") : green(" [pass]"))); - 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); + System.out.println(); } - 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 ////////////////////////////////////////////////////////////////////////////// + + private void sendConfigBits(int dat, int numbits) throws IOException { for(int i=(numbits-1); i>=0; i--) { boolean bit = (dat & (1<