## for rebuilding usbdrone.hex ###########################################################
-build/slipway_drone.hex: src/edu/berkeley/slipway/slipway_drone.c upstream/avr-libc/.built
+build/slipway_drone.hex: src/edu/berkeley/slipway/FtdiBoardSlave.c upstream/avr-libc/.built
upstream/prefix/bin/avr-gcc -O3 -mmcu=at94k $< -o $@.o
upstream/prefix/bin/avr-objcopy -O ihex $@.o $@
--- /dev/null
+- eeprom flash/restore
import java.io.*;
import org.ibex.util.Log;
-public class FakeAtmelDevice extends Fpslic {
+public class FakeFpslic extends Fpslic {
public void mode4(int z, int y, int x, int d) { }
public byte mode4(int z, int y, int x) {
import java.util.*;
import java.io.*;
import org.ibex.util.Log;
+import static com.atmel.fpslic.FpslicConstants.*;
public abstract class Fpslic {
old |= set ? (1 << bit) : 0;
mode4(z, y, x, old);
}
+
+ // Fpslic ///////////////////////////////////////////////////////////////////////////////
+
+
+
+ public final class Sector {
+ public final int col;
+ public final int row;
+ public Sector(Cell c) { this((c.col/4)*4, (c.row/4)*4); }
+ private 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 Sector north() { return row+4>=getHeight() ? null : new Sector(col, row+4); }
+ public Sector south() { return row==0 ? null : new Sector(col, row-4); }
+ public Sector east() { return col+4>=getWidth() ? null : new Sector(col+4, row); }
+ public Sector west() { return col==0 ? null : new Sector(col-4, row); }
+ public Cell cell() { return Fpslic.this.cell(col, row); }
+ }
+
+ public final class SectorWire {
+ public final boolean global;
+ public final boolean horizontal;
+ public final int plane;
+ public final int row;
+ public final int col;
+ public SectorWire(boolean horizontal, int plane, int col, int row) {
+ this.horizontal=horizontal;
+ this.global = false;
+ this.plane=plane;
+ this.col= horizontal ? (col & ~0x3) : col;
+ this.row=!horizontal ? (row & ~0x3) : row;
+ }
+ public boolean isDriven() {
+ // FIXME: bridging connections (horiz-to-vert)
+ for(int i=0; i<4; i++)
+ if (cell(horizontal ? col+i : col,
+ horizontal ? row : row+i).out(plane)) return true;
+ // FIXME: sector switchbox drivers
+ return false;
+ }
+ private int z(int z) { return (horizontal ? 0x30 : 0x20) | z; }
+ public int code(boolean topleft) {
+ switch(plane) {
+ case 0: return z(6)+(topleft?0:1);
+ case 1: return z(8)+(topleft?0:1);
+ case 2: return z(2*(4-plane))+(topleft?0:1);
+ case 3: return z(2*(4-plane))+(topleft?0:1);
+ case 4: return z(2*(4-plane))+(topleft?0:1);
+ }
+ throw new Error();
+ }
+
+ private final int fine() { return horizontal ? row : col; }
+ public final int coarse() { return horizontal ? col : row; }
+ private int _row() { return horizontal ? row : ((row)>>2); }
+ private int _col() { return horizontal ? ((col)>>2) : col; }
+
+ public SectorWire west() { return !horizontal ? null : col-4<0 ? null : new SectorWire(horizontal, plane, col-4, row); }
+ public SectorWire east() { return !horizontal ? null : col+4>=getWidth() ? null : new SectorWire(horizontal, plane, col+4, row); }
+ public SectorWire north() { return horizontal ? null : row+4>=getHeight() ? null : new SectorWire(horizontal, plane, col, row+4); }
+ public SectorWire south() { return horizontal ? null : row-4<0 ? null : new SectorWire(horizontal, plane, col, row-4); }
+
+ public String toString() {
+ return
+ (horizontal?(col+":"+(col+3)):(""+col))+","+
+ (horizontal?(row+"") :(row+":"+(row+3)))+
+ "x"+plane;
+ }
+
+ /** returns the ZYX0 coordinate of the byte controlling the switchbox that allows <tt>w</tt> to drive this wire */
+ public int switchbox(SectorWire w) {
+ if (w.horizontal==horizontal) {
+ if (w.plane!=plane) throw new Error();
+ if (Math.abs(w.coarse()-coarse())!=4) throw new Error(w.coarse() + " -- " + coarse());
+ boolean topleft = horizontal ? (w.coarse() < coarse()) : (w.coarse() > coarse());
+ int col = _col() + (( horizontal && !topleft) ? 1 : 0);
+ int row = _row() + ((!horizontal && topleft) ? 1 : 0);
+ return (code(topleft) << 24) | (row<<16) | (col<<8);
+ }
+ throw new Error("not implemented");
+ }
+
+ public void drives(SectorWire w, boolean enable) {
+ mode4zyx(switchbox(w), enable?0x02:0x00, 0x07);
+ }
+
+ public boolean drives(SectorWire w) {
+ int connect = (mode4zyx(switchbox(w)) >> (global?3:0)) & 0x7;
+ return (connect & 0x2)!=0;
+ }
+ public SectorWire driverRight() {
+ System.out.println("checking " + Integer.toString(code(true), 16) + " " + Integer.toString(_row(), 16) + " " + Integer.toString(_col(), 16));
+ int ret = mode4(z(code(true)), _row(), _col());
+ ret = (ret >> (global?3:0)) & 0x7;
+ switch(ret) {
+ case 0: return null;
+ case 1: return null; /* global wire on same side */
+ case 2: return new SectorWire(horizontal, plane, horizontal?(col+4):col, horizontal?row:(row+4));
+ case 4: return null; /* global wire on other side */
+ default: throw new Error("multiple drivers on " + this + "!");
+ }
+ }
+ }
+ /*
+ public final class SwitchBox {
+ public final boolean h;
+ public final int col;
+ public final int row;
+ public final int plane;
+ public SwitchBox(boolean h, int col, int row, int plane) { this.h = h; this.col = col; this.row = row; this.plane = plane; }
+ public SectorWire west(boolean global) { return !h ? null : global ? null : new SectorWire(h, col-4, row, plane); }
+ public SectorWire east(boolean global) { return !h ? null : global ? null : new SectorWire(h, col+4, row, plane); }
+ public SectorWire north(boolean global) { return !h ? null : global ? null : new SectorWire(h, col, row-4, plane); }
+ public SectorWire south(boolean global) { return !h ? null : global ? null : new SectorWire(h, col, row+4, plane); }
+ }
+ */
+
+ public Cell cell(int col, int row) {
+ if (col<0) return null;
+ if (row<0) return null;
+ if (col>=getWidth()) return null;
+ if (row>=getHeight()) return null;
+ return new Cell(col, row);
+ }
+
+ public final class Cell {
+ public final int col;
+ public final int row;
+
+ public Cell(int col, int row) {
+ this.row = row;
+ this.col = col;
+ }
+
+ // Accessors for Neighbors //////////////////////////////////////////////////////////////////////////////
+
+ public SectorWire hwire(int plane) { return new SectorWire(true, plane, col, row); }
+ public SectorWire vwire(int plane) { return new SectorWire(false, plane, col, row); }
+ public Cell east() { return cell(col+1, row); }
+ public Cell west() { return cell(col-1, row); }
+ public Cell north() { return cell(col, row+1); }
+ public Cell south() { return cell(col, row-1); }
+ public Cell ne() { return cell(col+1, row+1); }
+ public Cell nw() { return cell(col-1, row+1); }
+ public Cell se() { return cell(col+1, row-1); }
+ public Cell sw() { return cell(col-1, row-1); }
+ public Sector sector() { return new Sector(this); }
+
+ /* bit positions mean: [MSB] zxy z_y zx_ z__ _xy __y _x_ ___ [LSB] */
+ public void lut(int xlut, int ylut) { xlut(xlut); ylut(ylut); }
+ public void xlut(int table) { mode4(7, row, col, (byte)(table & 0xff)); }
+ public byte xlut() { return (byte)(mode4(7, row, col) & 0xff); }
+ public String printXLut() { return printLut(xlut(), "x", "y", "t"); }
+ public String printXLutX() { return printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti_source(), "t")); }
+
+ public String str(int x, String def) {
+ switch(x) {
+ case NORTH: return "n";
+ case SOUTH: return "s";
+ case EAST: return "e";
+ case WEST: return "w";
+ case NW: return "nw";
+ case SE: return "se";
+ case NE: return "ne";
+ case SW: return "sw";
+ case FB: return "fb";
+ case L0: return (hx(0)&&vx(0))?"HV0":hx(0)?"H0":vx(0)?"V0":"L0";
+ case L1: return (hx(1)&&vx(1))?"HV1":hx(1)?"H1":vx(1)?"V1":"L1";
+ case L2: return (hx(2)&&vx(2))?"HV2":hx(2)?"H2":vx(2)?"V2":"L2";
+ case L3: return (hx(3)&&vx(3))?"HV3":hx(3)?"H3":vx(3)?"V3":"L3";
+ case L4: return (hx(4)&&vx(4))?"HV4":hx(4)?"H4":vx(4)?"V4":"L4";
+ default: return def;
+ }
+ }
+
+ /* bit positions mean: [MSB] zxy zx_ z_y z__ _xy _x_ __y ___ [LSB] */
+ public void ylut(int table) { mode4(6, row, col, (byte)(table & 0xff)); }
+ public byte ylut() { return (byte)(mode4(6, row, col) & 0xff); }
+ public String printYLut() { return printLut(ylut(), "y", "x", "t"); }
+ public String printYLutX() { return printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti_source(), "t")) + Integer.toString(ylut() & 0xff, 16); }
+
+ public void ff_reset_value(boolean value) {
+ //mode4( /* FIXME WRONG!!! */, row, col, 3, !value); return;
+ }
+ /** FIXME!!! */
+ public boolean ff_reset_value() { return false; }
+ public boolean columnClocked() {
+ return false;
+ }
+
+ public void out(int plane, boolean enable) {
+ switch(plane) {
+ case L0: mode4(0x00, row, col, 2, enable); return;
+ case L1: mode4(0x00, row, col, 3, enable); return;
+ case L2: mode4(0x00, row, col, 5, enable); return;
+ case L3: mode4(0x00, row, col, 4, enable); return;
+ case L4: mode4(0x00, row, col, 1, enable); return;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public boolean out(int plane) {
+ switch(plane) {
+ case L0: return (mode4(0x00, row, col) & (1<<2)) != 0;
+ case L1: return (mode4(0x00, row, col) & (1<<3)) != 0;
+ case L2: return (mode4(0x00, row, col) & (1<<5)) != 0;
+ case L3: return (mode4(0x00, row, col) & (1<<4)) != 0;
+ case L4: return (mode4(0x00, row, col) & (1<<1)) != 0;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public void h(int plane, boolean enable) {
+ switch(plane) {
+ case 0: mode4(0x08, row, col, 2, enable); return;
+ case 1: mode4(0x08, row, col, 0, enable); return;
+ case 2: mode4(0x08, row, col, 5, enable); return;
+ case 3: mode4(0x08, row, col, 6, enable); return;
+ case 4: mode4(0x00, row, col, 6, enable); return;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public boolean hx(int plane) {
+ switch(plane) {
+ case 0: return (mode4(0x08, row, col) & (1<<2)) != 0;
+ case 1: return (mode4(0x08, row, col) & (1<<0)) != 0;
+ case 2: return (mode4(0x08, row, col) & (1<<5)) != 0;
+ case 3: return (mode4(0x08, row, col) & (1<<6)) != 0;
+ case 4: return (mode4(0x00, row, col) & (1<<6)) != 0;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public void v(int plane, boolean enable) {
+ switch(plane) {
+ case 0: mode4(0x08, row, col, 1, enable); return;
+ case 1: mode4(0x08, row, col, 3, enable); return;
+ case 2: mode4(0x08, row, col, 4, enable); return;
+ case 3: mode4(0x08, row, col, 7, enable); return;
+ case 4: mode4(0x00, row, col, 7, enable); return;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public boolean vx(int plane) {
+ switch(plane) {
+ case 0: return (mode4(0x08, row, col) & (1<<1)) != 0;
+ case 1: return (mode4(0x08, row, col) & (1<<3)) != 0;
+ case 2: return (mode4(0x08, row, col) & (1<<4)) != 0;
+ case 3: return (mode4(0x08, row, col) & (1<<7)) != 0;
+ case 4: return (mode4(0x00, row, col) & (1<<7)) != 0;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+
+ public int ti_source() {
+ switch(mode4(1, row, col) & 0x30) {
+ case 0x20: return zi();
+ case 0x10: return FB;
+ case 0x00: return wi();
+ default: throw new Error("ack!");
+ }
+ }
+
+ public int t() {
+ System.err.println("found " + (mode4(1, row, col) & 0x34));
+ switch(mode4(1, row, col) & 0x34) {
+ case 0x20: return TMUX_Z;
+ case 0x24: return TMUX_W_AND_Z;
+ case 0x34: return TMUX_FB;
+ case 0x14: return TMUX_W_AND_FB;
+ case 0x00: return TMUX_W;
+ //default: throw new RuntimeException("unknown!");
+ default: return TMUX_W;
+ }
+ }
+
+ public void t(int code) {
+ int result = 0;
+ switch(code) {
+ case TMUX_Z: result = 0x20; break; // TOTALLYBOGUS throw new Error("not implemented, but should be possible");
+ case TMUX_W_AND_Z: result = 0x24; break;
+ case TMUX_FB: result = 0x34; break; /* I think this is actually W_AND_FB, sadly */
+ case TMUX_W_AND_FB: result = 0x14; break;
+ case TMUX_W: result = 0x00; break;
+ //default: throw new RuntimeException("unknown code! " + code);
+ default: result = 0x00; break;
+ }
+ mode4(1, row, col, result, 0x34);
+ }
+ /*
+ private void fmux(int source) {
+ switch(source) {
+ case ZMUX:
+ case FB:
+ case ALWAYS_ON:
+ default: throw new Error("unknown argument to fmux()");
+ }
+ }
+
+ public boolean win_easable() {
+ }
+ */
+
+ public int ti() {
+ return mode4(1, row, col) & 0x34;
+ }
+
+ public void t(boolean ignore_z_and_fb, boolean zm_drives_fb, boolean fb_drives_wm) {
+ // still not totally satisfied...
+ // need to find the bit that sets the w-mux off
+ // what does it mean for both bits (0x30) to be set to 1?
+ //if (fb && z) throw new RuntimeException("invalid combination");
+ int result = 0;
+ // ZM->FB = 0x04
+ // FB->WM = 0x10
+ // WZ->WM = 0x20
+
+ // tff => w&z [0x20]
+ // fff => w [0x00]
+ // ttt => fb&w [0x34]
+ // ftt => fb&w [0x14]
+ // fft => fb&w [0x10]
+
+ // ttf => w&z [0x24]
+ // ftf => w [0x04]
+ // tft => fb&w [0x30]
+ if (ignore_z_and_fb) result |= 0x20;
+ if (zm_drives_fb) result |= 0x04;
+ if (fb_drives_wm) result |= 0x10;
+ mode4(1, row, col, result, 0x34);
+ }
+
+
+ public void c(int source) {
+ switch(source) {
+ case XLUT: mode4(1, row, col, 0x00, 0xc0); break;
+ case YLUT: mode4(1, row, col, 0x40, 0xc0); break;
+ case ZMUX: mode4(1, row, col, 0x80, 0xc0); break;
+ default: throw new RuntimeException("Invalid Argument");
+ }
+ }
+ public int c() {
+ int cval = mode4(1, row, col) & 0xc0;
+ switch (cval) {
+ case 0x00: return XLUT;
+ case 0x40: return YLUT;
+ case 0x80: return ZMUX;
+ }
+ throw new Error("c() => " + cval);
+ }
+ public void b(boolean registered) { mode4(1, row, col, 3, !registered); }
+ public void f(boolean registered) { mode4(1, row, col, 2, !registered); }
+ public boolean xo() { return (mode4(1, row, col) & 0x01) != 0; }
+ public boolean yo() { return (mode4(1, row, col) & 0x02) != 0; }
+ public void xo(boolean center) { mode4(1, row, col, 0, center); }
+ public void yo(boolean center) { mode4(1, row, col, 1, center); }
+ public boolean b() { return (mode4(1, row, col) & (1 << 3)) == 0; }
+ public boolean f() { return (mode4(1, row, col) & (1 << 2)) == 0; }
+ public boolean x() { return (mode4(1, row, col) & (1 << 1)) != 0; }
+ public boolean y() { return (mode4(1, row, col) & (1 << 0)) != 0; }
+
+ public int oe() {
+ switch (mode4(0x02, row, col) & 0x3) {
+ case 0: return NONE;
+ case 1: return H4;
+ case 2: return V4;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+ public void oe(int source) {
+ switch(source) {
+ case NONE: mode4(0x02, row, col, 0, 0x3); break;
+ case H4: mode4(0x02, row, col, 1, 0x3); break;
+ case V4: mode4(0x02, row, col, 2, 0x3); break;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public int xi() {
+ // FIXME: can be multiple
+ if ((mode4(0x03, row, col) & (1<<4))!=0) return L4;
+ switch(mode4(0x05, row, col) & 0xff) {
+ case 0x80: return SW;
+ case (1<<6): return NE;
+ case (1<<5): return SE;
+ case (1<<4): return NW;
+ case (1<<3): return L0;
+ case (1<<2): return L1;
+ case (1<<1): return L2;
+ case (1<<0): return L3;
+ case 0: return NONE;
+ default: throw new Error();
+ }
+ }
+
+ public void xi(int source) {
+ switch(source) {
+ case SW: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<7); break;
+ case NE: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<6); break;
+ case SE: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<5); break;
+ case NW: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<4); break;
+ case L4: mode4(0x03, row, col, 4, true); mode4(0x05, row, col, 0); break;
+ case L3: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<0); break;
+ case L2: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<1); break;
+ case L1: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<2); break;
+ case L0: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 1<<3); break;
+ case NONE: mode4(0x03, row, col, 4, false); mode4(0x05, row, col, 0); break;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public int yi() {
+ if ((mode4(0x02, row, col) & (1<<6))!=0) return L4;
+ switch(mode4(0x04, row, col) & 0xff) {
+ case 0x80: return NORTH;
+ case (1<<5): return SOUTH;
+ case (1<<6): return WEST;
+ case (1<<4): return EAST;
+ case (1<<3): return L0;
+ case (1<<2): return L1;
+ case (1<<1): return L2;
+ case (1<<0): return L3;
+ case 0: return NONE;
+ default: throw new Error();
+ }
+ }
+
+ public void yi(int source) {
+ switch(source) {
+ case NORTH: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<7); break;
+ case SOUTH: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<5); break;
+ case WEST: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<6); break;
+ case EAST: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<4); break;
+ case L4: mode4(0x02, row, col, 6, true); mode4(0x04, row, col, 0); break;
+ case L3: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<0); break;
+ case L2: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<1); break;
+ case L1: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<2); break;
+ case L0: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 1<<3); break;
+ case NONE: mode4(0x02, row, col, 6, false); mode4(0x04, row, col, 0); break;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public void wi(int source) {
+ switch(source) {
+ case L4: mode4(0x03, row, col, 1<<5, 0xEC); break;
+ case L3: mode4(0x03, row, col, 1<<6, 0xEC); break;
+ case L2: mode4(0x03, row, col, 1<<7, 0xEC); break;
+ case L1: mode4(0x03, row, col, 1<<3, 0xEC); break;
+ case L0: mode4(0x03, row, col, 1<<2, 0xEC); break;
+ case NONE: mode4(0x03, row, col, 0, 0xEC); break;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public int wi() {
+ int who = mode4(0x03, row, col) & 0xEC;
+ switch(who) {
+ case (1<<5): return L4;
+ case (1<<6): return L3;
+ case (1<<7): return L2;
+ case (1<<3): return L1;
+ case (1<<2): return L0;
+ case (1<<0): return NONE; /* huh? */
+ case (0): return NONE;
+ default: throw new RuntimeException("invalid argument: " + who);
+ }
+ }
+
+
+ public void zi(int source) {
+ switch(source) {
+ case L4: mode4(0x02, row, col, 1<<7, 0xDB); break;
+ case L3: mode4(0x02, row, col, 1<<5, 0xDB); break;
+ case L2: mode4(0x02, row, col, 1<<4, 0xDB); break;
+ case L1: mode4(0x02, row, col, 1<<3, 0xDB); break;
+ case L0: mode4(0x02, row, col, 1<<2, 0xDB); break;
+ case NONE: mode4(0x02, row, col, 0, 0xDB); break;
+ default: throw new RuntimeException("invalid argument");
+ }
+ }
+
+ public int zi() {
+ switch(mode4(0x02, row, col) & 0xDB) {
+ case (1<<7): return L4;
+ case (1<<5): return L3;
+ case (1<<4): return L2;
+ case (1<<3): return L1;
+ case (1<<2): return L0;
+ case (1<<1): return NONE; /* huh? */
+ case (1<<0): return NONE; /* huh? */
+ case 0: return NONE;
+ default: throw new RuntimeException("invalid argument: zi=="+(mode4(0x02, row, col) & 0xDB));
+ }
+ }
+
+
+ // Relevance //////////////////////////////////////////////////////////////////////////////
+
+ public boolean xo_relevant() { return xo_relevant(NE) || xo_relevant(SE) || xo_relevant(NW) || xo_relevant(SW); }
+ public boolean xo_relevant(int direction) {
+ switch(direction) {
+ case NE: return ne() != null && ne().xi()==SW /*&& ne().xi_relevant()*/;
+ case NW: return nw() != null && nw().xi()==SE /*&& nw().xi_relevant()*/;
+ case SE: return se() != null && se().xi()==NW /*&& se().xi_relevant()*/;
+ case SW: return sw() != null && sw().xi()==NE /*&& sw().xi_relevant()*/;
+ default: return false;
+ }
+ }
+ public boolean yo_relevant() { return yo_relevant(NORTH) || yo_relevant(SOUTH) || yo_relevant(EAST) || yo_relevant(WEST); }
+ public boolean yo_relevant(int direction) {
+ switch(direction) {
+ case NORTH: return north() != null && north().yi()==SOUTH /*&& north().yi_relevant()*/;
+ case EAST: return east() != null && east().yi()==WEST /*&& east().yi_relevant()*/;
+ case SOUTH: return south() != null && south().yi()==NORTH /*&& south().yi_relevant()*/;
+ case WEST: return west() != null && west().yi()==EAST /*&& west().yi_relevant()*/;
+ default: return false;
+ }
+ }
+ public boolean xi_relevant() { return xi_to_xlut_relevant() || xi_to_ylut_relevant(); }
+ public boolean yi_relevant() { return yi_to_xlut_relevant() || yi_to_ylut_relevant(); }
+ public boolean xi_to_ylut_relevant() { return (((ylut() & 0xcc) >> 2) != (ylut() & 0x33)); }
+ public boolean yi_to_xlut_relevant() { return (((xlut() & 0xcc) >> 2) != (xlut() & 0x33)); }
+ public boolean zi_to_xlut_relevant() { return (((xlut() & LUT_Z) >> 4) != (xlut() & LUT_Z)); }
+ public boolean zi_to_ylut_relevant() { return (((ylut() & LUT_Z) >> 4) != (ylut() & LUT_Z)); }
+ public boolean xi_to_xlut_relevant() { return (((xlut() & LUT_SELF) >> 1) != (xlut() & (LUT_SELF >> 1))); }
+ public boolean yi_to_ylut_relevant() { return (((ylut() & LUT_SELF) >> 1) != (ylut() & (LUT_SELF >> 1))); }
+ public boolean xlut_relevant() {
+ if ((c()==XLUT || c()==ZMUX) && c_relevant()) return true;
+ if (xo()) return false;
+ return xo_relevant();
+ }
+ public boolean ylut_relevant() {
+ if ((c()==YLUT || c()==ZMUX) && c_relevant()) return true;
+ if (yo()) return false;
+ return yo_relevant();
+ }
+ public boolean c_relevant() {
+ switch(ti()) {
+ case 0x34: return true;
+ case 0x14: return true;
+ case 0x10: return true;
+ case 0x30: return true;
+ }
+ for(int i=0; i<5; i++)
+ if (out(i))
+ return true;
+ if (xo() || yo()) return true;
+ return false;
+ }
+
+ public boolean register_relevant() {
+ if (!c_relevant()) return false;
+ if (f() && out_relevant()) return true;
+ if (f() && fb_relevant()) return true;
+ if (b() && xo()) return true;
+ if (b() && yo()) return true;
+ return false;
+ }
+ public boolean out_relevant() {
+ boolean out = false;
+ boolean connect = false;
+ for(int i=0; i<4; i++) {
+ if (out(L0+i)) out = true;
+ if (hx(L0+i)) connect = true;
+ if (vx(L0+i)) connect = true;
+ }
+ return out && connect;
+ }
+ public boolean fb_relevant() {
+ if (!(zi_to_xlut_relevant()) ||
+ !(zi_to_ylut_relevant())) return false;
+ switch(ti()) {
+ case 0x34: return true;
+ case 0x14: return true;
+ case 0x10: return true;
+ case 0x30: return true;
+ }
+ return false;
+ }
+
+
+ }
+
+ public IOB iob_bot(int col, boolean primary) { return new IOB(col, 0, primary, true); }
+ public IOB iob_top(int col, boolean primary) { return new IOB(col, 1, primary, true); }
+ public IOB iob_left(int row, boolean primary) { return new IOB(0, row, primary, false); }
+ public IOB iob_right(int row, boolean primary) { return new IOB(1, row, primary, false); }
+ /*
+ public IOB fromPin(int pin) {
+ if (pin >= 4 && pin <= 11) return io(pin-3);
+ if (pin >= 15 && pin <= 18) return io(pin-2);
+ if (pin >= 19 && pin <= 24) return io(pin);
+ if (pin >= 27 && pin <= 30) return io(pin-2);
+ if (pin >= 33 && pin <= 36) return io(pin);
+ if (pin >= 38 && pin <= 47) return io(pin+1);
+
+
+ if (pin >= 33 && pin <= 36) return io(pin+36);
+ if (pin >= 38 && pin <= 41) return io(pin+43);
+ if (pin >= 42 && pin <= 43) return io(pin+47);
+ if (pin >= 44 && pin <= 47) return io(pin+49);
+ if (pin >= 57 && pin <= 62) return io(pin+40);
+ if (pin >= 63 && pin <= 66) return io(pin+46);
+ if (pin >= 68 && pin <= 71) return io(pin+53);
+ if (pin >= 72 && pin <= 73) return io(pin+53);
+ if (pin >= 74 && pin <= 75) return io(pin+63);
+ if (pin >= 76 && pin <= 77) return io(143+(pin-76));
+ if (pin >= 80 && pin <= 81) return io(145+(pin-80));
+ if (pin >= 82 && pin <= 85) return io(151+(pin-82));
+ if (pin >= 86 && pin <= 89) return io(165+(pin-86));
+ if (pin >= 91 && pin <= 94) return io(177+(pin-91));
+ if (pin >= 95 && pin <= 96) return io(183+(pin-95));
+ if (pin >= 97 && pin <= 100) return io(189+(pin-97));
+ if (pin >= 161 && pin <= 164) return io(289+(pin-161));
+ if (pin >= 165 && pin <= 166) return io(297+(pin-165));
+ if (pin >= 167 && pin <= 168) return io(303+(pin-167));
+ if (pin >= 169 && pin <= 170) return io(309+(pin-169));
+ if (pin >= 172 && pin <= 173) return io(313+(pin-172));
+ if (pin >= 174 && pin <= 175) return io(325+(pin-174));
+ if (pin >= 176 && pin <= 179) return io(327+(pin-176));
+ if (pin >= 180 && pin <= 181) return io(335+(pin-180));
+ if (pin >= 184 && pin <= 185) return io(337+(pin-184));
+ if (pin >= 186 && pin <= 191) return io(343+(pin-186));
+ if (pin >= 192 && pin <= 193) return io(359+(pin-192));
+ if (pin >= 195 && pin <= 196) return io(363+(pin-195));
+ if (pin >= 197 && pin <= 200) return io(369+(pin-197));
+ if (pin >= 201 && pin <= 204) return io(381+(pin-201));
+ }
+ public io(int ionum) {
+ if (ionum <= 94) {
+ int cell = (94 - pin) / 2;
+ boolean primary = cell * 2 == (94-pin);
+ }
+ }
+ */
+ public final class IOB {
+ public final int col;
+ public final int row;
+ public final boolean primary;
+ public final boolean northsouth;
+ public IOB(int col, int row, boolean primary, boolean northsouth) {
+ this.col = col;
+ this.row = row;
+ this.northsouth = northsouth;
+ this.primary = primary;
+ }
+ /*
+ public String dump() {
+ System.out.println("[ "+
+ (schmitt()?"schmitt ":"")+
+ (slew()==3?"fast ":slew()==2?"med ":slew()==1?"slow ":"slew-unknown ")+
+ (cr()?"cr ":"")+
+ (reg()?"reg ":"")+
+
+ }
+ */
+ public void enableOutput(int direction) {
+ useoem(true);
+ output(direction);
+ pullnone();
+ useoem(true);
+ oem(ALWAYS_ON);
+ oe(true);
+ // note: east-side IOBs should have slew=med, others slew=fast
+ slew((!northsouth && col==1) ? MEDIUM : FAST);
+ }
+ public void enableInput() {
+ schmitt(true);
+ pullnone();
+ }
+
+ public void useoem(boolean use) { mode4(z(3), row, col, 6, use); }
+ public boolean useoem() { return (mode4(z(3), row, col) & (1<<6))!=0; }
+ public void schmitt(boolean use) { mode4(z(0), row, col, 7, use); }
+ public boolean schmitt() { return (mode4(z(0), row, col) & (1<<7))!=0; }
+
+ public void slew(int slew) {
+ switch(slew) {
+ case FAST: mode4(z(0), row, col, 3<<5, 0x60); return;
+ case MEDIUM: mode4(z(0), row, col, 2<<5, 0x60); return;
+ case SLOW: mode4(z(0), row, col, 1<<5, 0x60); return;
+ default: throw new Error();
+ }
+ }
+
+ public void oem(int source) {
+ switch(source) {
+ case ALWAYS_ON: mode4(z(3), row, col, 1<<5, 0x3f); return;
+ case ALWAYS_OFF: mode4(z(3), row, col, 0, 0x3f); return;
+ default: throw new Error();
+ }
+ }
+
+ private int z(int code) { return (northsouth ? 0x70 : 0x60) | (primary ? 0x00 : 0x04) | (code & 0x7); }
+ public void pullup() { mode4(z(0), row, col, 0x00<<1, 0x06); }
+ public void pulldown() { mode4(z(0), row, col, 0x03<<1, 0x06); }
+ public void pullnone() { mode4(z(0), row, col, 0x01<<1, 0x06); }
+ public void oe(boolean oe) {
+ int old = mode4(z(1), row, col) & (~(1<<5));
+ old |= oe ? 0 : (1<<5);
+ mode4(z(1), row, col, old & 0xff);
+ }
+
+ public void output(int which) {
+ switch(which) {
+ case NONE:
+ mode4(z(1), row, col, 0, 0x1f); return;
+ case WEST: case EAST: case NORTH: case SOUTH:
+ mode4(z(1), row, col, 1<<0, 0x1f); return;
+ case NW: case SW: case NE: case SE:
+ mode4(z(1), row, col, 1<<1, 0x1f); return;
+ default: throw new Error();
+ }
+ }
+
+ }
+
+ public static void main(String[] s) throws Exception {
+ System.out.println(printLut(0x39, "se", "n", "L0"));
+ }
+ public static synchronized String printLut(int lut, String xn, String yn, String zn) {
+ try {
+ File f = File.createTempFile("mvsis", ".mvs");
+ f.deleteOnExit();
+
+ FileOutputStream fos = new FileOutputStream(f);
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
+ pw.println(".model clb");
+ pw.println(".inputs "+xn+" "+yn+" "+zn);
+ pw.println(".outputs O");
+ pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
+ for(int i=8; i>=0; i--) {
+ int x = ((i & 0x01)!=0 ? 1 : 0);
+ int y = ((i & 0x02)!=0 ? 1 : 0);
+ int z = ((i & 0x04)!=0 ? 1 : 0);
+ pw.print(" "+x+" ");
+ pw.print(" "+y+" ");
+ pw.print(" "+z+" ");
+ //pw.print(" "+(x ^ y)+" ");
+ //pw.print(" "+(y ^ z)+" ");
+ //pw.print(" "+(z ^ y)+" ");
+ pw.print((lut & (1<<i))==0 ? 0 : 1);
+ pw.println();
+ }
+ pw.println(".end");
+ pw.flush();
+ pw.close();
+ Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
+ new Gobble("mvsis: ", p.getErrorStream()).start();
+ //new Gobble("mvsis: ", p.getInputStream()).start();
+ BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String ret = br.readLine();
+ //f.delete();
+ return ret.trim();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "*mvsis_error*";
+ }
+ }
+
+ public static class Gobble extends Thread {
+ private final String header;
+ private final BufferedReader br;
+ public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
+ public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
+ public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
+ public void run() {
+ try {
+ for(String s = br.readLine(); s!=null; s=br.readLine())
+ System.err.println(header + s);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
}
--- /dev/null
+package com.atmel.fpslic;
+
+public class FpslicConstants {
+ public static final int NONE = -1;
+ public static final int L0 = 0;
+ public static final int L1 = 1;
+ public static final int L2 = 2;
+ public static final int L3 = 3;
+ public static final int L4 = 4;
+
+ public static final int NORTH = 8;
+ public static final int WEST = 9;
+ public static final int SOUTH = 10;
+ public static final int EAST = 11;
+
+ public static final int XLUT = 12;
+ public static final int YLUT = 13;
+ public static final int ZMUX = 14;
+
+ public static final int H4 = 15;
+ public static final int V4 = 16;
+
+ public static final int NW = 20;
+ public static final int SW = 21;
+ public static final int NE = 22;
+ public static final int SE = 23;
+
+ public static final int SLOW = 24;
+ public static final int MEDIUM = 25;
+ public static final int FAST = 26;
+
+ public static final int ALWAYS_ON = 27;
+ public static final int ALWAYS_OFF = 28;
+
+ public static final int FB = 29;
+
+ public static final int LUT_SELF = 0xAA;
+ public static final int LUT_Z = 0xF0;
+ public static final int LUT_OTHER = 0xCC;
+
+ public static final int TMUX_W_AND_Z = 0x00001001;
+ public static final int TMUX_W = 0x00001002;
+ public static final int TMUX_Z = 0x00001004;
+ public static final int TMUX_W_AND_FB = 0x00001008;
+ public static final int TMUX_FB = 0x00001010;
+
+
+}
+++ /dev/null
-package edu.berkeley.obits;
-import java.util.*;
-import java.io.*;
-import org.ibex.util.*;
-
-public class Atmel {
-
- public static String pad(int len, String s) { if (s.length() >= len) return s.toUpperCase(); return "0"+pad(len-1,s); }
- public static String hex32(int i) { return pad(8, Long.toString(i & 0xffffffffffffffffL, 16)); }
- public static String hex24(int i) { return pad(6, Integer.toString((i & 0xffffff), 16)); }
- public static String hex8(int i) { return pad(2, Integer.toString((i & 0xff), 16)); }
- public static String bin8(int i) { return pad(8, Integer.toString((i & 0xff), 2)); }
- public static String dec2(int i) { return pad(2, Integer.toString(i & 0xff)); }
-
- public static void main(String[] s) throws Exception {
- Log.level = Log.DEBUG;
- new Bits().read(System.in);
- }
-
- private static class Bits {
- private byte[] bits = new byte[0];
- //public int get(int whichByte, int whichBit, int len) { }
- //public void set(int whichByte, int whichBit, int len, int val) { }
-
- private int control = 0;
- public int control() { return control; }
- public void control(int control) { this.control = control; }
-
- public void read2(InputStream bitstream) throws IOException {
- DataInputStream dis = new DataInputStream(new Encode.Ascii.In(16, bitstream));
- try {
- while(true) {
- dis.readUnsignedByte();
- dis.readUnsignedByte();
- dis.readUnsignedByte();
- int i = dis.readUnsignedByte();
- System.out.println(bin8(i));
- }
- } catch (EOFException e) {
- }
- }
- public void read(InputStream bitstream) throws IOException {
- DataInputStream dis = new DataInputStream(new Encode.Ascii.In(2, bitstream));
- int b = dis.readUnsignedByte();
- if (b != 0x00) throw new Error("bitstream did not start with zero-byte; got " + b);
- Log.debug(this, "saw leading zero-byte");
- b = dis.readUnsignedByte();
- if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + b);
- Log.debug(this, "saw preamble byte");
- control(dis.readInt());
- Log.debug(this, "set control register to " + hex32(control()));
- int numWindows = dis.readShort();
- Log.debug(this, "this bitstream has " + numWindows + " window(s)");
- int count = 0;
- for(int i=0; i<numWindows; i++) {
- int start = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
- int end = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
- count = 0;
- Log.debug(this, " window " + dec2(i) + " spans addresses " + hex24(start) + " - " + hex24(end) + "[count="+count+"]");
- int _z = (start & 0x0000ff) >> 0;
- int _y = (start & 0x00ff00) >> 8;
- int _x = (start & 0xff0000) >> 16;
- int z_ = (end & 0x0000ff) >> 0;
- int y_ = (end & 0x00ff00) >> 8;
- int x_ = (end & 0xff0000) >> 16;
- int z = (start & 0x0000ff) >> 0;
- int y = (start & 0x00ff00) >> 8;
- int x = (start & 0xff0000) >> 16;
-
- while(true) {
- count++;
- mode4(x, y, z, dis.readUnsignedByte());
- x++;
- if (x > 15) { x = 0; y++; }
- if (y > 15) { y = 0; z++; }
- do {
- z++;
- if (z > 77) {
- z = _z;
- x++;
- if (x > 15) {
- x = _x;
- y++;
- if (y > y_) break;
- }
- }
- } while(!valid(x,y,z));
- }
- //Log.debug(this, " read " + count + " bytes (" + hex24(count)+")");
- }
- /*
- Log.debug(this, "done " + count);
- b = dis.readUnsignedByte();
- if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + bin8(b));
- Log.debug(this, "done2");
- */
- }
-
- public boolean valid(int x, int y, int z) {
- switch(z) {
- case 0x00: case 0x01: break;
- }
- if (x > 15) return false;
- if (y > 15) return false;
- return true;
- }
-
- public void mode4(int x, int y, int z, int d) {
- //Log.debug(this, " ("+dec2(x)+","+dec2(y)+"):"+hex8(z)+" = "+bin8(d));
- //System.out.println(hex8(z)+hex8(y)+hex8(x)+hex8(d));
- }
- }
-}
- /*
- public static class At40k extends FPGA {
-
-
- public At40k(int width, int height) { this.width = width; this.height = height; }
-
- public static class At40k10 extends At40k { public At40k10() { super(24, 24); } }
-
- 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 Cell cell(int col, int row) { return new Cell(col, row); }
- public final class Cell {
- public final int col;
- public final int row;
- public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); }
- public Cell(int col, int row) {
- this.row = row;
- this.col = col;
- }
- }
-
- public class Sector {
- Cell[][] = new Cell[4][4];
- Ram ram = new Ram();
-
- Buf[] west = new Buf[4];
- Buf[] east = new Buf[4];
- Buf[] north = new Buf[4];
- Buf[] south = new Buf[4];
- Pip pass = new Pip[4][4][5][2];
- }
-
-
- public class Cell {
-
- public final Port[] h = new Port[5] { port(), port(), port(), port(), port() };
- public final Port[] v = new Port[5] { port(), port(), port(), port(), port() };
- public final Port[] s = new Port[5] { port(), port(), port(), port(), port() };
- public final Port nw, sw, se, ne;
- public final Port n, s, w, e;
- public final Port xout, yout;
-
- public final Pip zin = pip( s[0], s[1], s[2], s[3], s[4]);
- public final Pip win = pip( s[0], s[1], s[2], s[3], s[4]);
- public final Pip xin = pip(nw, ne, sw, se, s[0], s[1], s[2], s[3], s[4]);
- public final Pip yin = pip(n, s, e, w, s[0], s[1], s[2], s[3], s[4]);
-
- public final Pip wpip = pip(win, zin, and(win, zin), fb);
- public final Pip zpip = pip(zin, one, zero);
-
- public final Lut xlut = lut(xpip, wmux, ypip);
- public final Lut ylut = lut(xpip, wmux, ypip);
- public final Mux zmux = mux(xlut, ylut, zpip);
- public final Reg reg = reg(zmux);
- public final Pip center = pip(reg, zmux);
-
- public final Pip fb = pip(zmux, reg);
-
- public final Pip center = pip(zmux, reg);
- public final Pip xout = pip(xlut, center);
- public final Pip yout = pip(ylut, center);
-
- public final Pip oe = pip(one, h[4], v[4]);
- public final Buf out = buf(fb, oe);
-
- public final Pip[] o = pip5(out, s);
- public final Pip[] h = pip5(h, s);
- public final Pip[] v = pip5(v, s);
- }
-
-
- }
-
-
- public class At94k extends At40k {
- }
- */
-
package edu.berkeley.obits;
import edu.berkeley.slipway.*;
+import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
import static com.atmel.fpslic.Fpslic.Util.*;
import edu.berkeley.obits.device.atmel.*;
}
public static int PIPELEN=20;
public static void main(String[] s) throws Exception {
- //AvrDrone device = new AvrDrone(detectObitsPort());
- //AvrDrone device = new AvrDrone();
- AvrDrone device = new AvrDrone(new FtdiBoard());
- At40k at40k = new At40k.At40k10(device);
+ FtdiBoard device = new FtdiBoard();
+ Fpslic at40k = device;
try {
long begin = System.currentTimeMillis();
device.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740));
/*
System.out.println("a: " + at40k.new SectorWire(true, 0, 4, 0x17).driverRight());
System.out.println("b: " + at40k.new SectorWire(true, 1, 4, 0x17).driverRight());
- At40k.SectorWire h0p0 = at40k.new SectorWire(true, 0, 0, 0x17);
- At40k.SectorWire h0p1 = at40k.new SectorWire(true, 1, 0, 0x17);
- At40k.SectorWire h0p2 = at40k.new SectorWire(true, 2, 0, 0x17);
- At40k.SectorWire h4p0 = at40k.new SectorWire(true, 0, 4, 0x17);
- At40k.SectorWire h4p1 = at40k.new SectorWire(true, 1, 4, 0x17);
- At40k.SectorWire h4p2 = at40k.new SectorWire(true, 2, 4, 0x17);
+ Fpslic.SectorWire h0p0 = at40k.new SectorWire(true, 0, 0, 0x17);
+ Fpslic.SectorWire h0p1 = at40k.new SectorWire(true, 1, 0, 0x17);
+ Fpslic.SectorWire h0p2 = at40k.new SectorWire(true, 2, 0, 0x17);
+ Fpslic.SectorWire h4p0 = at40k.new SectorWire(true, 0, 4, 0x17);
+ Fpslic.SectorWire h4p1 = at40k.new SectorWire(true, 1, 4, 0x17);
+ Fpslic.SectorWire h4p2 = at40k.new SectorWire(true, 2, 4, 0x17);
//h4p1.drives(h0p1, false);
//at40k.cell(0x04, 0x17).out(L1, false);
/*
System.out.println("xlut is " + hex(at40k.cell(0x04, 0x17).xlut()));
System.out.println("ylut is " + hex(at40k.cell(0x04, 0x17).ylut()));
- At40k.Cell cell = at40k.cell(0x04, 0x17);
+ Fpslic.Cell cell = at40k.cell(0x04, 0x17);
//cell.xlut(0xff);
//cell.f(false);
System.out.println(cell.c());
at40k.iob_right(15, true).enableOutput(WEST);
- At40k.Cell c = at40k.cell(10,10);
+ Fpslic.Cell c = at40k.cell(10,10);
c.ylut(~LUT_SELF);
c.xlut(LUT_Z);
c.yi(WEST);
//at40k.cell(6,22).ylut(0xff);
//at40k.cell(22,11).ylut(0xff);
/*
- At40k.Cell cell = at40k.cell(4, 16);
+ Fpslic.Cell cell = at40k.cell(4, 16);
cell.xlut(0xff);
cell.ylut(0xff);
cell.b(false);
Visualizer v = new Visualizer(at40k, device);
v.show();
v.setSize(1380, 1080);
- At40k.Cell cell = at40k.cell(4, 23);
+ Fpslic.Cell cell = at40k.cell(4, 23);
Image img = v.createImage(v.getWidth(), v.getHeight());
/*
//int y = 11;
//selfTest(device, at40k, v);
- System.out.println("save: " + AvrDrone.save + " of " + (AvrDrone.saveof*5));
+ System.out.println("save: " + FtdiBoard.save + " of " + (FtdiBoard.saveof*5));
at40k.iob_top(0, true).enableInput();
copy(at40k.cell(0, 23), NORTH, NORTH);
} catch (Exception e) { e.printStackTrace(); }
}
- public static void scan(At40k dev, At40k.Cell cell, int source, boolean setup) {
+ public static void scan(Fpslic dev, Fpslic.Cell cell, int source, boolean setup) {
if (setup) {
if (source != NONE) cell.c(source);
if (cell.b()) cell.b(false);
if (cell.out(L3)!=setup) cell.out(L3, setup);
if (cell.vx(L3)!=setup) cell.v(L3, setup);
- At40k.SectorWire sw = cell.vwire(L3);
+ Fpslic.SectorWire sw = cell.vwire(L3);
//System.out.println("wire is: " + sw);
if (sw.row > (12 & ~0x3) && sw.north()!=null && sw.north().drives(sw))
}
- public static void copy(At40k.Cell c, int xdir, int ydir) {
+ public static void copy(Fpslic.Cell c, int xdir, int ydir) {
switch(xdir) {
case NW: case NE: case SW: case SE: {
c.xi(xdir);
return Long.toString(x & 0xffffffffL, 16);
}
- public static void handshaker(At40k.Cell cell) {
+ public static void handshaker(Fpslic.Cell cell) {
cell.xlut(0x22);
cell.ylut(0x71);
cell.c(XLUT);
public static final int LH = 15;
public static final Color RED = new Color(0xaa, 0x55, 0x55);
public static final Color BLUE = new Color(0x55, 0x55, 0xaa);
- private final At40k dev;
- private final AvrDrone drone;
+ private final Fpslic dev;
+ private final FtdiBoard drone;
int selx = -1;
int sely = -1;
- public Visualizer(final At40k dev, final AvrDrone drone) {
+ public Visualizer(final Fpslic dev, final FtdiBoard drone) {
this.dev = dev;
this.drone = drone;
show();
Thread.sleep(500);
if (!enabled) continue;
/*
- At40k.Cell cell = dev.cell(21, 22);
+ Fpslic.Cell cell = dev.cell(21, 22);
cell.xlut(0xff);
cell.ylut(0xff);
*/
switch(keyevent==null ? '_' : keyevent.getKeyChar()) {
case '1': {
if (selx==-1 || sely==-1) break;
- At40k.Cell cell = dev.cell(selx, sely);
+ Fpslic.Cell cell = dev.cell(selx, sely);
cell.xlut(0xff);
cell.ylut(0xff);
drawCell(getGraphics(), selx, sely);
*/
copy(dev.cell(mx, yofs-1), NORTH, SW);
boolean left = true;
- At40k.Cell lc = null;
+ Fpslic.Cell lc = null;
for(int k=0; k<10; k++) {
int y = yofs-2-(k*2);
copy(dev.cell(left?(mx-1):mx, y), SOUTH, left?NE:NW);
}
case 'C': {
if (selx==-1 || sely==-1) break;
- At40k.Cell cell = dev.cell(selx, sely);
+ Fpslic.Cell cell = dev.cell(selx, sely);
cell.ylut(0xB2);
drawCell(getGraphics(), selx, sely);
break;
}
case '0': {
if (selx==-1 || sely==-1) break;
- At40k.Cell cell = dev.cell(selx, sely);
+ Fpslic.Cell cell = dev.cell(selx, sely);
cell.xlut(0x00);
cell.ylut(0x00);
drawCell(getGraphics(), selx, sely);
showit(dev, drone, this);
}
public void mousePressed(MouseEvent e) {
- final At40k.Cell cell = dev.cell(selx, sely);
+ final Fpslic.Cell cell = dev.cell(selx, sely);
if (cell==null) return;
final int old = cell.c();
- AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
+ FtdiBoard.ByteCallback bc = new FtdiBoard.ByteCallback() {
public void call(byte b) throws Exception {
boolean y = (b & 0x80) != 0;
//cell.c(old);
if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
int cx = selx;
int cy = sely;
- At40k.Cell cell = dev.cell(cx, cy);
+ Fpslic.Cell cell = dev.cell(cx, cy);
selx = -1;
sely = -1;
/*
selx = (x-20)/(WIDTH+2);
sely = (23 - (y-20)/(HEIGHT+2))+1;
/*
- At40k.Cell cell = dev.cell(selx, sely);
+ Fpslic.Cell cell = dev.cell(selx, sely);
if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) {
drawCell(getGraphics(), selx, sely);
drawSector(getGraphics(), dev.cell(selx, sely).sector());
}
*/
}
- public static int left(At40k.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
- public static int top(At40k.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
- public void drawSector(Graphics g, At40k.Sector sector) {
+ public static int left(Fpslic.Cell cell) { return (cell.col) *(WIDTH+2)+20; }
+ public static int top(Fpslic.Cell cell) { return (23-cell.row)*(HEIGHT+2)+60; }
+ public void drawSector(Graphics g, Fpslic.Sector sector) {
g.setColor(Color.gray);
((Graphics2D)g).setStroke(new BasicStroke(1));
int px = ((sector.col)*(WIDTH+2))+20-1;
boolean h = dir==0;
for(int y=h?sector.row:sector.col; y<(h?sector.row+4:sector.col+4); y++)
for(int plane=0; plane<=4; plane++) {
- At40k.Cell cell = h ? dev.cell(sector.col, y) : dev.cell(y, sector.row);
- At40k.Cell cell_east = h ? dev.cell(sector.col-1, y) : dev.cell(y, sector.row-1);
- At40k.Cell cell_west = h ? dev.cell(sector.col+4, y) : dev.cell(y, sector.row+4);
+ Fpslic.Cell cell = h ? dev.cell(sector.col, y) : dev.cell(y, sector.row);
+ Fpslic.Cell cell_east = h ? dev.cell(sector.col-1, y) : dev.cell(y, sector.row-1);
+ Fpslic.Cell cell_west = h ? dev.cell(sector.col+4, y) : dev.cell(y, sector.row+4);
boolean draw = false;
if (h) {
if (cell_east!=null &&
int y = ((23-cy)*(HEIGHT+2))+60;
//System.out.println("drawcell " + cx + "," + cy);
- At40k.Cell cell = dev.cell(cx, cy);
+ Fpslic.Cell cell = dev.cell(cx, cy);
g.setColor(bg);
g.fillRect(x, y, WIDTH, HEIGHT);
return ret;
}
- public static void selfTest(AvrDrone device, At40k at40k, Visualizer v) {
+ public static void selfTest(FtdiBoard device, Fpslic at40k, Visualizer v) {
/*
int fail = 0;
long now = System.currentTimeMillis();
for(int x=0; x<24; x++)
for(int y=0; y<24; y++) {
- At40k.Cell cell = at40k.cell(x,y);
+ Fpslic.Cell cell = at40k.cell(x,y);
scan(at40k, cell, YLUT, true);
//v.paint(img.getGraphics());
//v.getGraphics().drawImage(img, 0, 0, null);
*/
}
- public static void bounce(At40k.Cell cell, int xi, int yi) {
+ public static void bounce(Fpslic.Cell cell, int xi, int yi) {
cell.xlut((byte)0xCC);
cell.ylut((byte)0xCC);
cell.xi(xi);
cell.xo(false);
cell.yo(false);
}
- public static void muller(At40k.Cell cell, int xi, int yi) {
+ public static void muller(Fpslic.Cell cell, int xi, int yi) {
cell.ylut(0xB2);
cell.c(YLUT);
cell.f(false);
}
/** watches for a rising/falling edge on Yin, emits a pulse on Xout */
- public static void pulse_detect(At40k.Cell c, int in, boolean falling) {
+ public static void pulse_detect(Fpslic.Cell c, int in, boolean falling) {
c.ylut(0x00);
c.xlut(0x00);
switch(in) {
}
/** watches for a pulse on Xin, copies value of Yin */
- public static void pulse_copy(At40k.Cell cell, int xi, int yi, boolean invert) {
+ public static void pulse_copy(Fpslic.Cell cell, int xi, int yi, boolean invert) {
loopback(cell, YLUT);
if (!invert) cell.ylut(0xB8); /* yo = x ? yi : z => 1011 1000 */
else cell.ylut(0x74); /* yo = x ? !yi : z => 0111 0100 */
cell.yi(yi);
}
- public static void loopback(At40k.Cell cell, int cin) {
+ public static void loopback(Fpslic.Cell cell, int cin) {
cell.f(false);
cell.b(false);
cell.t(false, false, true);
cell.xo(false);
cell.c(cin);
}
- public static void doit(At40k at40k, AvrDrone device) throws Exception {
+ public static void doit(Fpslic at40k, FtdiBoard device) throws Exception {
- At40k.Cell led = at40k.cell(1, 23);
+ Fpslic.Cell led = at40k.cell(1, 23);
led.v(L2, true);
led.h(L2, false);
led.yi(L2);
led.xlut(LUT_SELF);
led.yo(false);
- At40k.Cell c = at40k.cell(1, 22);
+ Fpslic.Cell c = at40k.cell(1, 22);
c.out(L1, true);
c.out(L0, true);
c.oe(V4);
c.c(YLUT);
for(int i=0; i<4; i++) at40k.cell(i, 20).h(L0, false);
- At40k.Cell z = at40k.cell(1, 20);
+ Fpslic.Cell z = at40k.cell(1, 20);
z.out(L0, true);
z.xlut(0xff);
z.c(XLUT);
}
public static int yofs = mullers ? 19 : 22;
- public static void counter(At40k at40k, AvrDrone device) throws Exception {
+ public static void counter(Fpslic at40k, FtdiBoard device) throws Exception {
// watch for rising edge from south, emit pulse on Xout (to NE)
//copy(at40k.cell(16,23), SW, WEST);
//at40k.iob_top(1, false).slew(SLOW);
}
- public static void fill(At40k at40k, AvrDrone device, int num) throws Exception {
+ public static void fill(Fpslic at40k, FtdiBoard device, int num) throws Exception {
//muller(at40k.cell(PIPELEN,22), NE, WEST);
- At40k.Cell a = at40k.cell(10,22);
- At40k.Cell b = at40k.cell(11,22);
+ Fpslic.Cell a = at40k.cell(10,22);
+ Fpslic.Cell b = at40k.cell(11,22);
a.ylut(0x00);
for(int i=0; i<num; i++) {
//System.out.println(i);
b.ylut(0xB2);
a.ylut(0xB2);
}
- public static void showit(At40k dev, AvrDrone drone, final Visualizer vis) {
+ public static void showit(Fpslic dev, FtdiBoard drone, final Visualizer vis) {
final long then = System.currentTimeMillis();
final Graphics g = vis.getGraphics();
g.setFont(new Font("sansserif", Font.BOLD, 24));
//for(int yy=21; yy<=22; yy++) {
final int x = xx;
final int y = yy;
- final At40k.Cell cell = dev.cell(x, y);
+ final Fpslic.Cell cell = dev.cell(x, y);
if ((cell.ylut()&0xff)!=0xB2) continue;
- AvrDrone.ByteCallback bc = new AvrDrone.ByteCallback() {
+ FtdiBoard.ByteCallback bc = new FtdiBoard.ByteCallback() {
public void call(byte b) throws Exception {
boolean v = (b & 0x80) != 0;
vis.drawCell(g, x, y, v?red:green);
}
}
}
- public static void drain(At40k at40k, AvrDrone device) throws Exception {
- At40k.Cell a = at40k.cell(10,22);
- At40k.Cell b = at40k.cell(11,22);
+ public static void drain(Fpslic at40k, FtdiBoard device) throws Exception {
+ Fpslic.Cell a = at40k.cell(10,22);
+ Fpslic.Cell b = at40k.cell(11,22);
a.lut(0x00, 0x00);
b.lut(0x00, 0x00);
for(int i=0; i<30; i++) {
b.ylut(0xB2);
a.ylut(0xB2);
}
- public static void doitx(At40k at40k, AvrDrone device) throws Exception {
+ public static void doitx(Fpslic at40k, FtdiBoard device) throws Exception {
for(int i=5; i<PIPELEN+1; i++) bounce(at40k.cell(i, 23), SE, SOUTH);
for(int x=5; x<PIPELEN; x++) muller(at40k.cell(x, 22), x==PIPELEN-1 ? SE : NE, WEST);
+++ /dev/null
-package edu.berkeley.obits;
-
-public abstract class Bits {
- /*
- public abstract boolean get(long bit);
- public abstract void set(long bit, boolean val);
-
- public int get(long bit, int len) {
- int ret = 0;
- for(long i=bit; i<bit+len; i++) ret = (ret << 1) | get(i);
- return ret;
- }
- public void set(long bit, int len, int val) {
- for(long i=bit+len-1; i>=bit; i--) {
- set(i, (val & 1) != 0);
- val >>= 1;
- }
- }
-
- public final boolean get(int offset, int bit) { return get(offset*8 + bit); }
- public final int get(int offset, int bit, int len) { return get(offset*8 + bit, num); }
- public final void set(int offset, int bit, boolean b) { set(offset*8 + bit, b); }
- public final void set(int offset, int bit, int len, int val) { set(offset*8 + bit, num, val); }
-
- public static class Offset extends Bits {
- private final Bits bits;
- private final long off;
-
- public Offset(Bits bits, long offset) { this.off = offset; this.bits = bits; }
- public Offset(Bits bits, int offset, int bit) { this(bits, offset*8+bit); }
-
- public boolean get(long bit) { return bits.get(bit+off); }
- public int get(long bit, int len) { return bits.get(bit+off, len); }
- public void set(long bit, boolean val) { bits.set(bit+off, val); }
- public void set(long bit, int len, int val) { bits.set(bit+off, len, val); }
- }
-
- public static class Arr extends Bits {
- private byte[] bits;
- public Bits(int capacity) { this.bits = new byte[(capacity / 8) + (capacity%8 == 0 ? 0 : 1)]; }
-
- public boolean get(long bit) {
- if (bit / 8 >= bits.length) return false;
- int ret = bits[bit/8];
- ret >> 8-(bit-((bit/8)*8));
- return (ret & 1) != 0;
- }
-
- public void set(long bit, boolean b) {
- if (bit / 8 >= bits.length) {
- if (!b) return;
- byte[] bits2 = new byte[Math.max((bit/8)+1, (bits.length * 2))];
- System.arraycopy(bits, 0, bits2, 0, bits.length);
- bits = bits2;
- set(bit, b);
- return;
- }
- byte mask = (byte)(1 << (8-(bit-((bit/8)*8))));
- if (b) {
- bits[bit/8] |= mask;
- } else {
- bits[bit/8] &= ~mask;
- }
- }
-
- }
- */
-}
+++ /dev/null
-package edu.berkeley.obits;
-
-import java.util.*;
-
-/** a physical or virtual reconfigurable device */
-public interface Device {
-
- /** reset the device */
- public void reset() throws DeviceException;
-
- /** flush any commands issued so far, blocking until they have taken effect */
- public void flush() throws DeviceException;
-
- public static class DeviceException extends RuntimeException {
- public DeviceException(String s) { super(s); }
- public DeviceException(Throwable t) { super(t); }
- }
-
-}
+++ /dev/null
-package edu.berkeley.obits.device.atmel;
-
-import com.atmel.fpslic.*;
-import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import org.ibex.util.*;
-import java.util.*;
-import java.io.*;
-
-public class At40k {
-
- /*private*/public final Fpslic dev;
- private final int width;
- private final int height;
-
- public At40k(Fpslic dev, int width, int height) {
- this.width = width;
- this.height = height;
- this.dev = dev;
- }
-
- public static class At40k10 extends At40k {
- public At40k10(Fpslic dev) { super(dev, 24, 24); }
- }
-
- public final class Sector {
- public final int col;
- public final int row;
- public Sector(Cell c) { this((c.col/4)*4, (c.row/4)*4); }
- private 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 Sector north() { return row+4>=height ? null : new Sector(col, row+4); }
- public Sector south() { return row==0 ? null : new Sector(col, row-4); }
- public Sector east() { return col+4>=width ? null : new Sector(col+4, row); }
- public Sector west() { return col==0 ? null : new Sector(col-4, row); }
- public Cell cell() { return At40k.this.cell(col, row); }
- }
-
- public final class SectorWire {
- public final boolean global;
- public final boolean horizontal;
- public final int plane;
- public final int row;
- public final int col;
- public SectorWire(boolean horizontal, int plane, int col, int row) {
- this.horizontal=horizontal;
- this.global = false;
- this.plane=plane;
- this.col= horizontal ? (col & ~0x3) : col;
- this.row=!horizontal ? (row & ~0x3) : row;
- }
- public boolean isDriven() {
- // FIXME: bridging connections (horiz-to-vert)
- for(int i=0; i<4; i++)
- if (cell(horizontal ? col+i : col,
- horizontal ? row : row+i).out(plane)) return true;
- // FIXME: sector switchbox drivers
- return false;
- }
- private int z(int z) { return (horizontal ? 0x30 : 0x20) | z; }
- public int code(boolean topleft) {
- switch(plane) {
- case 0: return z(6)+(topleft?0:1);
- case 1: return z(8)+(topleft?0:1);
- case 2: return z(2*(4-plane))+(topleft?0:1);
- case 3: return z(2*(4-plane))+(topleft?0:1);
- case 4: return z(2*(4-plane))+(topleft?0:1);
- }
- throw new Error();
- }
-
- private final int fine() { return horizontal ? row : col; }
- public final int coarse() { return horizontal ? col : row; }
- private int _row() { return horizontal ? row : ((row)>>2); }
- private int _col() { return horizontal ? ((col)>>2) : col; }
-
- public SectorWire west() { return !horizontal ? null : col-4<0 ? null : new SectorWire(horizontal, plane, col-4, row); }
- public SectorWire east() { return !horizontal ? null : col+4>=width ? null : new SectorWire(horizontal, plane, col+4, row); }
- public SectorWire north() { return horizontal ? null : row+4>=height ? null : new SectorWire(horizontal, plane, col, row+4); }
- public SectorWire south() { return horizontal ? null : row-4<0 ? null : new SectorWire(horizontal, plane, col, row-4); }
-
- public String toString() {
- return
- (horizontal?(col+":"+(col+3)):(""+col))+","+
- (horizontal?(row+"") :(row+":"+(row+3)))+
- "x"+plane;
- }
-
- /** returns the ZYX0 coordinate of the byte controlling the switchbox that allows <tt>w</tt> to drive this wire */
- public int switchbox(SectorWire w) {
- if (w.horizontal==horizontal) {
- if (w.plane!=plane) throw new Error();
- if (Math.abs(w.coarse()-coarse())!=4) throw new Error(w.coarse() + " -- " + coarse());
- boolean topleft = horizontal ? (w.coarse() < coarse()) : (w.coarse() > coarse());
- int col = _col() + (( horizontal && !topleft) ? 1 : 0);
- int row = _row() + ((!horizontal && topleft) ? 1 : 0);
- return (code(topleft) << 24) | (row<<16) | (col<<8);
- }
- throw new Error("not implemented");
- }
-
- public void drives(SectorWire w, boolean enable) {
- dev.mode4zyx(switchbox(w), enable?0x02:0x00, 0x07);
- }
-
- public boolean drives(SectorWire w) {
- int connect = (dev.mode4zyx(switchbox(w)) >> (global?3:0)) & 0x7;
- return (connect & 0x2)!=0;
- }
- public SectorWire driverRight() {
- System.out.println("checking " + Integer.toString(code(true), 16) + " " + Integer.toString(_row(), 16) + " " + Integer.toString(_col(), 16));
- int ret = dev.mode4(z(code(true)), _row(), _col());
- ret = (ret >> (global?3:0)) & 0x7;
- switch(ret) {
- case 0: return null;
- case 1: return null; /* global wire on same side */
- case 2: return new SectorWire(horizontal, plane, horizontal?(col+4):col, horizontal?row:(row+4));
- case 4: return null; /* global wire on other side */
- default: throw new Error("multiple drivers on " + this + "!");
- }
- }
- }
- /*
- public final class SwitchBox {
- public final boolean h;
- public final int col;
- public final int row;
- public final int plane;
- public SwitchBox(boolean h, int col, int row, int plane) { this.h = h; this.col = col; this.row = row; this.plane = plane; }
- public SectorWire west(boolean global) { return !h ? null : global ? null : new SectorWire(h, col-4, row, plane); }
- public SectorWire east(boolean global) { return !h ? null : global ? null : new SectorWire(h, col+4, row, plane); }
- public SectorWire north(boolean global) { return !h ? null : global ? null : new SectorWire(h, col, row-4, plane); }
- public SectorWire south(boolean global) { return !h ? null : global ? null : new SectorWire(h, col, row+4, plane); }
- }
- */
-
- public Cell cell(int col, int row) {
- if (col<0) return null;
- if (row<0) return null;
- if (col>=width) return null;
- if (row>=height) return null;
- return new Cell(col, row);
- }
-
- public final class Cell {
- public final int col;
- public final int row;
-
- public Cell(int col, int row) {
- this.row = row;
- this.col = col;
- }
-
- // Accessors for Neighbors //////////////////////////////////////////////////////////////////////////////
-
- public SectorWire hwire(int plane) { return new SectorWire(true, plane, col, row); }
- public SectorWire vwire(int plane) { return new SectorWire(false, plane, col, row); }
- public Cell east() { return cell(col+1, row); }
- public Cell west() { return cell(col-1, row); }
- public Cell north() { return cell(col, row+1); }
- public Cell south() { return cell(col, row-1); }
- public Cell ne() { return cell(col+1, row+1); }
- public Cell nw() { return cell(col-1, row+1); }
- public Cell se() { return cell(col+1, row-1); }
- public Cell sw() { return cell(col-1, row-1); }
- public Sector sector() { return new Sector(this); }
-
- /* bit positions mean: [MSB] zxy z_y zx_ z__ _xy __y _x_ ___ [LSB] */
- public void lut(int xlut, int ylut) { xlut(xlut); ylut(ylut); }
- public void xlut(int table) { dev.mode4(7, row, col, (byte)(table & 0xff)); }
- public byte xlut() { return (byte)(dev.mode4(7, row, col) & 0xff); }
- public String printXLut() { return printLut(xlut(), "x", "y", "t"); }
- public String printXLutX() { return printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti_source(), "t")); }
-
- public String str(int x, String def) {
- switch(x) {
- case NORTH: return "n";
- case SOUTH: return "s";
- case EAST: return "e";
- case WEST: return "w";
- case NW: return "nw";
- case SE: return "se";
- case NE: return "ne";
- case SW: return "sw";
- case FB: return "fb";
- case L0: return (hx(0)&&vx(0))?"HV0":hx(0)?"H0":vx(0)?"V0":"L0";
- case L1: return (hx(1)&&vx(1))?"HV1":hx(1)?"H1":vx(1)?"V1":"L1";
- case L2: return (hx(2)&&vx(2))?"HV2":hx(2)?"H2":vx(2)?"V2":"L2";
- case L3: return (hx(3)&&vx(3))?"HV3":hx(3)?"H3":vx(3)?"V3":"L3";
- case L4: return (hx(4)&&vx(4))?"HV4":hx(4)?"H4":vx(4)?"V4":"L4";
- default: return def;
- }
- }
-
- /* bit positions mean: [MSB] zxy zx_ z_y z__ _xy _x_ __y ___ [LSB] */
- public void ylut(int table) { dev.mode4(6, row, col, (byte)(table & 0xff)); }
- public byte ylut() { return (byte)(dev.mode4(6, row, col) & 0xff); }
- public String printYLut() { return printLut(ylut(), "y", "x", "t"); }
- public String printYLutX() { return printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti_source(), "t")) + Integer.toString(ylut() & 0xff, 16); }
-
- public void ff_reset_value(boolean value) {
- //dev.mode4( /* FIXME WRONG!!! */, row, col, 3, !value); return;
- }
- /** FIXME!!! */
- public boolean ff_reset_value() { return false; }
- public boolean columnClocked() {
- return false;
- }
-
- public void out(int plane, boolean enable) {
- switch(plane) {
- case L0: dev.mode4(0x00, row, col, 2, enable); return;
- case L1: dev.mode4(0x00, row, col, 3, enable); return;
- case L2: dev.mode4(0x00, row, col, 5, enable); return;
- case L3: dev.mode4(0x00, row, col, 4, enable); return;
- case L4: dev.mode4(0x00, row, col, 1, enable); return;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public boolean out(int plane) {
- switch(plane) {
- case L0: return (dev.mode4(0x00, row, col) & (1<<2)) != 0;
- case L1: return (dev.mode4(0x00, row, col) & (1<<3)) != 0;
- case L2: return (dev.mode4(0x00, row, col) & (1<<5)) != 0;
- case L3: return (dev.mode4(0x00, row, col) & (1<<4)) != 0;
- case L4: return (dev.mode4(0x00, row, col) & (1<<1)) != 0;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public void h(int plane, boolean enable) {
- switch(plane) {
- case 0: dev.mode4(0x08, row, col, 2, enable); return;
- case 1: dev.mode4(0x08, row, col, 0, enable); return;
- case 2: dev.mode4(0x08, row, col, 5, enable); return;
- case 3: dev.mode4(0x08, row, col, 6, enable); return;
- case 4: dev.mode4(0x00, row, col, 6, enable); return;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public boolean hx(int plane) {
- switch(plane) {
- case 0: return (dev.mode4(0x08, row, col) & (1<<2)) != 0;
- case 1: return (dev.mode4(0x08, row, col) & (1<<0)) != 0;
- case 2: return (dev.mode4(0x08, row, col) & (1<<5)) != 0;
- case 3: return (dev.mode4(0x08, row, col) & (1<<6)) != 0;
- case 4: return (dev.mode4(0x00, row, col) & (1<<6)) != 0;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public void v(int plane, boolean enable) {
- switch(plane) {
- case 0: dev.mode4(0x08, row, col, 1, enable); return;
- case 1: dev.mode4(0x08, row, col, 3, enable); return;
- case 2: dev.mode4(0x08, row, col, 4, enable); return;
- case 3: dev.mode4(0x08, row, col, 7, enable); return;
- case 4: dev.mode4(0x00, row, col, 7, enable); return;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public boolean vx(int plane) {
- switch(plane) {
- case 0: return (dev.mode4(0x08, row, col) & (1<<1)) != 0;
- case 1: return (dev.mode4(0x08, row, col) & (1<<3)) != 0;
- case 2: return (dev.mode4(0x08, row, col) & (1<<4)) != 0;
- case 3: return (dev.mode4(0x08, row, col) & (1<<7)) != 0;
- case 4: return (dev.mode4(0x00, row, col) & (1<<7)) != 0;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
-
- public int ti_source() {
- switch(dev.mode4(1, row, col) & 0x30) {
- case 0x20: return zi();
- case 0x10: return FB;
- case 0x00: return wi();
- default: throw new Error("ack!");
- }
- }
-
- public int t() {
- System.err.println("found " + (dev.mode4(1, row, col) & 0x34));
- switch(dev.mode4(1, row, col) & 0x34) {
- case 0x20: return TMUX_Z;
- case 0x24: return TMUX_W_AND_Z;
- case 0x34: return TMUX_FB;
- case 0x14: return TMUX_W_AND_FB;
- case 0x00: return TMUX_W;
- //default: throw new RuntimeException("unknown!");
- default: return TMUX_W;
- }
- }
-
- public void t(int code) {
- int result = 0;
- switch(code) {
- case TMUX_Z: result = 0x20; break; // TOTALLYBOGUS throw new Error("not implemented, but should be possible");
- case TMUX_W_AND_Z: result = 0x24; break;
- case TMUX_FB: result = 0x34; break; /* I think this is actually W_AND_FB, sadly */
- case TMUX_W_AND_FB: result = 0x14; break;
- case TMUX_W: result = 0x00; break;
- //default: throw new RuntimeException("unknown code! " + code);
- default: result = 0x00; break;
- }
- dev.mode4(1, row, col, result, 0x34);
- }
- /*
- private void fmux(int source) {
- switch(source) {
- case ZMUX:
- case FB:
- case ALWAYS_ON:
- default: throw new Error("unknown argument to fmux()");
- }
- }
-
- public boolean win_easable() {
- }
- */
-
- public int ti() {
- return dev.mode4(1, row, col) & 0x34;
- }
-
- public void t(boolean ignore_z_and_fb, boolean zm_drives_fb, boolean fb_drives_wm) {
- // still not totally satisfied...
- // need to find the bit that sets the w-mux off
- // what does it mean for both bits (0x30) to be set to 1?
- //if (fb && z) throw new RuntimeException("invalid combination");
- int result = 0;
- // ZM->FB = 0x04
- // FB->WM = 0x10
- // WZ->WM = 0x20
-
- // tff => w&z [0x20]
- // fff => w [0x00]
- // ttt => fb&w [0x34]
- // ftt => fb&w [0x14]
- // fft => fb&w [0x10]
-
- // ttf => w&z [0x24]
- // ftf => w [0x04]
- // tft => fb&w [0x30]
- if (ignore_z_and_fb) result |= 0x20;
- if (zm_drives_fb) result |= 0x04;
- if (fb_drives_wm) result |= 0x10;
- dev.mode4(1, row, col, result, 0x34);
- }
-
-
- public void c(int source) {
- switch(source) {
- case XLUT: dev.mode4(1, row, col, 0x00, 0xc0); break;
- case YLUT: dev.mode4(1, row, col, 0x40, 0xc0); break;
- case ZMUX: dev.mode4(1, row, col, 0x80, 0xc0); break;
- default: throw new RuntimeException("Invalid Argument");
- }
- }
- public int c() {
- int cval = dev.mode4(1, row, col) & 0xc0;
- switch (cval) {
- case 0x00: return XLUT;
- case 0x40: return YLUT;
- case 0x80: return ZMUX;
- }
- throw new Error("c() => " + cval);
- }
- public void b(boolean registered) { dev.mode4(1, row, col, 3, !registered); }
- public void f(boolean registered) { dev.mode4(1, row, col, 2, !registered); }
- public boolean xo() { return (dev.mode4(1, row, col) & 0x01) != 0; }
- public boolean yo() { return (dev.mode4(1, row, col) & 0x02) != 0; }
- public void xo(boolean center) { dev.mode4(1, row, col, 0, center); }
- public void yo(boolean center) { dev.mode4(1, row, col, 1, center); }
- public boolean b() { return (dev.mode4(1, row, col) & (1 << 3)) == 0; }
- public boolean f() { return (dev.mode4(1, row, col) & (1 << 2)) == 0; }
- public boolean x() { return (dev.mode4(1, row, col) & (1 << 1)) != 0; }
- public boolean y() { return (dev.mode4(1, row, col) & (1 << 0)) != 0; }
-
- public int oe() {
- switch (dev.mode4(0x02, row, col) & 0x3) {
- case 0: return NONE;
- case 1: return H4;
- case 2: return V4;
- default: throw new RuntimeException("invalid argument");
- }
- }
- public void oe(int source) {
- switch(source) {
- case NONE: dev.mode4(0x02, row, col, 0, 0x3); break;
- case H4: dev.mode4(0x02, row, col, 1, 0x3); break;
- case V4: dev.mode4(0x02, row, col, 2, 0x3); break;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public int xi() {
- // FIXME: can be multiple
- if ((dev.mode4(0x03, row, col) & (1<<4))!=0) return L4;
- switch(dev.mode4(0x05, row, col) & 0xff) {
- case 0x80: return SW;
- case (1<<6): return NE;
- case (1<<5): return SE;
- case (1<<4): return NW;
- case (1<<3): return L0;
- case (1<<2): return L1;
- case (1<<1): return L2;
- case (1<<0): return L3;
- case 0: return NONE;
- default: throw new Error();
- }
- }
-
- public void xi(int source) {
- switch(source) {
- case SW: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<7); break;
- case NE: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<6); break;
- case SE: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<5); break;
- case NW: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<4); break;
- case L4: dev.mode4(0x03, row, col, 4, true); dev.mode4(0x05, row, col, 0); break;
- case L3: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<0); break;
- case L2: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<1); break;
- case L1: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<2); break;
- case L0: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 1<<3); break;
- case NONE: dev.mode4(0x03, row, col, 4, false); dev.mode4(0x05, row, col, 0); break;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public int yi() {
- if ((dev.mode4(0x02, row, col) & (1<<6))!=0) return L4;
- switch(dev.mode4(0x04, row, col) & 0xff) {
- case 0x80: return NORTH;
- case (1<<5): return SOUTH;
- case (1<<6): return WEST;
- case (1<<4): return EAST;
- case (1<<3): return L0;
- case (1<<2): return L1;
- case (1<<1): return L2;
- case (1<<0): return L3;
- case 0: return NONE;
- default: throw new Error();
- }
- }
-
- public void yi(int source) {
- switch(source) {
- case NORTH: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<7); break;
- case SOUTH: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<5); break;
- case WEST: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<6); break;
- case EAST: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<4); break;
- case L4: dev.mode4(0x02, row, col, 6, true); dev.mode4(0x04, row, col, 0); break;
- case L3: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<0); break;
- case L2: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<1); break;
- case L1: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<2); break;
- case L0: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 1<<3); break;
- case NONE: dev.mode4(0x02, row, col, 6, false); dev.mode4(0x04, row, col, 0); break;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public void wi(int source) {
- switch(source) {
- case L4: dev.mode4(0x03, row, col, 1<<5, 0xEC); break;
- case L3: dev.mode4(0x03, row, col, 1<<6, 0xEC); break;
- case L2: dev.mode4(0x03, row, col, 1<<7, 0xEC); break;
- case L1: dev.mode4(0x03, row, col, 1<<3, 0xEC); break;
- case L0: dev.mode4(0x03, row, col, 1<<2, 0xEC); break;
- case NONE: dev.mode4(0x03, row, col, 0, 0xEC); break;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public int wi() {
- int who = dev.mode4(0x03, row, col) & 0xEC;
- switch(who) {
- case (1<<5): return L4;
- case (1<<6): return L3;
- case (1<<7): return L2;
- case (1<<3): return L1;
- case (1<<2): return L0;
- case (1<<0): return NONE; /* huh? */
- case (0): return NONE;
- default: throw new RuntimeException("invalid argument: " + who);
- }
- }
-
-
- public void zi(int source) {
- switch(source) {
- case L4: dev.mode4(0x02, row, col, 1<<7, 0xDB); break;
- case L3: dev.mode4(0x02, row, col, 1<<5, 0xDB); break;
- case L2: dev.mode4(0x02, row, col, 1<<4, 0xDB); break;
- case L1: dev.mode4(0x02, row, col, 1<<3, 0xDB); break;
- case L0: dev.mode4(0x02, row, col, 1<<2, 0xDB); break;
- case NONE: dev.mode4(0x02, row, col, 0, 0xDB); break;
- default: throw new RuntimeException("invalid argument");
- }
- }
-
- public int zi() {
- switch(dev.mode4(0x02, row, col) & 0xDB) {
- case (1<<7): return L4;
- case (1<<5): return L3;
- case (1<<4): return L2;
- case (1<<3): return L1;
- case (1<<2): return L0;
- case (1<<1): return NONE; /* huh? */
- case (1<<0): return NONE; /* huh? */
- case 0: return NONE;
- default: throw new RuntimeException("invalid argument: zi=="+(dev.mode4(0x02, row, col) & 0xDB));
- }
- }
-
-
- // Relevance //////////////////////////////////////////////////////////////////////////////
-
- public boolean xo_relevant() { return xo_relevant(NE) || xo_relevant(SE) || xo_relevant(NW) || xo_relevant(SW); }
- public boolean xo_relevant(int direction) {
- switch(direction) {
- case NE: return ne() != null && ne().xi()==SW /*&& ne().xi_relevant()*/;
- case NW: return nw() != null && nw().xi()==SE /*&& nw().xi_relevant()*/;
- case SE: return se() != null && se().xi()==NW /*&& se().xi_relevant()*/;
- case SW: return sw() != null && sw().xi()==NE /*&& sw().xi_relevant()*/;
- default: return false;
- }
- }
- public boolean yo_relevant() { return yo_relevant(NORTH) || yo_relevant(SOUTH) || yo_relevant(EAST) || yo_relevant(WEST); }
- public boolean yo_relevant(int direction) {
- switch(direction) {
- case NORTH: return north() != null && north().yi()==SOUTH /*&& north().yi_relevant()*/;
- case EAST: return east() != null && east().yi()==WEST /*&& east().yi_relevant()*/;
- case SOUTH: return south() != null && south().yi()==NORTH /*&& south().yi_relevant()*/;
- case WEST: return west() != null && west().yi()==EAST /*&& west().yi_relevant()*/;
- default: return false;
- }
- }
- public boolean xi_relevant() { return xi_to_xlut_relevant() || xi_to_ylut_relevant(); }
- public boolean yi_relevant() { return yi_to_xlut_relevant() || yi_to_ylut_relevant(); }
- public boolean xi_to_ylut_relevant() { return (((ylut() & 0xcc) >> 2) != (ylut() & 0x33)); }
- public boolean yi_to_xlut_relevant() { return (((xlut() & 0xcc) >> 2) != (xlut() & 0x33)); }
- public boolean zi_to_xlut_relevant() { return (((xlut() & LUT_Z) >> 4) != (xlut() & LUT_Z)); }
- public boolean zi_to_ylut_relevant() { return (((ylut() & LUT_Z) >> 4) != (ylut() & LUT_Z)); }
- public boolean xi_to_xlut_relevant() { return (((xlut() & LUT_SELF) >> 1) != (xlut() & (LUT_SELF >> 1))); }
- public boolean yi_to_ylut_relevant() { return (((ylut() & LUT_SELF) >> 1) != (ylut() & (LUT_SELF >> 1))); }
- public boolean xlut_relevant() {
- if ((c()==XLUT || c()==ZMUX) && c_relevant()) return true;
- if (xo()) return false;
- return xo_relevant();
- }
- public boolean ylut_relevant() {
- if ((c()==YLUT || c()==ZMUX) && c_relevant()) return true;
- if (yo()) return false;
- return yo_relevant();
- }
- public boolean c_relevant() {
- switch(ti()) {
- case 0x34: return true;
- case 0x14: return true;
- case 0x10: return true;
- case 0x30: return true;
- }
- for(int i=0; i<5; i++)
- if (out(i))
- return true;
- if (xo() || yo()) return true;
- return false;
- }
-
- public boolean register_relevant() {
- if (!c_relevant()) return false;
- if (f() && out_relevant()) return true;
- if (f() && fb_relevant()) return true;
- if (b() && xo()) return true;
- if (b() && yo()) return true;
- return false;
- }
- public boolean out_relevant() {
- boolean out = false;
- boolean connect = false;
- for(int i=0; i<4; i++) {
- if (out(L0+i)) out = true;
- if (hx(L0+i)) connect = true;
- if (vx(L0+i)) connect = true;
- }
- return out && connect;
- }
- public boolean fb_relevant() {
- if (!(zi_to_xlut_relevant()) ||
- !(zi_to_ylut_relevant())) return false;
- switch(ti()) {
- case 0x34: return true;
- case 0x14: return true;
- case 0x10: return true;
- case 0x30: return true;
- }
- return false;
- }
-
-
- }
-
- public IOB iob_bot(int col, boolean primary) { return new IOB(col, 0, primary, true); }
- public IOB iob_top(int col, boolean primary) { return new IOB(col, 1, primary, true); }
- public IOB iob_left(int row, boolean primary) { return new IOB(0, row, primary, false); }
- public IOB iob_right(int row, boolean primary) { return new IOB(1, row, primary, false); }
- /*
- public IOB fromPin(int pin) {
- if (pin >= 4 && pin <= 11) return io(pin-3);
- if (pin >= 15 && pin <= 18) return io(pin-2);
- if (pin >= 19 && pin <= 24) return io(pin);
- if (pin >= 27 && pin <= 30) return io(pin-2);
- if (pin >= 33 && pin <= 36) return io(pin);
- if (pin >= 38 && pin <= 47) return io(pin+1);
-
-
- if (pin >= 33 && pin <= 36) return io(pin+36);
- if (pin >= 38 && pin <= 41) return io(pin+43);
- if (pin >= 42 && pin <= 43) return io(pin+47);
- if (pin >= 44 && pin <= 47) return io(pin+49);
- if (pin >= 57 && pin <= 62) return io(pin+40);
- if (pin >= 63 && pin <= 66) return io(pin+46);
- if (pin >= 68 && pin <= 71) return io(pin+53);
- if (pin >= 72 && pin <= 73) return io(pin+53);
- if (pin >= 74 && pin <= 75) return io(pin+63);
- if (pin >= 76 && pin <= 77) return io(143+(pin-76));
- if (pin >= 80 && pin <= 81) return io(145+(pin-80));
- if (pin >= 82 && pin <= 85) return io(151+(pin-82));
- if (pin >= 86 && pin <= 89) return io(165+(pin-86));
- if (pin >= 91 && pin <= 94) return io(177+(pin-91));
- if (pin >= 95 && pin <= 96) return io(183+(pin-95));
- if (pin >= 97 && pin <= 100) return io(189+(pin-97));
- if (pin >= 161 && pin <= 164) return io(289+(pin-161));
- if (pin >= 165 && pin <= 166) return io(297+(pin-165));
- if (pin >= 167 && pin <= 168) return io(303+(pin-167));
- if (pin >= 169 && pin <= 170) return io(309+(pin-169));
- if (pin >= 172 && pin <= 173) return io(313+(pin-172));
- if (pin >= 174 && pin <= 175) return io(325+(pin-174));
- if (pin >= 176 && pin <= 179) return io(327+(pin-176));
- if (pin >= 180 && pin <= 181) return io(335+(pin-180));
- if (pin >= 184 && pin <= 185) return io(337+(pin-184));
- if (pin >= 186 && pin <= 191) return io(343+(pin-186));
- if (pin >= 192 && pin <= 193) return io(359+(pin-192));
- if (pin >= 195 && pin <= 196) return io(363+(pin-195));
- if (pin >= 197 && pin <= 200) return io(369+(pin-197));
- if (pin >= 201 && pin <= 204) return io(381+(pin-201));
- }
- public io(int ionum) {
- if (ionum <= 94) {
- int cell = (94 - pin) / 2;
- boolean primary = cell * 2 == (94-pin);
- }
- }
- */
- public final class IOB {
- public final int col;
- public final int row;
- public final boolean primary;
- public final boolean northsouth;
- public IOB(int col, int row, boolean primary, boolean northsouth) {
- this.col = col;
- this.row = row;
- this.northsouth = northsouth;
- this.primary = primary;
- }
- /*
- public String dump() {
- System.out.println("[ "+
- (schmitt()?"schmitt ":"")+
- (slew()==3?"fast ":slew()==2?"med ":slew()==1?"slow ":"slew-unknown ")+
- (cr()?"cr ":"")+
- (reg()?"reg ":"")+
-
- }
- */
- public void enableOutput(int direction) {
- useoem(true);
- output(direction);
- pullnone();
- useoem(true);
- oem(ALWAYS_ON);
- oe(true);
- // note: east-side IOBs should have slew=med, others slew=fast
- slew((!northsouth && col==1) ? MEDIUM : FAST);
- }
- public void enableInput() {
- schmitt(true);
- pullnone();
- }
-
- public void useoem(boolean use) { dev.mode4(z(3), row, col, 6, use); }
- public boolean useoem() { return (dev.mode4(z(3), row, col) & (1<<6))!=0; }
- public void schmitt(boolean use) { dev.mode4(z(0), row, col, 7, use); }
- public boolean schmitt() { return (dev.mode4(z(0), row, col) & (1<<7))!=0; }
-
- public void slew(int slew) {
- switch(slew) {
- case FAST: dev.mode4(z(0), row, col, 3<<5, 0x60); return;
- case MEDIUM: dev.mode4(z(0), row, col, 2<<5, 0x60); return;
- case SLOW: dev.mode4(z(0), row, col, 1<<5, 0x60); return;
- default: throw new Error();
- }
- }
-
- public void oem(int source) {
- switch(source) {
- case ALWAYS_ON: dev.mode4(z(3), row, col, 1<<5, 0x3f); return;
- case ALWAYS_OFF: dev.mode4(z(3), row, col, 0, 0x3f); return;
- default: throw new Error();
- }
- }
-
- private int z(int code) { return (northsouth ? 0x70 : 0x60) | (primary ? 0x00 : 0x04) | (code & 0x7); }
- public void pullup() { dev.mode4(z(0), row, col, 0x00<<1, 0x06); }
- public void pulldown() { dev.mode4(z(0), row, col, 0x03<<1, 0x06); }
- public void pullnone() { dev.mode4(z(0), row, col, 0x01<<1, 0x06); }
- public void oe(boolean oe) {
- int old = dev.mode4(z(1), row, col) & (~(1<<5));
- old |= oe ? 0 : (1<<5);
- dev.mode4(z(1), row, col, old & 0xff);
- }
-
- public void output(int which) {
- switch(which) {
- case NONE:
- dev.mode4(z(1), row, col, 0, 0x1f); return;
- case WEST: case EAST: case NORTH: case SOUTH:
- dev.mode4(z(1), row, col, 1<<0, 0x1f); return;
- case NW: case SW: case NE: case SE:
- dev.mode4(z(1), row, col, 1<<1, 0x1f); return;
- default: throw new Error();
- }
- }
-
- }
-
- public static void main(String[] s) throws Exception {
- System.out.println(printLut(0x39, "se", "n", "L0"));
- }
- public static synchronized String printLut(int lut, String xn, String yn, String zn) {
- try {
- File f = File.createTempFile("mvsis", ".mvs");
- f.deleteOnExit();
-
- FileOutputStream fos = new FileOutputStream(f);
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
- pw.println(".model clb");
- pw.println(".inputs "+xn+" "+yn+" "+zn);
- pw.println(".outputs O");
- pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
- for(int i=8; i>=0; i--) {
- int x = ((i & 0x01)!=0 ? 1 : 0);
- int y = ((i & 0x02)!=0 ? 1 : 0);
- int z = ((i & 0x04)!=0 ? 1 : 0);
- pw.print(" "+x+" ");
- pw.print(" "+y+" ");
- pw.print(" "+z+" ");
- //pw.print(" "+(x ^ y)+" ");
- //pw.print(" "+(y ^ z)+" ");
- //pw.print(" "+(z ^ y)+" ");
- pw.print((lut & (1<<i))==0 ? 0 : 1);
- pw.println();
- }
- pw.println(".end");
- pw.flush();
- pw.close();
- Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
- new Gobble("mvsis: ", p.getErrorStream()).start();
- //new Gobble("mvsis: ", p.getInputStream()).start();
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String ret = br.readLine();
- //f.delete();
- return ret.trim();
- } catch (Exception e) {
- e.printStackTrace();
- return "*mvsis_error*";
- }
- }
-
- public static class Gobble extends Thread {
- private final String header;
- private final BufferedReader br;
- public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
- public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
- public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
- public void run() {
- try {
- for(String s = br.readLine(); s!=null; s=br.readLine())
- System.err.println(header + s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-}
+++ /dev/null
-// FIXMEs for SLIPWAY:\r
-// - use INT3 instead of INT1\r
-// - use PORTE[0:1] instead of PORTE[2:3]\r
-// - use UART0 instead of UART1\r
-// - clock frequency\r
-\r
-//\r
-// YOU MUST COMPILE THIS WITH -O3 OR THE AVR WILL NOT BE ABLE TO KEEP UP!!!!\r
-//\r
-\r
-//#define F_CPU 3960000\r
-#define F_CPU 4000000\r
-\r
-#if !defined(__AVR_AT94K__)\r
-#error you forgot to put -mmcu=at94k on the command line\r
-#endif\r
-\r
-#include <avr/wdt.h>\r
-#include <util/delay.h>\r
-#include <avr/io.h>\r
-#include <avr/interrupt.h>\r
-\r
-void initUART1(unsigned int baudRate, unsigned int doubleRate) {\r
- UBRRHI = (((baudRate) >> 8) & 0x000F); \r
- UBRR1 = ((baudRate) & 0x00FF); \r
- UCSR1B |= ((1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1)); \r
-\r
- if (doubleRate)\r
- UCSR1A |= (1 << U2X1);\r
- /*\r
- else\r
- UCSR1A &= ~(1 << U2X1);\r
- */\r
-}\r
-\r
-#define BUFSIZE (1024)\r
-\r
-inline void portd(int bit, int on) {\r
- /*\r
- if (on) {\r
- PORTD &= ~(1<<bit);\r
- } else {\r
- PORTD |= (1<<bit);\r
- }\r
- */\r
-}\r
-inline void cts(int c) {\r
- if (c) {\r
- PORTE &= ~(1 << 4);\r
- portd(0, 1);\r
- } else {\r
- PORTE |= (1 << 4);\r
- portd(0, 0);\r
- }\r
-}\r
-\r
-\r
-static volatile int sending = 0;\r
-static volatile int32_t interrupt_count = 0;\r
-\r
-// RECV //////////////////////////////////////////////////////////////////////////////\r
-\r
-char read_buf[BUFSIZE];\r
-volatile int read_buf_head;\r
-volatile int read_buf_tail;\r
-char write_buf[BUFSIZE];\r
-volatile int write_buf_head;\r
-volatile int write_buf_tail;\r
-\r
-inline int inc(int x) { x++; if (x>=BUFSIZE) x=0; return x; }\r
-inline int read_full() { return inc(read_buf_tail)==read_buf_head; }\r
-inline int read_empty() { return read_buf_head==read_buf_tail; }\r
-inline int read_nearlyFull() {\r
- if (read_buf_tail==read_buf_head) return 0;\r
- if (read_buf_tail < read_buf_head) return (read_buf_head-read_buf_tail) < (BUFSIZE/2);\r
- return (read_buf_tail-read_buf_head) > (BUFSIZE/2);\r
-}\r
-\r
-inline int write_full() { return inc(write_buf_tail)==write_buf_head; }\r
-inline int write_empty() { return write_buf_head==write_buf_tail; }\r
-inline int write_nearlyFull() {\r
- if (write_buf_tail==write_buf_head) return 0;\r
- if (write_buf_tail < write_buf_head) return (write_buf_head-write_buf_tail) < (BUFSIZE/2);\r
- return (write_buf_tail-write_buf_head) > (BUFSIZE/2);\r
-}\r
-\r
-inline char recv() {\r
- int q;\r
- char ret;\r
- while(read_empty()) cts(1);\r
- ret = read_buf[read_buf_head];\r
- read_buf_head = inc(read_buf_head);\r
- if (!read_nearlyFull()) cts(0);\r
- return ret;\r
-}\r
-\r
-ISR(SIG_UART1_DATA) {\r
-\r
- if (write_empty()) {\r
- UCSR1B &= ~(1 << UDRIE1);\r
- return;\r
- }\r
- /*\r
- portd(1, 0);\r
- _delay_ms(10);\r
- portd(1, 1);\r
- _delay_ms(10);\r
- */\r
- char ret = write_buf[write_buf_head];\r
- write_buf_head = inc(write_buf_head);\r
- UDR1 = (int)ret;\r
-\r
- sei();\r
-}\r
-\r
-void send(char c) {\r
-\r
- while (write_full());\r
-\r
- write_buf[write_buf_tail] = c;\r
- write_buf_tail = inc(write_buf_tail);\r
-\r
- UCSR1B |= (1 << UDRIE1);\r
-\r
- //while(!(UCSR1A & (1 << UDRE1))); /* Wait for data Regiester to be empty */\r
-}\r
-\r
-\r
-void fpga_interrupts(int on) {\r
- if (on/* && interrupt_count<301*/) {\r
- //FISUA = 0x1;\r
- FISCR = 0x80;\r
- FISUD = 0x08;\r
- } else {\r
- FISUD = 0;\r
- FISCR = 0;\r
- }\r
-}\r
-\r
-void init() {\r
- read_buf_head = 0;\r
- read_buf_tail = 0;\r
- write_buf_head = 0;\r
- write_buf_tail = 0;\r
- EIMF = 0xFF; /* Enalbe External Interrrupt*/ \r
- DDRD = 0xFF; /* Configure PORTD as Output */\r
- DDRE = 1 << 4; /* ability to write to E4 */\r
- initUART1(12, 1); //for slow board\r
- //initUART1(1, 0);\r
- fpga_interrupts(1);\r
- SREG |= 0x80;\r
- sei();\r
-}\r
-\r
-\r
-\r
-void conf(int z, int y, int x, int d) {\r
- FPGAX = x;\r
- FPGAY = y;\r
- FPGAZ = z;\r
- FPGAD = d;\r
-}\r
-\r
-void doreset() {\r
- int i;\r
- for(i=0; i<5; i++) {\r
- PORTD = ~0x01;\r
- _delay_ms(50);\r
- PORTD = ~0x02;\r
- _delay_ms(50);\r
- PORTD = ~0x04;\r
- _delay_ms(50);\r
- PORTD = ~0x08;\r
- _delay_ms(50);\r
- }\r
- PORTD = ~0x00;\r
- wdt_enable(WDTO_250MS);\r
- while(1) { }\r
-}\r
-\r
-#define TIMERVAL 100\r
-int portdc = 0;\r
-ISR(SIG_FPGA_INTERRUPT15) { \r
- PORTD = portdc++;\r
- interrupt_count++;\r
- //PORTD = ~(interrupt_count & 0xff);\r
- //if (interrupt_count >= 301) fpga_interrupts(0);\r
- //sei();\r
- fpga_interrupts(1);\r
-}\r
-ISR(SIG_OVERFLOW0) { \r
- fpga_interrupts(0);\r
- PORTD = ~FISUA;\r
- TCNT0 = TIMERVAL; // load the nearest-to-one-second value into the timer0\r
- TIMSK |= (1<<TOIE0); // enable the compare match1 interrupt and the timer/counter0 overflow interrupt\r
- if (sending) UDR1 = FISUA;\r
- fpga_interrupts(1);\r
- sei();\r
-} \r
-void init_timer() { \r
- TCCR0 |= (1<<CS00); // set the timer0 prescaler to CK\r
- TCNT0 = TIMERVAL; // load the nearest-to-one-second value into the timer0\r
- TIMSK |= (1<<TOIE0); //enable the compare match1 interrupt and the timer/counter0 overflow interrupt\r
-} \r
-\r
-ISR(SIG_INTERRUPT1) { // use interrupt1 since interrupt0 is sent by the watchdog (I think)\r
- doreset();\r
-}\r
-\r
-void die() { cli(); cts(0); _delay_ms(2000); while(1) { portd(2,0); portd(2,1); } }\r
-ISR(SIG_UART1_RECV) {\r
- if (UCSR1A & (1 << FE1)) { portd(2,0); portd(3,1); die(); } // framing error, lock up with LED=01\r
- if ((UCSR1A & (1 << OR1))) { portd(2,1); portd(3,0); die(); } // overflow; lock up with LED=10\r
- if (read_full()) { portd(2,1); portd(3,1); die(); } // buffer overrun\r
- read_buf[read_buf_tail] = UDR1;\r
- read_buf_tail = inc(read_buf_tail);\r
- SREG |= 0x80;\r
- sei();\r
- if (read_nearlyFull()) cts(0);\r
-}\r
-\r
-inline int hex(char c) {\r
- if (c >= '0' && c <= '9') return (c - '0');\r
- if (c >= 'a' && c <= 'f') return ((c - 'a') + 0xa);\r
- if (c >= 'A' && c <= 'F') return ((c - 'A') + 0xa);\r
- return -1;\r
-}\r
-\r
-int main() {\r
- int count;\r
- init();\r
- cts(0);\r
- send('O');\r
- send('B');\r
- send('I');\r
- send('T');\r
- send('S');\r
- send('\n');\r
- cts(1);\r
- int x=0, y=0, z=0;\r
- for(;;) {\r
- int i, d=0;\r
- int r = recv();\r
- switch(r) {\r
- case 1:\r
- z = recv();\r
- y = recv();\r
- x = recv();\r
- d = recv();\r
- portd(1,1);\r
- conf(z, y, x, d);\r
- portd(1,0);\r
- break;\r
- case 2:\r
- fpga_interrupts(0);\r
- portd(1,1);\r
- send(FISUA);\r
- portd(1,0);\r
- fpga_interrupts(1);\r
- break;\r
- case 3:\r
- init_timer();\r
- break;\r
- case 4:\r
- sending = 1;\r
- break;\r
- case 5:\r
- sending = 0;\r
- break;\r
- case 6: {\r
- int32_t local_interrupt_count = interrupt_count;\r
- interrupt_count = 0;\r
- send((local_interrupt_count >> 24) & 0xff);\r
- send((local_interrupt_count >> 16) & 0xff);\r
- send((local_interrupt_count >> 8) & 0xff);\r
- send((local_interrupt_count >> 0) & 0xff);\r
- fpga_interrupts(1);\r
- break;\r
- }\r
- default: {\r
- if ((r & 0x80) == 0x80) {\r
- switch (r & 0x44) {\r
- case 0x44: z = recv(); break;\r
- case 0x40: z++; break;\r
- case 0x04: z--; break;\r
- }\r
- switch (r & 0x22) {\r
- case 0x22: y = recv(); break;\r
- case 0x20: y++; break;\r
- case 0x02: y--; break;\r
- }\r
- switch (r & 0x11) {\r
- case 0x11: x = recv(); break;\r
- case 0x10: x++; break;\r
- case 0x01: x--; break;\r
- }\r
- d = recv();\r
- portd(1,1);\r
- conf(z, y, x, d);\r
- portd(1,0);\r
- break;\r
- }\r
- die();\r
- }\r
- }\r
- }\r
- return 0;\r
-} \r
-\r
+++ /dev/null
-package edu.berkeley.obits.device.atmel;
-
-import com.atmel.fpslic.*;
-import edu.berkeley.slipway.*;
-import edu.berkeley.obits.*;
-import org.ibex.util.Log;
-import java.io.*;
-import java.util.*;
-import gnu.io.*;
-
-/** the "host" side of the AVR Drone; see AvrDrone.c for the other side */
-public class AvrDrone extends Fpslic {
-
- private final DataInputStream in;
- private final DataOutputStream out;
- private final Board board;
-
- public AvrDrone(Board b) throws IOException {
- this.board = b;
- this.out = new DataOutputStream(b.getOutputStream());
- this.in = new DataInputStream(b.getInputStream());
- init();
- }
-
- public void reset() throws IOException {
- board.reset();
- }
-
- private void init() throws IOException {
- 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.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') {
- System.out.println("\rsignature: got proper signature ");
- break;
- }
- }
-
- }
-
- 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() {
- try {
- if (reader != null) {
- reader.start();
- reader = null;
- }
- ByteCallback bc = new ByteCallback() {
- public synchronized void call(byte b) throws Exception {
- retval =
- ((b & 0xff) << 24) |
- ((in.read() & 0xff) << 16) |
- ((in.read() & 0xff) << 8) |
- ((in.read() & 0xff) << 0);
- this.notify();
- }
- };
- synchronized(bc) {
- callbacks.add(bc);
- out.writeByte(6);
- out.flush();
- bc.wait();
- }
- return retval;
- } catch (Exception e) { throw new RuntimeException(e); }
- }
-
- public static interface ByteCallback {
- public void call(byte b) throws Exception;
- }
-
- private Vector callbacks = new Vector();
-
- private Thread reader = new Thread() {
- public void run() {
- System.out.println("*** reader thread begun");
- while(true) {
- try {
- byte b = in.readByte();
- ByteCallback bc = (ByteCallback)callbacks.remove(0);
- bc.call(b);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- };
-
- 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 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) {
- if (cache[x]==null) return 0;
- if (cache[x][y]==null) return 0;
- return cache[x][y][z];
- }
-
- int lastz = 0;
- int lastx = 0;
- 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) {
- try {
- out.writeByte(1);
- out.writeByte(z);
- out.writeByte(y);
- out.writeByte(x);
- saveof++;
- lastz = z;
- lastx = x;
- lasty = y;
- out.writeByte(d);
-
- 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 RuntimeException(e);
- }
- }
-
- public /*synchronized*/ void flush() {
- try {
- out.flush();
- } 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); }
-
-}
package edu.berkeley.obits.gui;
+import com.atmel.fpslic.*;
+import edu.berkeley.slipway.*;
import static com.atmel.fpslic.FpslicConstants.*;
import static com.atmel.fpslic.Fpslic.Util.*;
import edu.berkeley.obits.*;
Graphics2D g;
G gg;
- At40k at40k;
- AvrDrone drone;
+ Fpslic at40k;
+ FtdiBoard drone;
private Cell[][] ca = new Cell[128][];
}
}
- public Gui(At40k at40k, AvrDrone drone) {
+ public Gui(Fpslic at40k, FtdiBoard drone) {
this.at40k = at40k;
this.drone = drone;
for(int i=0; i<ca.length; i++)
scan();
/*
- At40k.Cell c = at40k.cell(0,0);
+ Fpslic.Cell c = at40k.cell(0,0);
for(int i=0; i<256; i++) {
c.ylut(i);
System.out.println(c.printYLut());
}
public class Cell {
- At40k.Cell cell;
+ Fpslic.Cell cell;
boolean in = false;
public boolean xon = false;
public boolean yon = false;
public boolean xknown = false;
public boolean yknown = false;
int _x, _y;
- public Cell(int x, int y, At40k.Cell cell) {
+ public Cell(int x, int y, Fpslic.Cell cell) {
_x = x;
_y = y;
ca[_x][_y] = this;
return null;
}
- public static boolean xlut_relevant(At40k.Cell c) {
+ public static boolean xlut_relevant(Fpslic.Cell c) {
return c.xlut_relevant();
}
}
public void scan(final Gui.Cell c) {
try {
- final At40k.Cell cell = c.cell;
+ final Fpslic.Cell cell = c.cell;
AtmelSerial.scan(at40k, cell, NONE, true);
boolean safe = !cell.fb_relevant();
if (cell.xo()) safe = false;
int made = 0;
- private class BCB implements AvrDrone.ByteCallback {
+ private class BCB implements FtdiBoard.ByteCallback {
Gui.Cell c;
int who;
public BCB(Gui.Cell c, int who) {
package edu.berkeley.obits.gui;
+import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
import static com.atmel.fpslic.Fpslic.Util.*;
import edu.berkeley.obits.*;
}
}
Gui.Cell cell = whichCell(mousex, mousey);
- At40k.Cell c = cell == null ? null : cell.cell;
+ Fpslic.Cell c = cell == null ? null : cell.cell;
if ((k.getModifiers() & k.ALT_MASK) != 0)
switch(k.getKeyCode()) {
case VK_S:
import java.util.*;
import gnu.io.*;
-public abstract class Board {
+public interface Board {
/** boot the board using an md4 configuration stream */
public abstract void boot(Reader r) throws Exception;
import java.util.*;
import gnu.io.*;
-public class FakeBoard extends Board {
+public class FakeBoard implements Board {
public FakeBoard() {
import java.util.*;
import gnu.io.*;
-public class FtdiBoard extends Board {
+public class FtdiBoard extends Fpslic implements Board {
static {
System.load(new File("build/"+System.mapLibraryName("FtdiUartNative")).getAbsolutePath());
}
private final FpslicBoot chip;
- private final InputStream in;
- private final OutputStream out;
+ private final DataInputStream in;
+ private final DataOutputStream out;
public InputStream getInputStream() { return in; }
public OutputStream getOutputStream() { return out; }
bstFile = bstFile.substring(0, bstFile.lastIndexOf('.'));
bstFile = bstFile.replace('.', '/')+"/slipway_drone.bst";
boot(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(bstFile)));
- in = chip.getInputStream();
- out = chip.getOutputStream();
+ in = new DataInputStream(chip.getInputStream());
+ out = new DataOutputStream(chip.getOutputStream());
for(int i=0; i<255; i++) out.write(0);
out.flush();
}
if (s.length() >= i) return s;
return "0"+pad(s, i-1);
}
+
+
+ // AvrDrone leftovers //////////////////////////////////////////////////////////////////////////////
+
+ private void init() throws IOException {
+ 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.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') {
+ System.out.println("\rsignature: got proper signature ");
+ break;
+ }
+ }
+
+ }
+
+ 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() {
+ try {
+ if (reader != null) {
+ reader.start();
+ reader = null;
+ }
+ ByteCallback bc = new ByteCallback() {
+ public synchronized void call(byte b) throws Exception {
+ retval =
+ ((b & 0xff) << 24) |
+ ((in.read() & 0xff) << 16) |
+ ((in.read() & 0xff) << 8) |
+ ((in.read() & 0xff) << 0);
+ this.notify();
+ }
+ };
+ synchronized(bc) {
+ callbacks.add(bc);
+ out.writeByte(6);
+ out.flush();
+ bc.wait();
+ }
+ return retval;
+ } catch (Exception e) { throw new RuntimeException(e); }
+ }
+
+ public static interface ByteCallback {
+ public void call(byte b) throws Exception;
+ }
+
+ private Vector callbacks = new Vector();
+
+ private Thread reader = new Thread() {
+ public void run() {
+ System.out.println("*** reader thread begun");
+ while(true) {
+ try {
+ byte b = in.readByte();
+ ByteCallback bc = (ByteCallback)callbacks.remove(0);
+ bc.call(b);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ 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 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) {
+ if (cache[x]==null) return 0;
+ if (cache[x][y]==null) return 0;
+ return cache[x][y][z];
+ }
+
+ int lastz = 0;
+ int lastx = 0;
+ 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) {
+ try {
+ out.writeByte(1);
+ out.writeByte(z);
+ out.writeByte(y);
+ out.writeByte(x);
+ saveof++;
+ lastz = z;
+ lastx = x;
+ lasty = y;
+ out.writeByte(d);
+
+ 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 RuntimeException(e);
+ }
+ }
+
+ public /*synchronized*/ void flush() {
+ try {
+ out.flush();
+ } 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); }
+
}
// YOU MUST COMPILE THIS WITH -O3 OR THE AVR WILL NOT BE ABLE TO KEEP UP!!!!\r
//\r
\r
-//#define F_CPU 3960000\r
#define F_CPU 12000000\r
\r
#if !defined(__AVR_AT94K__)\r
import java.util.*;
import gnu.io.*;
-public class SerialBoard extends Board {
+public class SerialBoard implements Board {
private final SerialPort sp;
private final DataInputStream in;