X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fslipway%2FAsyncPaperDemo.java;h=dc1b823cd6fd772b236df198d48f1349811f8ec6;hb=05bfa73d5415e19943cf36c094dbdb50304a341c;hp=d9428c37ac644ecc68aa6d5f1cc50951917426fe;hpb=dfa9f65eb0614beb6fe0d7e7660a300087fc656d;p=slipway.git diff --git a/src/edu/berkeley/slipway/AsyncPaperDemo.java b/src/edu/berkeley/slipway/AsyncPaperDemo.java index d9428c3..dc1b823 100644 --- a/src/edu/berkeley/slipway/AsyncPaperDemo.java +++ b/src/edu/berkeley/slipway/AsyncPaperDemo.java @@ -21,63 +21,364 @@ public class AsyncPaperDemo { fpslic = new FtdiBoard(); } - public void main() throws Exception { + Fpslic.Cell start; + public void main(String[] s) throws Exception { turnOnLeds(); setupScanCell(); - Fpslic.Cell root = fpslic.cell(2, 2); - - root.yo(root.north()); - root.ylut(~LUT_SELF); - root.c(YLUT); - root = root.north(); - - root.yo(root.east()); - root.ylut(~LUT_SELF); - root.c(YLUT); - root = root.east(); - - root.yo(root.south()); - root.ylut(~LUT_SELF); - root.c(YLUT); - root = root.south(); - - root.yo(root.west()); - root.c(YLUT); - root = root.west(); - - root = fpslic.cell(3, 7); - root.h(1, true); - root.h(2, true); - root.wi(L1); - root.zi(L2); - root.c(YLUT); - root.t(TMUX_W); - root.b(false); - root.f(false); - root.ylut(LUT_SELF); - root.yi(EAST); - root.xlut(LUT_Z); - root.xo(false); - - root.west().out(2, true); - root.west().h(2, true); - root.west().c(YLUT); - - root.west().west().out(1, true); - root.west().west().h(1, true); - root.west().west().c(YLUT); - - root.ne().xo(root); - - runGui(24, 24); + //runGui(24, 24); + + for(int i=0; i<255; i++) + fpslic.readCount(); + + //System.in.read(); + for(int i=46; i<400; i+=2) { + go(i); + } + System.out.println("done"); + + } + + public void go(int size) throws Exception { + start = fpslic.cell(20, 21); + int rsize = size-createPipeline(start, true, size, false); + System.out.println("actual size => " + rsize); + pipe(start.west().north(), start.west(), new int[] { NE, EAST, SW, SOUTH }); + + for(int i=1; i<22; i+=2) + divider(fpslic.cell(21, i)); + fpslic.cell(23,0).yo(fpslic.cell(22,0)); + fpslic.cell(21,22).yo(fpslic.cell(20,22)); + fpslic.cell(21,22).xo(fpslic.cell(20,22)); + + reconfigTopLeft(); + reconfigTopRight(); + fpslic.flush(); + + Thread.sleep(2000); + + String sizes = rsize+""; + while(sizes.length()<3) sizes = "0"+sizes; + String fname = "data/size"+sizes+".csv"; + if (!new File(fname).exists()) { + PrintWriter outfile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(fname))); + for(int i=0; i 633mcell/sec velocity! =) + outfile.println(occupancy + ", " + result); + System.out.println((2*count)+"/"+size+" "+occupancy + ", " + result + " @ " + elapsed); + outfile.flush(); + } + + private void drain(int size) { + while(true){ + topLeft().xlut(0x00); + for(int i=0; i " + rc); + //try { System.in.read(); } catch (Exception _) { } + continue; + } + + reconfigTopLeft(); + + fpslic.flush(); + fpslic.readCount(); + fpslic.readCount(); + try { Thread.sleep(100); } catch (Exception e) { } + rc = fpslic.readCount(); + if (rc!=0) { + System.err.println("flush() failed => " + rc); + //try { System.in.read(); } catch (Exception _) { } + continue; + } + break; + } + } + + private void fill(int count, int size) { + //topLeft().ylut((count>0 && count " + yes); + //try { Thread.sleep(500); } catch (Exception _) { } + } + //System.out.println("done filling."); + //try { Thread.sleep(2000); } catch (Exception _) { } + + //System.out.println("reconfigured."); + //try { System.in.read(); } catch (Exception _) { } + + + if (count>0 && count c.fpslic().getHeight()-7) { + if (length < 10+4) { stop = true; break; } + length -= 10; + c = pipe(c, c.south(), new int[] { NW, SOUTH }); + c = c.nw(); + c = pipe(c, c.south(), new int[] { NE, EAST, SE, WEST, SE, SOUTH }); + c = c.nw().west(); + downward = true; + } else { + if (length < 8+4) { stop = true; break; } + length -= 8; + Fpslic.Cell ret = c = pipe(c, c.south(), new int[] { NE, NORTH, NW, NORTH }); + c = c.se(); + c = pipe(c, c.north(), new int[] { SW, SOUTH, SE, SOUTH }); + c = ret; + } + } + } while(false); + if (stop) { + length -= 4; + if (downward) { + c = micropipelineStage(c, c.north(), c.sw()); + c = micropipelineStage(c, c.ne(), c.west()); + c = micropipelineStage(c, c.east(), c.ne()); + c = micropipelineStage(c, c.sw(), c.north()); + } else { + c = pipe(c, c.south(), new int[] { NW, EAST, SE, SOUTH }); + } + return length; + } else { + return createPipeline(c, downward, length, false); + } + } + + /* + private void createPipeline(Fpslic.Cell c, boolean downward, int length) { + length -= 2; + if (downward) { + if (c.row == 0) { + c = micropipelineStage(c, c.ne(), c.west()); + c = micropipelineStage(c, c.east(), c.nw()); + if (length > 0) createPipeline(c, false, length); + } else { + c = micropipelineStage(c, c.ne(), c.east()); + c = micropipelineStage(c, c.west(), c.sw()); + if (length > 0) createPipeline(c, true, length); + } + } else { + if (c.row == c.fpslic().getHeight()-1) { + c = micropipelineStage(c, c.se(), c.west()); + c = micropipelineStage(c, c.east(), c.sw()); + if (length > 0) createPipeline(c, true, length); + } else { + c = micropipelineStage(c, c.se(), c.east()); + c = micropipelineStage(c, c.west(), c.nw()); + if (length > 0) createPipeline(c, false, length); + } + } + } + */ + + private Fpslic.Cell micropipelineStage(Fpslic.Cell c, Fpslic.Cell prev, Fpslic.Cell next) { + return micropipelineStage(c, prev, next, true); + } + private Fpslic.Cell micropipelineStage(Fpslic.Cell c, Fpslic.Cell prev, Fpslic.Cell next, boolean configDir) { + c.b(false); + c.f(false); + c.yo(false); + c.xo(false); + switch(c.dir(next)) { + case NORTH: case SOUTH: case EAST: case WEST: + switch (c.dir(prev)) { + case NORTH: case SOUTH: case EAST: case WEST: throw new Error("cannot have prev&next both use y"); + } + if (configDir) { + c.yi(next); + c.xi(prev); + } + + c.c(YLUT); + c.ylut(0x00); + c.xlut(0x00); + c.wi(L0); + c.t(TMUX_W_AND_FB); + c.ylut((LUT_SELF & ~LUT_OTHER) | + (LUT_Z & ~LUT_OTHER) | + (LUT_Z & LUT_SELF)); + c.xlut(LUT_Z); + fpslic.flush(); + c.wi(NONE); + fpslic.flush(); + break; + case NW: case SE: case SW: case NE: + switch (c.dir(prev)) { + case NW: case SE: case SW: case NE: throw new Error("cannot have prev&next both use x"); + } + if (configDir) { + c.xi(next); + c.yi(prev); + } + + c.c(XLUT); + c.xlut(0x00); + c.ylut(0x00); + c.wi(L0); + c.t(TMUX_W_AND_FB); + c.xlut((LUT_SELF & ~LUT_OTHER) | + (LUT_Z & ~LUT_OTHER) | + (LUT_Z & LUT_SELF)); + c.ylut(LUT_Z); + fpslic.flush(); + c.wi(NONE); + fpslic.flush(); + break; + default: throw new Error(); + } + //c.t(TMUX_FB); + return next; } private void turnOnLeds() { for(int i=0; i<24; i++) { - fpslic.iob_bot(i, true).enableOutput(NORTH); - fpslic.iob_bot(i, false).enableOutput(NW); + //fpslic.iob_bot(i, true).enableOutput(NORTH); + //fpslic.iob_bot(i, false).enableOutput(NW); fpslic.cell(i, 0).xlut(0xff); fpslic.cell(i, 0).ylut(0xff); } @@ -88,6 +389,58 @@ public class AsyncPaperDemo { fpslic.cell(23,15).yi(L3); fpslic.cell(23,15).ylut(0xAA); fpslic.iob_right(15, true).enableOutput(WEST); + + fpslic.cell(23,0).ylut(0x00); + fpslic.iob_right(0, true).enableOutput(WEST); + fpslic.flush(); + } + + private void divider(Fpslic.Cell c) { + Fpslic.Cell detect1 = c; + Fpslic.Cell detect2 = c.east(); + + detect1.yi(NORTH); + detect1.ylut(LUT_SELF); + detect1.xlut(LUT_OTHER & (~LUT_Z)); + detect1.c(YLUT); + detect1.t(TMUX_FB); + detect1.f(false); + detect1.b(false); + + detect2.xi(NW); + detect2.ylut(LUT_OTHER); + detect2.xlut((~LUT_SELF) & LUT_Z); + detect2.c(YLUT); + detect2.t(TMUX_FB); + detect2.f(false); + detect2.b(false); + + detect1.south().yi(EAST); + detect1.south().xi(NE); + detect1.south().c(YLUT); + detect1.south().t(TMUX_FB); + detect1.south().f(false); + detect1.south().b(false); + detect1.south().ylut( (LUT_OTHER & (~LUT_SELF)) | + ((~LUT_OTHER) & LUT_Z) + ); + detect1.south().xlut( (LUT_SELF & (~LUT_OTHER)) | + ((~LUT_SELF) & LUT_Z) + ); + + detect2.south().yi(WEST); + detect2.south().xi(NW); + detect2.south().c(YLUT); + detect2.south().t(TMUX_FB); + detect2.south().f(false); + detect2.south().b(false); + detect2.south().ylut( (LUT_OTHER & (LUT_SELF)) | + ((~LUT_OTHER) & LUT_Z) + ); + detect2.south().xlut( (LUT_SELF & (~LUT_OTHER)) | + ((~LUT_SELF) & LUT_Z) + ); + } private void runGui(int width, int height) throws Exception { @@ -101,7 +454,6 @@ public class AsyncPaperDemo { vis.repaint(); fr.repaint(); fr.show(); - synchronized(Demo.class) { Demo.class.wait(); } } }