distinguish topleft cell
[slipway.git] / src / edu / berkeley / slipway / AsyncPaperDemo.java
index d41a59f..7bea5ba 100644 (file)
@@ -24,7 +24,7 @@ public class AsyncPaperDemo {
     Fpslic.Cell start;
     public void main(String[] s) throws Exception {
 
-        turnOnLeds();
+        //turnOnLeds();
         setupScanCell();
 
         //runGui(24, 24);
@@ -33,22 +33,28 @@ public class AsyncPaperDemo {
             fpslic.readCount();
 
         //System.in.read();
-        for(int i=46; i<400; i+=2) {
+        for(int i=16; i<400; i+=2) {
             go(i);
         }
-        System.out.println("done");
+        //System.out.println("done");
 
     }
 
     public void go(int size) throws Exception {
         start = fpslic.cell(20, 21);
-        int rsize = size-createPipeline(start, true, size, false);
+        int rsize = size-createPipeline(start, true, size-4, 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 div = start.east();
+        while(true) {
+            divider(div);
+            if (div.south()==null || div.south().south()==null) break;
+            div = div.south().south();
+        }
+        div = div.south().east();
+        div.east().yo(div);
+        //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));
 
@@ -56,14 +62,11 @@ public class AsyncPaperDemo {
         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<rsize/2+1; i++) test(i, rsize, outfile);
             for(int i=rsize/2; i>=0; i--) test(i, rsize, outfile);
             outfile.flush();
             outfile.close();
@@ -88,59 +91,56 @@ public class AsyncPaperDemo {
         long then = System.currentTimeMillis();
 
         int tokens = fpslic.readCount();
-        double elapsed = (double)((FtdiBoard)fpslic).timer;
+
+        int clockrate = 24; // (in mhz)
+        double elapsed = (double)((((FtdiBoard)fpslic).timer)/clockrate);
         
         double occupancy = ((double)(2*count))/((double)size);
 
-        //double elapsed = (then-now);
-        double result = (tokens*1000)/elapsed;
+        // eleven dividers... ...and the interrupt pin counts *pairs* of transitions
+        int multiplier = 2*2*2*2*2*2*2*2*2*2*2*2;
+
+        int clockdivisor = 64;
+        multiplier /= clockdivisor;
 
-        // eleven dividers...
-        //result *= 2*2*2*2*2*2*2*2*2*2*2;
+        double result = (tokens*multiplier)/elapsed; // in millions
 
-        // ...and the interrupt pin counts *pairs* of transitions
-        //result *= 2;
 
         // result is transitions/sec => 633mcell/sec velocity! =)
         outfile.println(occupancy + ", " + result);
-        System.out.println((2*count)+"/"+size+"  "+occupancy + ", " + result + " @ " + elapsed);
+        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<size*4; i++) {
-            topLeft().ylut(0xff);
+            topLeft().xlut(0x00);
+            for(int i=0; i<size*4; i++) {
+                topLeft().ylut(0xff);
+                topLeft().ylut(0x00);
+            }
+            
             fpslic.flush();
-            topLeft().ylut(0x00);
+            fpslic.readCount();
+            try { Thread.sleep(100); } catch (Exception e) { }
+            int rc = fpslic.readCount();
+            if (rc!=0) { System.err.println("flush() failed REALLY BADLY => " + rc); continue; }
+            
+            reconfigTopLeft();
+            for(int x=0; x<24; x++)
+                for(int y=0; y<24; y++)
+                    fpslic.cell(x,y).wi(L0);
             fpslic.flush();
-        }
-
-        fpslic.flush();
-        fpslic.readCount();
-        fpslic.readCount();
-        try { Thread.sleep(100); } catch (Exception e) { }
-        int rc = fpslic.readCount();
-        if (rc!=0) {
-            System.err.println("flush() failed REALLY BADLY => " + 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;
+            for(int x=0; x<24; x++)
+                for(int y=0; y<24; y++)
+                    fpslic.cell(x,y).wi(NONE);
+            fpslic.flush();
+            
+            fpslic.readCount();
+            try { Thread.sleep(100); } catch (Exception e) { }
+            rc = fpslic.readCount();
+            if (rc!=0) { System.err.println("flush() failed => " + rc); continue; }
+            break;
         }
     }
 
@@ -149,16 +149,21 @@ public class AsyncPaperDemo {
         if (count>0)
             topLeft().ylut(0x00);
         boolean yes = true;
-        for(int i=0; i<count; i++) {
+        if (count==1) {
+            topLeft().xlut(0x00);
+            yes = true;
+        } else {
+            for(int i=0; i<count-1; i++) {
                 if (yes) {
                     topLeft().xlut(0xff);
                 } else {
                     topLeft().xlut(0x00);
                 }
                 fpslic.flush();
-            yes = !yes;
+                yes = !yes;
             //System.out.println("fill => " + yes);
             //try { Thread.sleep(500); } catch (Exception _) { }
+            }
         }
         //System.out.println("done filling.");
         //try { Thread.sleep(2000); } catch (Exception _) { }
@@ -167,7 +172,7 @@ public class AsyncPaperDemo {
         //try { System.in.read(); }  catch (Exception _) { }
 
 
-        if (count>0 && count<size/2-1) {
+        if (count>0 && count!=size/2-1) {
             reconfigTopLeftPreserve(yes);
         } else if (count>0) {
             topLeft().xlut(0xff);
@@ -240,8 +245,8 @@ public class AsyncPaperDemo {
         do {
         if (downward) {
             if (c.row < 6) {
-                if (length < 10+4) { stop = true; break; }
-                length -= 10;
+                if (length < 8+4) { stop = true; break; }
+                length -= 8;
                 c = pipe(c, c.north(), new int[] { SW, EAST, SW, WEST, NW, NORTH });
                 c = c.se();
                 c = pipe(c, c.north(), new int[] { NE, NORTH });
@@ -263,8 +268,8 @@ public class AsyncPaperDemo {
             }
         } else {
             if (c.row > c.fpslic().getHeight()-7) {
-                if (length < 10+4) { stop = true; break; }
-                length -= 10;
+                if (length < 8+4) { stop = true; break; }
+                length -= 8;
                 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 });
@@ -329,8 +334,6 @@ public class AsyncPaperDemo {
     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)) {
@@ -341,6 +344,14 @@ public class AsyncPaperDemo {
                     c.xi(prev);
                 }
 
+        if (c.row==topLeft().row && c.col==topLeft().col) {
+            c.yo(false);
+            c.xo(false);
+        } else {
+            c.yo(false);
+            c.xo(true);
+        }
+
                 c.c(YLUT);
                 c.ylut(0x00);
                 c.xlut(0x00);
@@ -363,7 +374,12 @@ public class AsyncPaperDemo {
                     c.yi(prev);
                 }
 
-                c.c(XLUT);
+        c.yo(true);
+        c.xo(true);
+        c.c(ZMUX);
+        c.zi(NONE);
+
+        //c.c(XLUT);
                 c.xlut(0x00);
                 c.ylut(0x00);
                 c.wi(L0);
@@ -382,6 +398,7 @@ public class AsyncPaperDemo {
         return next;
     }
 
+    /*
     private void turnOnLeds() {
         for(int i=0; i<24; i++) {
             //fpslic.iob_bot(i, true).enableOutput(NORTH);
@@ -390,7 +407,7 @@ public class AsyncPaperDemo {
             fpslic.cell(i, 0).ylut(0xff);
         }
     }
-
+    */
     private void setupScanCell() {
         fpslic.cell(23,15).h(3, true);
         fpslic.cell(23,15).yi(L3);