X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fobits%2Fdevice%2Fatmel%2FAvrDrone.java;h=2854ece727dc8b7ecccd62c95df83f5afe1d2f2f;hb=e9724a11d269da6da7763cfe558691791809aa9b;hp=47aa49deb86a44390e44ea656118e75cfcb14cc8;hpb=5a91bf9a6e633c2ee544aa414ed54702b409883f;p=slipway.git diff --git a/src/edu/berkeley/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/obits/device/atmel/AvrDrone.java index 47aa49d..2854ece 100644 --- a/src/edu/berkeley/obits/device/atmel/AvrDrone.java +++ b/src/edu/berkeley/obits/device/atmel/AvrDrone.java @@ -1,5 +1,6 @@ package edu.berkeley.obits.device.atmel; +import com.atmel.fpslic.*; import edu.berkeley.slipway.*; import edu.berkeley.obits.*; import org.ibex.util.Log; @@ -8,7 +9,7 @@ import java.util.*; import gnu.io.*; /** the "host" side of the AVR Drone; see AvrDrone.c for the other side */ -public class AvrDrone extends AtmelDevice { +public class AvrDrone extends Fpslic { private final DataInputStream in; private final DataOutputStream out; @@ -21,58 +22,46 @@ public class AvrDrone extends AtmelDevice { init(); } - public void reset() throws DeviceException { - try { - board.reset(); - } catch (IOException e) { - throw new DeviceException(e); - } + public void reset() throws IOException { + board.reset(); } private void init() throws IOException { - //Log.debug(this, "waiting for device to identify itself"); - /* - if (in.readByte() != (byte)'O') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'B') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'I') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'T') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'S') throw new RuntimeException("didn't get the proper signature"); - if (in.readByte() != (byte)'\n') throw new RuntimeException("didn't get the proper signature"); - */ byte[] bytes = new byte[6]; int i=0; + out.write(0); + out.flush(); + + // read any crap that might be left in the buffer while(true) { System.arraycopy(bytes, 1, bytes, 0, 5); bytes[5] = in.readByte(); i++; - System.out.println("got " + new String(bytes)); + System.out.print("\rsignature: read \"" + new String(bytes) + "\" "); if (bytes[0] == (byte)'O' && bytes[1] == (byte)'B' && bytes[2] == (byte)'I' && bytes[3] == (byte)'T' && - bytes[4] == (byte)'S' && - bytes[5] == (byte)'\n') { - System.out.println("got proper signature"); + bytes[4] == (byte)'S') { + System.out.println("\rsignature: got proper signature "); break; } } - //Log.info(this, "device correctly identified itself; ready for operation"); + } - public synchronized void scanFPGA(boolean on) throws DeviceException { - try { - if (on) { - out.writeByte(3); - out.flush(); - } else { - // FIXME - } - } catch (IOException e) { throw new DeviceException(e); } + public synchronized void scanFPGA(boolean on) throws IOException { + if (on) { + out.writeByte(3); + out.flush(); + } else { + // FIXME + } } // fixme! public static int retval = 0; - public synchronized int readCount() throws DeviceException { + public synchronized int readCount() { try { if (reader != null) { reader.start(); @@ -95,7 +84,7 @@ public class AvrDrone extends AtmelDevice { bc.wait(); } return retval; - } catch (Exception e) { throw new DeviceException(e); } + } catch (Exception e) { throw new RuntimeException(e); } } public static interface ByteCallback { @@ -119,32 +108,28 @@ public class AvrDrone extends AtmelDevice { } }; - public synchronized void readBus(ByteCallback bc) throws DeviceException { - try { - callbacks.add(bc); - out.writeByte(2); - out.flush(); - if (reader != null) { - reader.start(); - reader = null; - } - } catch (IOException e) { throw new DeviceException(e); } + public synchronized void readBus(ByteCallback bc) throws IOException { + callbacks.add(bc); + out.writeByte(2); + out.flush(); + if (reader != null) { + reader.start(); + reader = null; + } } - public synchronized void readInterrupts(ByteCallback bc) throws DeviceException { - try { - callbacks.add(bc); - out.writeByte(6); - out.flush(); - if (reader != null) { - reader.start(); - reader = null; - } - } catch (IOException e) { throw new DeviceException(e); } + public synchronized void readInterrupts(ByteCallback bc) throws IOException { + callbacks.add(bc); + out.writeByte(6); + out.flush(); + if (reader != null) { + reader.start(); + reader = null; + } } private byte[][][] cache = new byte[24][][]; - public /*synchronized*/ byte mode4(int z, int y, int x) throws DeviceException { + public /*synchronized*/ byte mode4(int z, int y, int x) { if (cache[x]==null) return 0; if (cache[x][y]==null) return 0; return cache[x][y][z]; @@ -155,26 +140,8 @@ public class AvrDrone extends AtmelDevice { int lasty = 0; public static int save = 0; public static int saveof = 0; - public /*synchronized*/ void mode4(int z, int y, int x, int d) throws DeviceException { + public /*synchronized*/ void mode4(int z, int y, int x, int d) { try { - /* - Log.info(this, "writing configuration frame [zyxd]: " + - pad(1, Integer.toString(z&0xff, 16)) + " " + - pad(1, Integer.toString(y&0xff, 16)) + " " + - pad(1, Integer.toString(x&0xff, 16)) + " " + - pad(1, Integer.toString(d&0xff, 16)) - ); - */ - boolean zchange = z!=lastz; - boolean ychange = y!=lasty; - boolean xchange = x!=lastx; - boolean zinc = z==lastz+1; - boolean yinc = y==lasty+1; - boolean xinc = x==lastx+1; - boolean zdec = z==lastz-1; - boolean ydec = y==lasty-1; - boolean xdec = x==lastx-1; - out.writeByte(1); out.writeByte(z); out.writeByte(y); @@ -188,13 +155,17 @@ public class AvrDrone extends AtmelDevice { if (cache[x & 0xff]==null) cache[x & 0xff] = new byte[24][]; if (cache[x & 0xff][y & 0xff]==null) cache[x & 0xff][y & 0xff] = new byte[256]; cache[x & 0xff][y & 0xff][z & 0xff] = (byte)(d & 0xff); - } catch (IOException e) { throw new DeviceException(e); } + } catch (IOException e) { + throw new RuntimeException(e); + } } - public /*synchronized*/ void flush() throws DeviceException { + public /*synchronized*/ void flush() { try { out.flush(); - } catch (IOException e) { throw new DeviceException(e); } + } catch (IOException e) { + throw new RuntimeException(e); + } } private String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); }