X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fobits%2Fdevice%2Fatmel%2FChipImpl.java;h=05ed4f2f9972c4fbb3ab8757cafcc7685cfc891c;hb=1569edbaee7c8ff330a7f3289856970c46082a12;hp=5cb10ec80b6bc1fae0aa865dfa591db1a47ea357;hpb=8ebad3793f9372a389c1904b461debd8add2d853;p=slipway.git diff --git a/src/edu/berkeley/obits/device/atmel/ChipImpl.java b/src/edu/berkeley/obits/device/atmel/ChipImpl.java index 5cb10ec..05ed4f2 100644 --- a/src/edu/berkeley/obits/device/atmel/ChipImpl.java +++ b/src/edu/berkeley/obits/device/atmel/ChipImpl.java @@ -2,7 +2,17 @@ package edu.berkeley.obits.device.atmel; import com.ftdi.usb.*; import java.io.*; -public class ChipImpl extends FtdiChip implements Chip { +public class ChipImpl extends FtdiUart implements Chip { + + private int dmask = + (1<<0) | + (1<<1) | + (1<<2) | + //(1<<3) | + //(1<<4) | + (1<<5) | + (1<<6) | + (1<<7); public ChipImpl() { super(); @@ -10,22 +20,42 @@ public class ChipImpl extends FtdiChip implements Chip { } public void doReset() { + + dmask = + (1<<0) | + (1<<1) | + (1<<2) | + //(1<<3) | + //(1<<4) | + (1<<5) | + (1<<6) | + (1<<7); + avrrst(false); + + flush(); + //purge(); + dbangmode(dmask); + flush(); + clk(false); data(false); - con(false); flush(); - buffered(false); + //try { Thread.sleep(500); } catch (Exception e) { } + reset(false); - //avrrst(false); - try { Thread.sleep(200); } catch (Exception e) { } - reset(true); - //avrrst(true); - try { Thread.sleep(200); } catch (Exception e) { } + 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()); - dmask &= ~(1<<7); - dbangmode(dmask); + 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); } int porte = 0; @@ -37,9 +67,6 @@ public class ChipImpl extends FtdiChip implements Chip { } } - - // - 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) { @@ -51,33 +78,45 @@ public class ChipImpl extends FtdiChip implements Chip { } } - protected int dmask = - //(1<<0) | - (1<<1) | - (1<<2) | - //(1<<3) | - //(1<<4) | - (1<<5) | - (1<<6) | - (1<<7); - + // tricky: RESET has a weak pull-up, and is wired to a CBUS line. So, + // we can pull it down (assert reset) from uart-mode, or we can + // let it float upward from either mode. public void reset(boolean on) { bits = on ? (1<<1) : 0; + mask = (1<<1); uart(); + flush(); + if (on) { + //mask = 0; + //uart(); + //flush(); + dbangmode(dmask); + flush(); + } } + public void avrrst(boolean on) { dbang(7, on); } public void clk(boolean on) { dbang(6, on); } public void data(boolean on) { dbang(5, on); } - public boolean initErr() { return (readPins() & (1<<4))!=0; } + public boolean initErr() { flush(); return (readPins() & (1<<4))!=0; } + public boolean con() { + flush(); + //dmask &= ~(1<<0); + dbangmode(dmask); + return (readPins() & (1<<0)) != 0; + } + public boolean rcon() { + flush(); dmask &= ~(1<<0); dbangmode(dmask); return (readPins() & (1<<0)) != 0; } public void con(boolean on) { + flush(); dmask |= (1<<0); - dbangmode(dmask); dbang(0, on); + dbangmode(dmask); } }