X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fobits%2Fdevice%2Fatmel%2FChipImpl.java;h=ec48f7bc4cccd5fba68bfa3b87449c6bcbc5d39d;hb=7f6492ec8a39f2bb510d5be0b92031f231a2a935;hp=6231c02bb925a2141f59ad2548b4197a4fd09bb5;hpb=47d5266e9936715198b0cd2d0339aacf7f2c847c;p=slipway.git diff --git a/src/edu/berkeley/obits/device/atmel/ChipImpl.java b/src/edu/berkeley/obits/device/atmel/ChipImpl.java index 6231c02..ec48f7b 100644 --- a/src/edu/berkeley/obits/device/atmel/ChipImpl.java +++ b/src/edu/berkeley/obits/device/atmel/ChipImpl.java @@ -4,28 +4,43 @@ import java.io.*; 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); + public ChipImpl() { super(); doReset(); } public void doReset() { - dbangmode(); + + flush(); + + dbangmode(dmask); + flush(); + clk(false); data(false); - con(false); flush(); - buffered(false); + reset(false); - //avrrst(false); - try { Thread.sleep(200); } catch (Exception e) { } + flush(); + try { Thread.sleep(500); } catch (Exception e) { } + reset(true); - //avrrst(true); - try { Thread.sleep(200); } catch (Exception e) { } + flush(); + try { Thread.sleep(500); } catch (Exception e) { } - dmask &= ~(1<<7); - dbangmode(); + dbangmode(dmask); + flush(); } int porte = 0; @@ -37,11 +52,6 @@ public class ChipImpl extends FtdiChip implements Chip { } } - - // - - public void buffered() { buffered = true; } - public void buffered(boolean buf) { buffered = buf; } 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) { @@ -55,112 +65,23 @@ public class ChipImpl extends FtdiChip implements Chip { public void reset(boolean on) { bits = on ? (1<<1) : 0; - cbangmode(); - //dbang(0, on); + uart(); } public void avrrst(boolean on) { dbang(7, on); } - public boolean initErr() { return (readPins() & (1<<4))!=0; } public void clk(boolean on) { dbang(6, on); } public void data(boolean on) { dbang(5, on); } + public boolean initErr() { flush(); return (readPins() & (1<<4))!=0; } public boolean con() { - - /* - mask &= ~(1<<0); - cbangmode(); - boolean ret = (readPins() & (1<<0)) != 0; - dbangmode(); - return ret; - */ - - - + flush(); dmask &= ~(1<<0); - dbangmode(); + dbangmode(dmask); return (readPins() & (1<<0)) != 0; - } public void con(boolean on) { - - /* - mask |= (1<<0); - bits = on ? (1<<0) : 0; - cbangmode(); - */ - - + flush(); dmask |= (1<<0); - dbangmode(); + dbangmode(dmask); dbang(0, on); - } - - - // UART comm pair ////////////////////////////////////////////////////////////////////////////// - - - private OutputStream os = new ChipOutputStream(); - private InputStream is = new ChipInputStream(); - public OutputStream getOutputStream() { return os; } - public InputStream getInputStream() { return is; } - - public class ChipInputStream extends InputStream { - public int available() throws IOException { - // FIXME - return 0; - } - public long skip(long l) throws IOException { - throw new RuntimeException("not supported"); - } - public int read() throws IOException { - System.out.println("read()"); - byte[] b = new byte[1]; - int result = 0; - while(result==0) - result = read(b, 0, 1); - if (result==-1) - throw new IOException("ftdi_read_pins() returned " + result); - return b[0] & 0xff; - } - public int read(byte[] b, int off, int len) throws IOException { - // FIXME: blocking reads? - int result = 0; - while(true) { - if (len==0) return 0; - byte[] b0 = new byte[len]; - synchronized(ChipImpl.this) { - result = example.ftdi_read_data(context, b0, len); - } - if (result == -1) - throw new IOException("ftdi_read_pins() returned " + result); - if (result>0) { - System.arraycopy(b0, 0, b, off, result); - return result; - } - try { Thread.sleep(50); } catch (Exception e) { e.printStackTrace(); } - } - } - } - - public class ChipOutputStream extends OutputStream { - public void write(int b) throws IOException { - byte[] d = new byte[1]; - d[0] = (byte)b; - write(d, 0, 1); - } - public void write(byte[] b, int off, int len) throws IOException { - byte[] b2 = new byte[64]; - while(len > 0) { - System.arraycopy(b, off, b2, 0, Math.min(b2.length, len)); - synchronized(ChipImpl.this) { - int result = example.ftdi_write_data(context, b2, Math.min(b2.length, len)); - if (result < 0) - throw new IOException("ftdi_write_data() returned " + result); - off += result; - len -= result; - } - } - } - } - }