X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=inline;f=src%2Fedu%2Fberkeley%2Fslipway%2Fdemos%2FDemo.java;fp=src%2Fedu%2Fberkeley%2Fslipway%2Fdemos%2FDemo.java;h=08f9ca6b0e798dcb3ecebf732d2b03b3ab95f2fd;hb=5301afc9e47f0dd6f96858d1c70407e0df5b53cf;hp=0000000000000000000000000000000000000000;hpb=d76f7c4ce28a3b84ada73282f3ca00a9b716cf93;p=slipway.git diff --git a/src/edu/berkeley/slipway/demos/Demo.java b/src/edu/berkeley/slipway/demos/Demo.java new file mode 100644 index 0000000..08f9ca6 --- /dev/null +++ b/src/edu/berkeley/slipway/demos/Demo.java @@ -0,0 +1,1096 @@ +package edu.berkeley.slipway.demos; + +import edu.berkeley.slipway.*; +import com.atmel.fpslic.*; +import static com.atmel.fpslic.FpslicConstants.*; +import edu.berkeley.slipway.gui.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.color.*; +import org.ibex.util.*; +import java.io.*; +import java.util.*; +import gnu.io.*; + +public class Demo { + + public static boolean mullers = true; + public static int masterx = 1; + + public static int PIPELEN=20; + + public static void main(String[] s) throws Exception { + SlipwayBoard slipway = new SlipwayBoard(); + FpslicDevice device = slipway.getFpslicDevice(); + FpslicDevice at40k = device; + try { + Log.info(Demo.class, "issuing command"); + + //at40k.iob_top(2, true).oe(false); + //at40k.iob_top(2, false).oe(false); + //at40k.iob_top(1, true).oe(false); + + // this command confirmed to turn *on* led0 + //at40k.iob_top(1, false).output(0); + /* + for(int i=0; i<20; i++) { + at40k.iob_bot(i, false).output(0); + at40k.iob_bot(i, true).output(0); + } + */ + + //System.out.println("tick"); + //Thread.sleep(3000); + //System.out.println("tick"); + //at40k.cell(0x01, 0x17).xlut((byte)0x); + + /* + System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).xlut(), 16)); + System.out.println(Integer.toString(0xff & at40k.cell(0x01, 0x17).ylut(), 16)); + at40k.cell(0x01, 0x17).ylut((byte)0xff); + */ + + //at40k.cell(0x01, 0x17).wi(L1); + /* + System.out.println("a: " + at40k.new SectorWire(true, 0, 4, 0x17).driverRight()); + System.out.println("b: " + at40k.new SectorWire(true, 1, 4, 0x17).driverRight()); + FpslicDevice.SectorWire h0p0 = at40k.new SectorWire(true, 0, 0, 0x17); + FpslicDevice.SectorWire h0p1 = at40k.new SectorWire(true, 1, 0, 0x17); + FpslicDevice.SectorWire h0p2 = at40k.new SectorWire(true, 2, 0, 0x17); + FpslicDevice.SectorWire h4p0 = at40k.new SectorWire(true, 0, 4, 0x17); + FpslicDevice.SectorWire h4p1 = at40k.new SectorWire(true, 1, 4, 0x17); + FpslicDevice.SectorWire h4p2 = at40k.new SectorWire(true, 2, 4, 0x17); + + //h4p1.drives(h0p1, false); + //at40k.cell(0x04, 0x17).out(L1, false); + //at40k.cell(0x04, 0x17).h(L0, false); + + for(int plane=0; plane<5; plane++) { + at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), false); + at40k.cell(0x04, 0x17).out(plane, false); + at40k.cell(0x04, 0x17).h(plane, false); + at40k.cell(0x01, 0x17).h(plane, false); + } + try { Thread.sleep(2000); } catch (Exception e) { } + + int plane=0; + at40k.new SectorWire(true, plane, 4, 0x17).drives(at40k.new SectorWire(true, plane, 0, 0x17), true); + at40k.cell(0x04, 0x17).out(plane, true); + at40k.cell(0x04, 0x17).h(plane, true); + at40k.cell(0x01, 0x17).h(plane, true); + at40k.cell(0x01, 0x17).wi(plane); + + */ + + /* + System.out.println("xlut is " + hex(at40k.cell(0x04, 0x17).xlut())); + System.out.println("ylut is " + hex(at40k.cell(0x04, 0x17).ylut())); + FpslicDevice.Cell cell = at40k.cell(0x04, 0x17); + //cell.xlut(0xff); + //cell.f(false); + System.out.println(cell.c()); + cell.c(YLUT); + cell.ylut(0x4D); + cell.xlut(0x00); + + cell.b(false); + cell.f(false); + //cell.t(false, false, true); + cell.t(false, true, false); + cell.out(L3, true); + cell.wi(L3); + + cell.yo(false); + cell.h(L0, false); + cell.h(L1, false); + cell.h(L2, false); + cell.h(L3, false); + cell.h(L4, false); + + for(int i=3; i>=1; i--) { + at40k.cell(i, 0x17).yi(EAST); + at40k.cell(i, 0x17).ylut(0x55); + at40k.cell(i, 0x17).yo(false); + } + */ + + //System.out.println("reading port status: " + Integer.toString(device.readFpgaData() & 0xff, 16)); + + + // blank these out + /* + at40k.cell(23, 8).ylut(0xff); + at40k.cell(23, 11).ylut(0xff); + at40k.iob_right(8, true).enableOutput(); + at40k.iob_right(11, true).enableOutput(); + */ + //for(int x=4; x<=22; x++) swap(at40k.cell(x, 22), NW, NORTH); + + + // entry cell: just copy X->X Y->Y + //at40k.cell(4,23).b(false); + //at40k.cell(4,23).yo(false); + //at40k.cell(4,23).ylut(at40k.cell(4,23).xlut()); + //at40k.cell(4,23).xo(false); + /* + at40k.cell(4,23).xlut(0x55); + at40k.cell(4,23).ylut(0x55); + */ + /* + at40k.cell(4,23).xlut(0x71); + at40k.cell(4,23).ylut(0x44); + at40k.cell(4,23).c(YLUT); + at40k.cell(4,23).f(false); + at40k.cell(4,23).t(false, false, true); + */ + + //for(int x=6; x<=23; x++) copy(at40k.cell(x, 23), NW, WEST); // top row copies to the right + /* + copy(at40k.cell(5, 22), NW, NORTH); + for(int x=6; x<=22; x++) copy(at40k.cell(x, 22), NW, WEST); // second top row copies to the right + //for(int y=22; y>=10; y--) copy(at40k.cell(23, y), NW, NORTH); // right edge copies down + for(int y=21; y>=9; y--) copy(at40k.cell(22, y), NW, NORTH); // second right edge copies down + copy(at40k.cell(23, 9), NW, WEST); // second output + */ + /* + handshaker(at40k.cell(4,23)); + at40k.cell(4,23).xi(NW); + at40k.cell(4,23).yi(SOUTH); + + //handshaker(at40k.cell(5,23)); + //at40k.cell(5,23).yi(NORTH); + + at40k.cell(5,23).yi(NORTH); + at40k.cell(5,23).xlut(0x55); + at40k.cell(5,23).xi(SW); + at40k.cell(5,23).ylut(0x55); + at40k.cell(5,22).yi(NORTH); + at40k.cell(5,22).xlut(0x55); + + bounce(at40k.cell(4,22)); + + // cell southeast of entry cell + at40k.cell(3,22).xi(NE); // NW->xin + at40k.cell(3,22).ylut(0x33); // xin->y + at40k.cell(3,22).yo(false); // y->yout + copy(at40k.cell(3, 21), NW, NORTH); // second top row copies to the right + copy(at40k.cell(4, 21), NW, EAST); // second top row copies to the right + copy(at40k.cell(5, 21), NW, EAST); // second top row copies to the right + copy(at40k.cell(6, 21), NW, EAST); // second top row copies to the right + copy(at40k.cell(6, 22), NW, SOUTH); // second top row copies to the right + */ + /* + at40k.cell(05,22).xlut(0xff); + at40k.cell(05,22).ylut(0xff); + at40k.cell(05,22).c(XLUT); + at40k.cell(05,22).f(false); + at40k.cell(05,22).b(false); + at40k.cell(05,22).oe(NONE); + at40k.cell(05,22).v(L3, true); + at40k.cell(05,22).out(L3, true); + */ + /* + at40k.cell(4,23).ylut(~0xCC); + at40k.cell(4,23).xlut(~0xAA); + at40k.cell(5,23).ylut(~0xAA); + at40k.cell(5,23).xlut(~0xAA); + for(int i=6; ii) return s; return "0"+pad((i-1),s); } + public static String bin8(byte b) { + int n = b & 0xff; + String ret = ""; + for(int i=7; i>=0; i--) + ret += (n & (1<> 1) | + (x & 0x10) | + (x & 0x08) | + ((x & 0x02) << 1) | + ((x & 0x04) >> 1) | + (x & 0x01); + } + + /** watches for a rising/falling edge on Yin, emits a pulse on Xout */ + public static void pulse_detect(FpslicDevice.Cell c, int in, boolean falling) { + c.ylut(0x00); + c.xlut(0x00); + switch(in) { + case NW: case NE: case SW: case SE: { + c.xi(in); + loopback(c, XLUT); + if (!falling) c.ylut(lutSwap(0x0C)); /* x & !z */ + else c.ylut(lutSwap(0x30)); /* !x & z */ + c.xlut(LUT_SELF); + break; + } + case NORTH: case SOUTH: case EAST: case WEST: { + c.yi(in); + loopback(c, YLUT); + if (!falling) c.xlut(0x0C); /* y & !z */ + else c.xlut(0x30); /* !y & z */ + c.ylut(LUT_SELF); + break; + } + default: throw new Error(); + } + } + + /** watches for a pulse on Xin, copies value of Yin */ + public static void pulse_copy(FpslicDevice.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 */ + if (!invert) cell.xlut(lutSwap(0xB8)); /* yo = x ? yi : z => 1011 1000 */ + else cell.xlut(lutSwap(0x74)); /* yo = x ? !yi : z => 0111 0100 */ + cell.xi(xi); + cell.yi(yi); + } + + public static void loopback(FpslicDevice.Cell cell, int cin) { + cell.f(false); + cell.b(false); + cell.t(false, false, true); + cell.yo(false); + cell.xo(false); + cell.c(cin); + } + + public static void doit(FpslicDevice at40k, SlipwayBoard device) throws Exception { + + FpslicDevice.Cell led = at40k.cell(1, 23); + led.v(L2, true); + led.h(L2, false); + led.yi(L2); + led.ylut(~LUT_SELF); + led.xlut(LUT_SELF); + led.yo(false); + + FpslicDevice.Cell c = at40k.cell(1, 22); + c.out(L1, true); + c.out(L0, true); + c.oe(V4); + c.ylut(0xff); + c.h(L1, true); + c.h(L0, false); + + c.v(L0, /*false*/true); + + c.v(L1, true); + c.f(false); + c.b(false); + c.c(YLUT); + + for(int i=0; i<4; i++) at40k.cell(i, 20).h(L0, false); + FpslicDevice.Cell z = at40k.cell(1, 20); + z.out(L0, true); + z.xlut(0xff); + z.c(XLUT); + z.yi(L0); + z.ylut(~LUT_SELF); + z.v(L0, true); + //z.h(L0, true); + z.h(L0, false); + z.f(false); + z.b(false); + z.hwire(L0).east().drives(z.hwire(L0), false); + z.hwire(L1).east().drives(z.hwire(L1), false); + z.vwire(L0).south().drives(z.vwire(L0), false); + z.vwire(L1).south().drives(z.vwire(L1), false); + z.oe(H4); + + z = at40k.cell(0, 20); + z.oe(NONE); + z.out(L0, true); + z.out(L1, true); + z.out(L2, true); + //z.out(L3, true); + z.out(L4, true); + z.h(L0, true); + z.h(L1, true); + z.h(L2, true); + //z.h(L3, true); + z.h(L4, true); + z.f(false); + z.b(false); + z.yi(EAST); + z.ylut(LUT_SELF); + z.c(YLUT); + + for(int y=20; y<=22; y++) + for(int x=2; x<=5; x++) { + c = at40k.cell(x, y); + copy(c, NW, WEST); + } + + //c = at40k.cell(2, 22); + //c.h(L0, true); + //c.yi(L0); + + c = at40k.cell(1, 21); + c.v(L0, true); + c.v(L2, true); + c.yi(L0); + c.out(L2, true); + c.ylut(LUT_SELF); + c.c(YLUT); + c.b(false); + c.f(false); + c.oe(NONE); + c.yo(false); + + + + c = at40k.cell(13, 22); + c.xlut(LUT_OTHER | 0xF0); + c.c(XLUT); + c.t(false, false, true); + c.b(false); + c.f(false); + c.ylut(0xF0); + c.yi(EAST); + c.yo(false); + /* + // this gate detects a rising edge on its Xin (delayed copy on Yin); when viewed, it inverts its state + c = at40k.cell(14, 22); + c.ylut(0x00); + c.c(XLUT); + c.f(false); + c.b(false); + c.t(false, false, true); + c.xi(SE); + c.yi(SOUTH); + c.yo(false); + c.xo(false); + c.ylut(0xA6); // (x & !z) ? ~y : y + c.xlut(LUT_SELF); + + c = at40k.cell(14, 20); + c.ylut(LUT_OTHER); + c.xi(NE); + c = at40k.cell(14, 21); + c.ylut(LUT_SELF); + c.xi(SOUTH); + + c = at40k.cell(13, 22); + c.xlut(0x00); + c.xlut(LUT_OTHER);// | 0xF0); + */ + //c = at40k.cell(13, 22); + //copy(c, NW, EAST); + /* + c.ylut(0x00); + c.c(YLUT); + c.f(false); + c.b(false); + c.t(false, false, true); + c.xi(SE); + c.yi(NORTH); + c.yo(false); + c.xo(false); + c.ylut(0x54); // (x || z) & !y + */ + + /* + c = at40k.cell(2, 21); + c.ylut(0x00); + c.c(YLUT); + c.f(false); + c.b(false); + c.t(false, false, true); + c.xi(SE); + c.yi(WEST); + c.yo(false); + c.xo(false); + c.ylut(0xE8); + + //at40k.cell(2, 21).xlut(0xF0); + + at40k.cell(3, 22).ylut(LUT_OTHER); + at40k.cell(3, 22).xi(SW); + */ + //at40k.iob_top(5, true).enableOutput(SOUTH); + //at40k.iob_top(5, false).enableOutput(SE); + } + + public static int yofs = mullers ? 19 : 22; + public static void counter(FpslicDevice at40k, SlipwayBoard device) throws Exception { + // watch for rising edge from south, emit pulse on Xout (to NE) + //copy(at40k.cell(16,23), SW, WEST); + + for(int x=22; x>=1; x-=2) { + pulse_detect(at40k.cell(x, yofs), SE, false); + pulse_detect(at40k.cell(x, yofs-1), EAST, true); + pulse_copy(at40k.cell(x-1, yofs), SE, SOUTH, false); + pulse_copy(at40k.cell(x-1, yofs-1), NE, NORTH, true); + + //pulse_detect(at40k.cell(15, 22), NORTH, false); + //pulse_detect(at40k.cell(16, 22), NW, true); + //pulse_copy(at40k.cell(16, 21), NW, WEST, false); + //pulse_copy(at40k.cell(15, 21), NE, EAST, true); + } + for(int x=23; x>1; x-=2) { + pulse_detect(at40k.cell(x-1, yofs-2), SW, false); + pulse_detect(at40k.cell(x-1, yofs-3), WEST, true); + pulse_copy(at40k.cell(x, yofs-2), SW, SOUTH, false); + pulse_copy(at40k.cell(x, yofs-3), NW, NORTH, true); + + //pulse_detect(at40k.cell(15, 22), NORTH, false); + //pulse_detect(at40k.cell(16, 22), NW, true); + //pulse_copy(at40k.cell(16, 21), NW, WEST, false); + //pulse_copy(at40k.cell(15, 21), NE, EAST, true); + } + copy(at40k.cell(1, yofs-2), SOUTH, SOUTH); + copy(at40k.cell(1, yofs-3), NORTH, NORTH); + at40k.cell(1, yofs-3).ylut(~at40k.cell(1, yofs-3).ylut()); + at40k.cell(1, yofs-3).xlut(~at40k.cell(1, yofs-3).xlut()); + + copy(at40k.cell(23, yofs), SOUTH, SOUTH); + copy(at40k.cell(23, yofs-1), SOUTH, SOUTH); + + for(int i=23; i>yofs; i--) copy(at40k.cell(1, i), SOUTH, SOUTH); + + //at40k.iob_top(1, true).slew(SLOW); + //at40k.iob_top(1, false).slew(SLOW); + + } + + public static void fill(FpslicDevice at40k, SlipwayBoard device, int num) throws Exception { + //muller(at40k.cell(PIPELEN,22), NE, WEST); + FpslicDevice.Cell a = at40k.cell(10,22); + FpslicDevice.Cell b = at40k.cell(11,22); + a.ylut(0x00); + for(int i=0; i=0; x--) { + at40k.cell(x, 21).ylut(0xAA); + at40k.cell(x, 21).yi(EAST); + at40k.cell(x, 21).yo(false); + } + + at40k.cell(0, 22).ylut(0xAA); + at40k.cell(0, 22).yi(SOUTH); + at40k.cell(0, 22).yo(false); + + at40k.cell(0, 23).ylut(~0xAA); + at40k.cell(0, 23).xlut(~0xcc); + at40k.cell(0, 23).yi(SOUTH); + at40k.cell(0, 23).yo(false); + */ + for(int x=3; x<=23; x+=2) { + pulse_detect(at40k.cell(x-1, 19), SW, false); + pulse_detect(at40k.cell(x-1, 18), WEST, true); + pulse_copy(at40k.cell(x, 19), SW, SOUTH, false); + pulse_copy(at40k.cell(x, 18), NW, NORTH, true); + + if (x<17) { + pulse_detect(at40k.cell(x-1, 16), SW, false); + pulse_detect(at40k.cell(x-1, 15), WEST, true); + pulse_copy(at40k.cell(x, 16), SW, SOUTH, false); + pulse_copy(at40k.cell(x, 15), NW, NORTH, true); + } + //pulse_detect(at40k.cell(15, 22), NORTH, false); + //pulse_detect(at40k.cell(16, 22), NW, true); + //pulse_copy(at40k.cell(16, 21), NW, WEST, false); + //pulse_copy(at40k.cell(15, 21), NE, EAST, true); + } + for(int x=14; x>=1; x--) + copy(at40k.cell(x, 17), EAST, EAST); + for(int x=4; x>=0; x--) + copy(at40k.cell(x, 21), EAST, EAST); + copy(at40k.cell(13, 17), SOUTH, SOUTH); + + copy(at40k.cell(0, 20), NORTH, NORTH); + copy(at40k.cell(0, 19), NORTH, NORTH); + copy(at40k.cell(0, 18), NORTH, NORTH); + copy(at40k.cell(0, 17), NORTH, NORTH); + copy(at40k.cell(0, 16), NORTH, NORTH); + copy(at40k.cell(1, 16), WEST, WEST); + copy(at40k.cell(1, 15), NORTH, NORTH); + + copy(at40k.cell(1, 20), SOUTH, SOUTH); + copy(at40k.cell(1, 19), SOUTH, SOUTH); + copy(at40k.cell(1, 18), SOUTH, SOUTH); + + for(int y=20; y<=23; y++) + copy(at40k.cell(23, y), SOUTH, SOUTH); + + + //for(int x=19; x<=23; x++) + //copy(at40k.cell(x, 0), WEST, WEST); + //copy(at40k.cell(18, 19), NW, NW); + //at40k.iob_top(5, true).enableOutput(SOUTH); + //at40k.iob_top(5, false).enableOutput(SOUTH); + } +}