X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fatmel%2Ffpslic%2FFpslicRawUsb.java;h=d6fddeeac4348d8835a4b1c1a7412dae5c183869;hb=d44022802297d495dfb0de032251f62d0021a1f6;hp=a459e8df111c8a9e0f7a8b5bd0548820e2f4e7b6;hpb=75fe11ac15f5de917698dc6649b862e38b087564;p=slipway.git diff --git a/src/com/atmel/fpslic/FpslicRawUsb.java b/src/com/atmel/fpslic/FpslicRawUsb.java index a459e8d..d6fddee 100644 --- a/src/com/atmel/fpslic/FpslicRawUsb.java +++ b/src/com/atmel/fpslic/FpslicRawUsb.java @@ -2,129 +2,49 @@ package com.atmel.fpslic; import com.ftdi.usb.*; import java.io.*; -public class FpslicRawUsb extends FtdiUart implements FpslicRaw { - - private int dmask = - (1<<0) | - (1<<1) | - (1<<2) | - //(1<<3) | - //(1<<4) | - (1<<5) | - (1<<6) | - (1<<7); - - public FpslicRawUsb() throws IOException { - super(0x6666, 0x3133, 1500 * 1000); - reset(); - } +/** + * Exposes the FpslicRaw interface of an FPSLIC wired to an FTDI USB-UART. + */ +public class FpslicRawUsb implements FpslicRaw { - void flush() throws IOException { getOutputStream().flush(); } + private FpslicPins pins; - protected int dbits = 0; - protected synchronized void dbang(int bit, boolean val) throws IOException { - dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit))); - try { - getOutputStream().write((byte)dbits); - } catch (IOException e) { throw new RuntimeException(e); } + public FpslicRawUsb(FtdiUart ftdiuart) throws IOException { + 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(); - - 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"); + if (pins.initPin()) throw new RuntimeException("INIT was still high after pulling RESET low"); - 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"))); - - d.reset(); + System.out.print("smoke check: "); + + // correct preamble + getConfigStream(); + sendConfigBits(Integer.parseInt("00000000", 2), 8); + sendConfigBits(Integer.parseInt("10110111", 2), 8); + sendConfigBits(0,1); + pins.flush(); try { Thread.sleep(100); } catch (Exception e) { } - d.config(0,3); - d.con(); - d.config(0,6); - d.flush(); - //d.flush(); - d.config(Integer.parseInt("10110111", 2), 8); - d.config(0, 2); - d.flush(); + 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) { } - pin = d.initErr(); - System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good"))); - - d.reset(); + 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) { } - d.config(0,3); - d.con(); - d.config(0,7); - d.flush(); - //d.flush(); - d.config(Integer.parseInt("11110111", 2), 8); - d.config(0, 1); - d.flush(); + 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) { } - pin = d.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<