checkpoint
[slipway.git] / src / edu / berkeley / obits / AtmelSerial.java
index cffe6c7..dd37793 100644 (file)
@@ -1,7 +1,8 @@
 package edu.berkeley.obits;
 
-import static edu.berkeley.obits.device.atmel.AtmelDevice.Constants.*;
-import static edu.berkeley.obits.device.atmel.AtmelDevice.Util.*;
+import edu.berkeley.slipway.*;
+import static com.atmel.fpslic.Fpslic.Constants.*;
+import static com.atmel.fpslic.Fpslic.Util.*;
 import edu.berkeley.obits.device.atmel.*;
 import edu.berkeley.obits.gui.*;
 import java.awt.*;
@@ -22,28 +23,23 @@ public class AtmelSerial {
         while(e.hasMoreElements()) {
             CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
             Log.info(AtmelSerial.class, "trying " + cpi.getName());
-            if (cpi.getName().startsWith("/dev/cu.usbserial-")) return new RXTXPort(cpi.getName());
-            if (cpi.getName().startsWith("/dev/ttyS0")) return new RXTXPort(cpi.getName());
+            if (cpi.getName().startsWith("/dev/cu.usbserial-"))
+                return new RXTXPort(cpi.getName());
+            if (cpi.getName().startsWith("/dev/ttyS0"))
+                return new RXTXPort(cpi.getName());
         }
         Log.info(AtmelSerial.class, "returning null...");
         return null;
     }
     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(detectObitsPort());
+        //AvrDrone device = new AvrDrone();
+        AvrDrone device = new AvrDrone(new FtdiBoard());
         At40k at40k = new At40k.At40k10(device);
-        int count = 0;
         try {
             long begin = System.currentTimeMillis();
-            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
-            for(String str = br.readLine(); str != null; str = br.readLine()) {
-                long foo = Long.parseLong(str, 16);
-                device.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >>  8), (int)(foo >>  0));
-                count++;
-                if (count % 100 == 0) Log.info(AtmelSerial.class, "wrote " + count + " configuration octets");
-            }
-            device.flush();
+            device.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740));
             long end = System.currentTimeMillis();
             Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
             Thread.sleep(1000);
@@ -402,8 +398,15 @@ public class AtmelSerial {
             c.out(L2, true);
             c.out(L3, true);
             c.out(L4, true);
+            c.xo(true);
+            c.yo(true);
             c.c(ZMUX);
 
+            at40k.cell(9,10).xo(true);
+            at40k.cell(9,10).yo(true);
+            at40k.cell(9,10).c(YLUT);
+            at40k.cell(9,10).b(false);
+
             //for(int x=5; x<PIPELEN; x++) {
             //at40k.cell(x,23).hwire(L0).drives(at40k.cell(x,23).hwire(L0).east());
             //}
@@ -492,21 +495,34 @@ public class AtmelSerial {
             at40k.cell(6,13).yo(false);
             at40k.cell(7,12).xi(SE);
 
-            Gui vis = new Gui(at40k);
+            for(int i=0; i<24; i++) {
+                at40k.iob_bot(i, true).enableOutput(NORTH);
+                at40k.iob_bot(i, false).enableOutput(NW);
+                at40k.cell(i, 0).xlut(0xff);
+                at40k.cell(i, 0).ylut(0xff);
+            }
+
+            device.flush();
+
+            Gui vis = new Gui(at40k, device);
             Frame fr = new Frame();
+            fr.addKeyListener(vis);
             fr.setLayout(new BorderLayout());
             fr.add(vis, BorderLayout.CENTER);
             fr.pack();
+            fr.setSize(900, 900);
+            vis.repaint();
+            fr.repaint();
             fr.show();
-            fr.setSize(600, 600);
-            fr.addKeyListener(vis);
             synchronized(AtmelSerial.class) { AtmelSerial.class.wait(); }
 
 
+
             Visualizer v = new Visualizer(at40k, device);
             v.show();
             v.setSize(1380, 1080);
             At40k.Cell cell = at40k.cell(4, 23);
+
             Image img = v.createImage(v.getWidth(), v.getHeight());
             /*
             int x = 1;
@@ -623,8 +639,8 @@ public class AtmelSerial {
             if (source != NONE) cell.c(source);
             if (cell.b()) cell.b(false);
             if (cell.f()) cell.f(false);
-            if (!cell.out(L3)) cell.out(L3, true);
         }
+        if (cell.out(L3)!=setup) cell.out(L3, setup);
         if (cell.vx(L3)!=setup) cell.v(L3, setup);
 
         At40k.SectorWire sw = cell.vwire(L3);
@@ -774,6 +790,7 @@ public class AtmelSerial {
                     cell.xlut(0xff);
                     cell.ylut(0xff);
                     drawCell(getGraphics(), selx, sely);
+                    drone.flush();
                     break;
                 }
                 case 'i': {
@@ -885,6 +902,7 @@ public class AtmelSerial {
                     cell.xlut(0x00);
                     cell.ylut(0x00);
                     drawCell(getGraphics(), selx, sely);
+                    drone.flush();
                     break;
                 }
             } 
@@ -914,11 +932,15 @@ public class AtmelSerial {
                         g.setColor(BLUE);
                         g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35);
                     } };
-            scan(dev, cell, NONE, true);
-            drone.readBus(bc);
-            //scan(dev, cell, XLUT, true);
-            //boolean x = (drone.readBus() & 0x80) != 0;
-            scan(dev, cell, NONE, false);
+            try {
+                scan(dev, cell, NONE, true);
+                drone.readBus(bc);
+                //scan(dev, cell, XLUT, true);
+                //boolean x = (drone.readBus() & 0x80) != 0;
+                scan(dev, cell, NONE, false);
+            } catch (IOException ex) {
+                throw new RuntimeException(ex);
+            }
         }
 
         public void mouseMoved(MouseEvent e) {
@@ -1465,11 +1487,15 @@ public class AtmelSerial {
                         }
                     };
                 scan(dev, cell, NONE, true);
-                drone.readBus(bc);
-                //scan(dev, cell, YLUT, false);
-                cell.v(L3, false);
-                dev.cell(x, 15).h(L3, false);
-                dev.cell(x, 15).v(L3, false);
+                try {
+                    drone.readBus(bc);
+                    //scan(dev, cell, YLUT, false);
+                    cell.v(L3, false);
+                    dev.cell(x, 15).h(L3, false);
+                    dev.cell(x, 15).v(L3, false);
+                } catch (IOException ex) {
+                    throw new RuntimeException(ex);
+                }
             }
         }
     }