X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fcom%2Fatmel%2Ffpslic%2FChipImpl.java;h=dedc4b04b32c95bcec41ec3dd6fec684291eb7b3;hb=3212d3617ec8c1b2dce1e8a0991f196f03236ef9;hp=66557fa9986b64171a36f396d51b552705487c6a;hpb=10b33f2888bcd7dd97f8a8ef84b9e63f0694e4c3;p=slipway.git diff --git a/src/com/atmel/fpslic/ChipImpl.java b/src/com/atmel/fpslic/ChipImpl.java index 66557fa..dedc4b0 100644 --- a/src/com/atmel/fpslic/ChipImpl.java +++ b/src/com/atmel/fpslic/ChipImpl.java @@ -14,12 +14,22 @@ public class ChipImpl extends FtdiUart implements Chip { (1<<6) | (1<<7); - public ChipImpl() { - super(0x6666, 0x3133); + public ChipImpl() throws IOException { + super(0x6666, 0x3133, 1500 * 1000); doReset(); } - public void doReset() { + public void flush() throws IOException { getOutputStream().flush(); } + + 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 void doReset() throws IOException { dmask = (1<<0) | @@ -35,7 +45,7 @@ public class ChipImpl extends FtdiUart implements Chip { flush(); //purge(); - dbangmode(dmask); + dbus_mode(dmask); flush(); clk(false); @@ -48,19 +58,18 @@ public class ChipImpl extends FtdiUart implements Chip { flush(); try { Thread.sleep(500); } catch (Exception e) { } if (initErr()) throw new RuntimeException("INIT was still high after pulling RESET low"); - //System.out.println("0 con() = " + con()); reset(true); flush(); try { Thread.sleep(500); } catch (Exception e) { } if (!initErr()) throw new RuntimeException("INIT was still low after releasing RESET"); - //System.out.println("1 con() = " + con()); + con(false); } - public void config(boolean bit) { config(bit?1:0, 1); } - public void config(int dat) { config(dat, 8); } - public void config(int dat, int numbits) { + public void config(boolean bit) throws IOException { config(bit?1:0, 1); } + public void config(int dat) throws IOException { config(dat, 8); } + public 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.doReset(); + 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(); + try { Thread.sleep(100); } catch (Exception e) { } + pin = d.initErr(); + System.out.println("bad preamble #2 => " + pin + " " + (pin ? red("BAD") : green("good"))); + + d.doReset(); + 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(); + try { Thread.sleep(100); } catch (Exception e) { } + pin = d.initErr(); + System.out.println("bad preamble #1 => " + pin + " " + (pin ? red("BAD") : green("good"))); } }