From f720ef5a2aeeca2b0fdf46721fa0bdd10b513720 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 22 Sep 2006 08:04:31 +0100 Subject: [PATCH] checkpoint --- src/edu/berkeley/obits/AtmelSerial.java | 28 ++- .../berkeley/obits/device/atmel/AtmelDevice.java | 242 +------------------- src/edu/berkeley/obits/device/atmel/AvrDrone.java | 78 +++---- .../obits/device/atmel/FakeAtmelDevice.java | 2 +- src/edu/berkeley/obits/gui/Gui.java | 54 +++-- 5 files changed, 88 insertions(+), 316 deletions(-) diff --git a/src/edu/berkeley/obits/AtmelSerial.java b/src/edu/berkeley/obits/AtmelSerial.java index aab369b..54cee70 100644 --- a/src/edu/berkeley/obits/AtmelSerial.java +++ b/src/edu/berkeley/obits/AtmelSerial.java @@ -932,11 +932,15 @@ public class AtmelSerial { g.setColor(BLUE); g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35); } }; - scan(dev, cell, NONE, true); - drone.readBus(bc); - //scan(dev, cell, XLUT, true); - //boolean x = (drone.readBus() & 0x80) != 0; - scan(dev, cell, NONE, false); + try { + scan(dev, cell, NONE, true); + drone.readBus(bc); + //scan(dev, cell, XLUT, true); + //boolean x = (drone.readBus() & 0x80) != 0; + scan(dev, cell, NONE, false); + } catch (IOException ex) { + throw new RuntimeException(ex); + } } public void mouseMoved(MouseEvent e) { @@ -1483,11 +1487,15 @@ public class AtmelSerial { } }; scan(dev, cell, NONE, true); - drone.readBus(bc); - //scan(dev, cell, YLUT, false); - cell.v(L3, false); - dev.cell(x, 15).h(L3, false); - dev.cell(x, 15).v(L3, false); + try { + drone.readBus(bc); + //scan(dev, cell, YLUT, false); + cell.v(L3, false); + dev.cell(x, 15).h(L3, false); + dev.cell(x, 15).v(L3, false); + } catch (IOException ex) { + throw new RuntimeException(ex); + } } } } diff --git a/src/edu/berkeley/obits/device/atmel/AtmelDevice.java b/src/edu/berkeley/obits/device/atmel/AtmelDevice.java index ffad1f4..a25a707 100644 --- a/src/edu/berkeley/obits/device/atmel/AtmelDevice.java +++ b/src/edu/berkeley/obits/device/atmel/AtmelDevice.java @@ -6,7 +6,7 @@ import java.util.*; import java.io.*; import org.ibex.util.Log; -public abstract class AtmelDevice extends Bits implements Device { +public abstract class AtmelDevice { public static class Util { public static int lutSwap(int x) { @@ -91,6 +91,8 @@ public abstract class AtmelDevice extends Bits implements Device { in.close(); } + public abstract void flush(); + public void writeMode4(Writer w) throws IOException { for(int x=0; x>24, (zyx>>16)&0xff, (zyx>>8)&0xff); } public void mode4zyx(int zyx, int d, int invmask) { mode4(zyx>>24, (zyx>>16)&0xff, (zyx>>8)&0xff, d, invmask); } @@ -131,240 +133,4 @@ public abstract class AtmelDevice extends Bits implements Device { old |= set ? (1 << bit) : 0; mode4(z, y, x, old); } - /* - public Sector sector(int col, int row) { return new Sector(col, row); } - public final class Sector { - public final int col; - public final int row; - public Sector(int col, int row) { - if (row % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 row"); - if (col % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 col"); - this.row = row; - this.col = col; - } - } - - public static interface Driver { } - - public static interface HasPlane { public int getPlane(); } - - public static interface XI extends Driver { } - public static interface YI extends Driver { } - */ - /* - public static void foo(Direction f) { } - public static enum Direction implements Drives { N, S, E, W; } - public static enum Bar { A, B, C; } - public static Object B = new Object(); - public static Direction foo = null; - static { - switch(foo) { - case N: - case S: - case W: - } - } - - public class Drives> { } - public class EPR> { - public abstract Drives driver(); - public abstract void driver(Drives); - } - - public class Joins> { } - public abstract class Bus> { - public Set> drivers(); - } - public interface Drives { } - - - public static interface EPR { - } - public static interface Drives { } - public static interface Bus extends EPR { } - public static interface Joins> extends Bus { } - //public static interface Joins extends Bus { } - public static interface Has { - public Drives getDriver(E e); - public void setDriver(E e, Drives driver); - } - //public static interface HasBus { public Set> on(B b); } - public interface Input { } - public interface Output { } - public interface InOut { } - - public static abstract class LUT implements EPR { } - public static abstract class And implements EPR { } - public static abstract class Reg { } - public static abstract class Mux { } - public static abstract class Buf { } - - public enum DiagonalInputs implements Input, Drives { NW, SW, NE, SE; } - public enum OrthogonalInputs implements Input, Drives { N, S, E, W; } - - public , Y extends EPR> void connect(X x, Y y) { } - - public static enum Plane { P0, P1, P2, P3, P4; } - public static class L

implements Bus, Drives, Drives, Drives, Drives { } - - public final class Cell { - public class X implements EPR, Drives, Drives { } - public class Y implements EPR, Drives, Drives { } - public class Z implements EPR, Drives, Drives { } - public class F implements EPR, Drives, Drives, Drives { } - public class W implements EPR, Drives, Drives, Drives { } - public class A implements EPR { } - public class WZ extends And implements EPR, Drives, Drives { } - public class WF extends And implements EPR, Drives, Drives { } - public class CM extends Mux implements EPR, Drives { } - public class XLUT extends LUT implements EPR, Drives, Drives { } - public class YLUT extends LUT implements EPR, Drives, Drives { } - public class C implements EPR, Drives, Drives { } - public class R extends Reg implements EPR, Drives, Drives, Drives{ } - public class XO implements EPR, Output { } - public class YO implements EPR, Output { } - public static class OB extends Buf> implements EPR, Drives, Drives, Drives, Drives, Drives { } - - */ - //public static L1 L1 = new L1(); - /* - public static class CellImpl implements - Has, - Has { - public void setDriver(X x, Drives d) { } - public void setDriver(Y y, Drives d) { } - public void setDriver(Z z, Drives d) { } - public void setDriver(W w, Drives d) { } - public Drives getDriver(X x) { return null; } - public Drives getDriver(Y y) { return null; } - public Drives getDriver(Z z) { return null; } - public Drives getDriver(W w) { return null; } - - public Set> on(L1 l1) { return null; } - public Drives getDriver(Y y) { return null; } - public void setDriver(Y y, Drives d) { } - } - */ - /* - public static abstract class L implements HasPlane, EPR { - private final int plane; - L(int plane) { this.plane = plane; } - public int getPlane() { return plane; } - public boolean h(); - public void h(boolean connected); - public boolean v(); - public void v(boolean connected); - public boolean f(); - public void f(boolean connected); - } - - L0 = new L(0); - L1 = new L(1); - L2 = new L(2); - L3 = new L(3); - L4 = new L(4); - - - - public static enum L implements XI, YI { - L0(0), L1(1), L2(2), L3(3) { public int foo() { return 2; } }, L4(4); - - public final int plane; - public L(int plane) { this.plane = plane; } - - } - */ - - //public static interface L0 extends XI, YI { } public static L0 L0 = new L0() { }; - - /* - - public static enum Xi { NONE, L0, L1, L2, L3, NW, SW, NE, SE, L4; } - public static enum Yi { NONE, L0, L1, L2, L3, E, W, S, N, L4; } - public static enum Wi { NONE, L0, L1, L4, L3, L2; } - public static enum Zi { NONE, L0, L1, L2, L3, L4; } - public static enum Ti { W, Z, F, WZ, WF, ONE; } - public static enum Ci { X, Y, CMux; } - public static enum Fi { R, C; } - public static enum Bi { R, C; } - public static enum Xo { X, B; } - public static enum Yo { Y, B; } - public static enum Oe { ONE, H4, V4; } - - public Cell cell(int col, int row) { return new Cell(col, row); } - public final class Cell { - public final int col; - public final int row; - */ - /** assumes LITTLE endian */ - /* - protected int onehot(int val) { - int ret = -1; - for(int i=0; i<32; i++) { - if ((val & (1 << i)) != 0) { - if (ret != -1) throw new Error("two bits set in a one-hot encoded value"); - ret = i; - } - } - return ret+1; - } - protected int bits(int octet, int bit, int count) { - return AtmelDevice.this.bits.get(offset, count); - } - - public void set(Xi xi) { } - public void set(Yi xi) { } - public void set(Ti xi) { } - public void set(Ci xi) { } - public void set(Fi xi) { } - public void set(Bi xi) { } - public void set(Xo xo) { } - public void set(Yo yo) { } - public void set(Oe oe) { } - - public Xi xi() { return Xi.values()[onehot((bits(3,3,1)<<8)|bits(5,0,8))]; } - public Yi yi() { return Yi.values()[onehot((bits(2,1,1)<<8)|bits(4,0,8))]; } - public Wi wi() { return Wi.values()[onehot((bits(3,0,3)<<2)|bits(3,4,2))]; } - public Zi zi() { return Zi.values()[onehot((bits(2,0,1)<<4)|bits(2,2,4))]; } - public Ti ti() { return null; } - public Ci ci() { return null; } - public Fi fi() { return null; } - public Bi bi() { return null; } - public Xo xo() { return Xo.values()[onehot(bits(1,6,1))]; } - public Yo yo() { return Yo.values()[onehot(bits(1,7,1))]; } - public Oe oe() { return Oe.values()[onehot(bits(3,6,2))]; } - - public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); } - public Cell(int col, int row) { - this.row = row; - this.col = col; - } - - - - - public static enum EPR { L0, L1, L2, L3, L4 } - public static enum XInputDriver extends InputDriver { - public static enum YInputDriver extends InputDriver { N, S, E, W } - public XInputDriver xi() { } - public void xi(XInputDriver) { } - public YInputDriver yi() { } - public void yi(YInputDriver) { } - public InputDriver zi() { } - public void zi(InputDriver) { } - public InputDriver wi() { } - public void wi(InputDriver) { } - - public byte xlut() { } - public xlut(byte) { } - public byte ylut() { } - public ylut(byte) { } - - public static enum CInputDriver { XL, YL, C } - public static enum FDriver { R, C } - - public boolean cRegistered() { } - - } - */ } diff --git a/src/edu/berkeley/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/obits/device/atmel/AvrDrone.java index 7860ad6..f73f0a7 100644 --- a/src/edu/berkeley/obits/device/atmel/AvrDrone.java +++ b/src/edu/berkeley/obits/device/atmel/AvrDrone.java @@ -21,12 +21,8 @@ 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 { @@ -54,19 +50,17 @@ public class AvrDrone extends AtmelDevice { } - 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(); @@ -89,7 +83,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 { @@ -113,32 +107,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]; @@ -149,7 +139,7 @@ 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]: " + @@ -182,13 +172,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); } diff --git a/src/edu/berkeley/obits/device/atmel/FakeAtmelDevice.java b/src/edu/berkeley/obits/device/atmel/FakeAtmelDevice.java index 9d245e5..f603009 100644 --- a/src/edu/berkeley/obits/device/atmel/FakeAtmelDevice.java +++ b/src/edu/berkeley/obits/device/atmel/FakeAtmelDevice.java @@ -7,7 +7,7 @@ import org.ibex.util.Log; public class FakeAtmelDevice extends AtmelDevice { - public void mode4(int z, int y, int x, int d) throws DeviceException { } + public void mode4(int z, int y, int x, int d) { } public byte mode4(int z, int y, int x) { // FIXME return 0; diff --git a/src/edu/berkeley/obits/gui/Gui.java b/src/edu/berkeley/obits/gui/Gui.java index 394ca7d..59e4cc8 100644 --- a/src/edu/berkeley/obits/gui/Gui.java +++ b/src/edu/berkeley/obits/gui/Gui.java @@ -719,33 +719,37 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene scan(ca[x][y]); } public void scan(final Gui.Cell c) { - final At40k.Cell cell = c.cell; - AtmelSerial.scan(at40k, cell, NONE, true); - boolean safe = !cell.fb_relevant(); - if (cell.xo()) safe = false; - if (cell.yo()) safe = false; - for(int i=0; i<5; i++) - if (cell.out(i)) - safe = false; - if (safe) { - int oldc = cell.c(); - if (cell.xlut_relevant()) { - cell.c(XLUT); - drone.readBus(new BCB(c, XLUT)); - } - if (cell.ylut_relevant()) { - cell.c(YLUT); - drone.readBus(new BCB(c, YLUT)); - } - cell.c(oldc); - } else { - switch(cell.c()) { - case XLUT: if (cell.xlut_relevant()) drone.readBus(new BCB(c, XLUT)); break; - case YLUT: if (cell.ylut_relevant()) drone.readBus(new BCB(c, YLUT)); break; + try { + final At40k.Cell cell = c.cell; + AtmelSerial.scan(at40k, cell, NONE, true); + boolean safe = !cell.fb_relevant(); + if (cell.xo()) safe = false; + if (cell.yo()) safe = false; + for(int i=0; i<5; i++) + if (cell.out(i)) + safe = false; + if (safe) { + int oldc = cell.c(); + if (cell.xlut_relevant()) { + cell.c(XLUT); + drone.readBus(new BCB(c, XLUT)); + } + if (cell.ylut_relevant()) { + cell.c(YLUT); + drone.readBus(new BCB(c, YLUT)); + } + cell.c(oldc); + } else { + switch(cell.c()) { + case XLUT: if (cell.xlut_relevant()) drone.readBus(new BCB(c, XLUT)); break; + case YLUT: if (cell.ylut_relevant()) drone.readBus(new BCB(c, YLUT)); break; + } + } - + AtmelSerial.scan(at40k, cell, NONE, false); + } catch (IOException e) { + throw new RuntimeException(e); } - AtmelSerial.scan(at40k, cell, NONE, false); } -- 1.7.10.4