From 57f6ad104a6e2bf0433a86f5c8e1f31c1715dab9 Mon Sep 17 00:00:00 2001 From: adam Date: Fri, 22 Sep 2006 12:15:56 +0100 Subject: [PATCH] checkpoint --- bitstreams/slipway_drone.bst | 2 +- src/edu/berkeley/slipway/Demo.java | 509 +---------------------------- src/edu/berkeley/slipway/FtdiBoard.java | 112 +++---- src/edu/berkeley/slipway/FtdiBoardSlave.c | 2 +- src/edu/berkeley/slipway/SerialBoard.java | 16 + src/edu/berkeley/slipway/gui/Gui.java | 3 +- 6 files changed, 76 insertions(+), 568 deletions(-) diff --git a/bitstreams/slipway_drone.bst b/bitstreams/slipway_drone.bst index 1262189..4774557 100644 --- a/bitstreams/slipway_drone.bst +++ b/bitstreams/slipway_drone.bst @@ -1884,7 +1884,7 @@ 01000010 00001000 10001111 -11100110 +11100011 00001001 10100110 01000000 diff --git a/src/edu/berkeley/slipway/Demo.java b/src/edu/berkeley/slipway/Demo.java index 4fb97ac..cff81c4 100644 --- a/src/edu/berkeley/slipway/Demo.java +++ b/src/edu/berkeley/slipway/Demo.java @@ -15,22 +15,9 @@ import gnu.io.*; public class Demo { - //public static boolean mullers = false; public static boolean mullers = true; public static int masterx = 1; - public static SerialPort detectObitsPort() throws Exception { - Enumeration e = CommPortIdentifier.getPortIdentifiers(); - while(e.hasMoreElements()) { - CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); - Log.info(Demo.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()); - } - Log.info(Demo.class, "returning null..."); - return null; - } + public static int PIPELEN=20; public static void main(String[] s) throws Exception { FtdiBoard device = new FtdiBoard(); @@ -516,12 +503,13 @@ public class Demo { + /* Visualizer v = new Visualizer(at40k, device); v.show(); v.setSize(1380, 1080); Fpslic.Cell cell = at40k.cell(4, 23); - - Image img = v.createImage(v.getWidth(), v.getHeight()); + */ + //Image img = v.createImage(v.getWidth(), v.getHeight()); /* int x = 1; int y = 14; @@ -537,14 +525,14 @@ public class Demo { //int y = 11; //selfTest(device, at40k, v); - System.out.println("save: " + FtdiBoard.save + " of " + (FtdiBoard.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); at40k.iob_bot(0, true).enableOutput(NORTH); for(int i=0; i<10000; i++) { - v.refresh(); + //v.refresh(); try { Thread.sleep(100); } catch (Exception e) { } } //cell.ylut(0x09); @@ -728,419 +716,6 @@ public class Demo { cell.t(false, false, true); } - public static class Visualizer extends Frame implements KeyListener, MouseMotionListener, MouseListener { - public static final int WIDTH = 40; - public static final int HEIGHT = 40; - public static final int LW = 15; - 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 Fpslic dev; - private final FtdiBoard drone; - int selx = -1; - int sely = -1; - public Visualizer(final Fpslic dev, final FtdiBoard drone) { - this.dev = dev; - this.drone = drone; - show(); - addMouseMotionListener(this); - addMouseListener(this); - addKeyListener(this); - new Thread() { - public void run() { - try { - while(true) { - Thread.sleep(500); - if (!enabled) continue; - /* - Fpslic.Cell cell = dev.cell(21, 22); - cell.xlut(0xff); - cell.ylut(0xff); - */ - keyPressed(null); - /* - cell.xlut(0x00); - cell.ylut(0x00); - */ - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }.start(); - } - public boolean enabled = false; - public void mouseClicked(MouseEvent e) { } - public void mouseEntered(MouseEvent e) { } - public void mouseExited(MouseEvent e) { } - public void mouseReleased(MouseEvent e) { - } - public void keyTyped(KeyEvent k) { - } - public void keyReleased(KeyEvent k) { - } - public void keyPressed(KeyEvent keyevent) { - boolean scan = false; - switch(keyevent==null ? '_' : keyevent.getKeyChar()) { - case '1': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.xlut(0xff); - cell.ylut(0xff); - drawCell(getGraphics(), selx, sely); - drone.flush(); - break; - } - case 'i': { - System.out.println("interrupt_count: " + drone.readCount()); - break; - } - case 'x': { - masterx+=2; - if (mullers) { - if (masterx <= 22) { - int mx = masterx; - System.out.println("low => " + mx); - copy(dev.cell(mx, yofs-2), NORTH, NORTH); - copy(dev.cell(mx, yofs-3), NORTH, NORTH); - //dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut()); - //dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut()); - } else { - int mx = 23-(masterx-23); - System.out.println("high => " + mx); - copy(dev.cell(mx, yofs), NW, NW);//NORTH, NORTH); - copy(dev.cell(mx, yofs-1), NORTH, NORTH); - //for(int x=mx-1; x>=1; x--) - //copy(dev.cell(x, yofs), EAST, EAST); - for(int y=yofs+1; y<=23; y++) - copy(dev.cell(1, y), SOUTH, SOUTH); - //dev.cell(mx, yofs-1).ylut(~dev.cell(mx, yofs-1).ylut()); - //dev.cell(mx, yofs-1).xlut(~dev.cell(mx, yofs-1).xlut()); - } - } else { - if (masterx <= 22) { - int mx = masterx; - System.out.println("low => " + mx); - copy(dev.cell(mx, yofs-2), SOUTH, SOUTH); - copy(dev.cell(mx, yofs-3), NORTH, NORTH); - dev.cell(mx, yofs-3).ylut(~dev.cell(mx, yofs-3).ylut()); - dev.cell(mx, yofs-3).xlut(~dev.cell(mx, yofs-3).xlut()); - } else { - int mx = 23-(masterx-23); - System.out.println("high => " + mx); - copy(dev.cell(mx, yofs), SOUTH, SOUTH); - /* - copy(dev.cell(mx, yofs-1), NORTH, NORTH); - */ - copy(dev.cell(mx, yofs-1), NORTH, SW); - boolean left = true; - 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); - copy(lc = dev.cell(left?(mx-1):mx, y-1), NORTH, left?SE:SW); - left = !left; - } - copy(lc, NORTH, NORTH); - - //for(int x=mx-1; x>=1; x--) - //copy(dev.cell(x, yofs), EAST, EAST); - //for(int y=yofs+1; y<=23; y++) - //copy(dev.cell(1, y), SOUTH, SOUTH); - - if (mx<21) { - dev.cell(mx+2, yofs).ylut(0x00); - dev.cell(mx+2, yofs).xlut(0x00); - } - - /* - dev.cell(mx, yofs-1).ylut(~LUT_Z); - dev.cell(mx, yofs-1).xlut(LUT_Z); - loopback(dev.cell(mx, yofs-1), YLUT); - */ - dev.cell(mx, yofs).ylut(~LUT_SELF); - dev.cell(mx, yofs).xlut(~LUT_OTHER); - } - } - break; - } - case ' ': { - //enabled = !enabled; - scan = true; - break; - } - case '4': { - //enabled = !enabled; - try { - for(int cap=0; cap<15; cap++) { - drain(dev, drone); - try { Thread.sleep(100); } catch (Exception e) { } - //showit(dev, drone, this); - fill(dev, drone, cap); - drone.readCount(); - long now = System.currentTimeMillis(); - try { Thread.sleep(4000); } catch (Exception e) { } - int count = drone.readCount(); - long now2 = System.currentTimeMillis(); - System.out.println(cap + " , " + (((float)count * (2*2*2*2*2*2*2*2*2*1000))/(now2-now))); - } - } catch (Exception e) { e.printStackTrace(); } - break; - } - case 'C': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.ylut(0xB2); - drawCell(getGraphics(), selx, sely); - break; - } - case '0': { - if (selx==-1 || sely==-1) break; - Fpslic.Cell cell = dev.cell(selx, sely); - cell.xlut(0x00); - cell.ylut(0x00); - drawCell(getGraphics(), selx, sely); - drone.flush(); - break; - } - } - if (!scan) return; - showit(dev, drone, this); - } - public void mousePressed(MouseEvent e) { - final Fpslic.Cell cell = dev.cell(selx, sely); - if (cell==null) return; - final int old = cell.c(); - FtdiBoard.ByteCallback bc = new FtdiBoard.ByteCallback() { - public void call(byte b) throws Exception { - boolean y = (b & 0x80) != 0; - //cell.c(old); - Graphics g = getGraphics(); - g.setFont(new Font("sansserif", Font.BOLD, 14)); - g.setColor(Color.white); - //g.drawString("X=0", left(cell) + 10, top(cell) + 20); - //g.drawString("X=1", left(cell) + 10, top(cell) + 20); - //g.setColor(Color.white); - //g.drawString("Y=0", left(cell) + 8, top(cell) + 35); - //g.drawString("Y=1", left(cell) + 8, top(cell) + 35); - //g.setColor(RED); - //g.drawString("X="+(x?"1":"0"), left(cell) + 10, top(cell) + 20); - String v = (cell.c()==YLUT ? "Y" : cell.c()==XLUT ? "X" : "C"); - g.drawString(v+"="+(y?"0":"1"), left(cell) + 8, top(cell) + 35); - g.setColor(BLUE); - g.drawString(v+"="+(y?"1":"0"), left(cell) + 8, top(cell) + 35); - } }; - 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) { - int x = e.getX(); - int y = e.getY(); - if (selx >= 0 && selx < 24 && sely >= 0 && sely < 24) { - int cx = selx; - int cy = sely; - Fpslic.Cell cell = dev.cell(cx, cy); - selx = -1; - sely = -1; - /* - drawCell(getGraphics(), cx, cy); - drawSector(getGraphics(), dev.cell(cx, cy).sector()); - */ - } - selx = (x-20)/(WIDTH+2); - sely = (23 - (y-20)/(HEIGHT+2))+1; - /* - 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 void mouseDragged(MouseEvent e) { mousePressed(e); } - public void paint(Graphics g) { - System.out.println("paintall"); - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - g.setFont(new Font("sansserif", Font.BOLD, 24)); - for(int x=0; x<24; x++) - for(int y=0; y<24; y++) - drawCell(g,x,y); - for(int x=0; x<=23; x+=4) - for(int y=23; y>=0; y-=4) - drawSector(g, dev.cell(x, y).sector()); - /* - g.setColor(BLUE); - g.drawString("Ready", (5*(WIDTH+2))+20, 40); - g.setColor(RED); - g.drawString("Send", (3*(WIDTH+2))+20, 40); - g.setColor(BLUE); - */ - refresh(); - } - public void refresh() { - Graphics g = getGraphics(); - /* - int data = drone.readBus() & 0xff; - for(int i=0; i<8; i++) { - g.setColor((data & (1<i) return s; return "0"+pad((i-1),s); } public static String bin8(byte b) { @@ -1151,40 +726,6 @@ public class Demo { return ret; } - 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++) { - Fpslic.Cell cell = at40k.cell(x,y); - scan(at40k, cell, YLUT, true); - //v.paint(img.getGraphics()); - //v.getGraphics().drawImage(img, 0, 0, null); - cell.ylut(0xff); - boolean a = (device.readBus() & 0x80)!=0; - cell.ylut(0x00); - boolean b = (device.readBus() & 0x80)!=0; - if (a & !b) { - //System.out.println("pass " + x+","+y); - Graphics g = v.getGraphics(); - g.setColor(Color.green); - g.drawString("pass", v.left(cell) + 10, v.top(cell) + 20); - } else { - System.out.println("FAIL!!!! " + x+","+y+" => " + a + " " + b); - fail++; - Graphics g = v.getGraphics(); - g.setColor(Color.red); - g.drawString("FAIL", v.left(cell) + 10, v.top(cell) + 20); - } - scan(at40k, cell, YLUT, false); - } - - System.out.println("failures: " + fail); - System.out.println("scan time: " + (System.currentTimeMillis()-now) + "ms"); - */ - } - public static void bounce(Fpslic.Cell cell, int xi, int yi) { cell.xlut((byte)0xCC); cell.ylut((byte)0xCC); @@ -1248,6 +789,7 @@ public class Demo { cell.xo(false); cell.c(cin); } + public static void doit(Fpslic at40k, FtdiBoard device) throws Exception { Fpslic.Cell led = at40k.cell(1, 23); @@ -1446,6 +988,7 @@ public class Demo { //at40k.iob_top(1, false).slew(SLOW); } + public static void fill(Fpslic at40k, FtdiBoard device, int num) throws Exception { //muller(at40k.cell(PIPELEN,22), NE, WEST); Fpslic.Cell a = at40k.cell(10,22); @@ -1463,40 +1006,7 @@ public class Demo { b.ylut(0xB2); a.ylut(0xB2); } - 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)); - final Color red = new Color(0xff, 0x99, 0x99); - final Color green = new Color(0x99, 0xff, 0x99); - for(int xx=0; xx<=22; xx++) { - for(int yy=23; yy>=0; yy--) { - //for(int xx=5; xx<=PIPELEN-1; xx++) { - //for(int yy=21; yy<=22; yy++) { - final int x = xx; - final int y = yy; - final Fpslic.Cell cell = dev.cell(x, y); - if ((cell.ylut()&0xff)!=0xB2) continue; - 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); - //if (x==PIPELEN-1 && y==22) System.out.println("time: " + (System.currentTimeMillis()-then)); - } - }; - scan(dev, cell, NONE, true); - 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); - } - } - } - } + public static void drain(Fpslic at40k, FtdiBoard device) throws Exception { Fpslic.Cell a = at40k.cell(10,22); Fpslic.Cell b = at40k.cell(11,22); @@ -1514,6 +1024,7 @@ public class Demo { b.ylut(0xB2); a.ylut(0xB2); } + public static void doitx(Fpslic at40k, FtdiBoard device) throws Exception { for(int i=5; i= i) return s; - return "0"+pad(s, i-1); - } - // AvrDrone leftovers ////////////////////////////////////////////////////////////////////////////// @@ -94,6 +86,7 @@ public class FtdiBoard extends Fpslic implements Board { public void run() { while(true) { try { + while(callbacks.size() == 0) Thread.sleep(500); byte b = in.readByte(); ByteCallback bc = (ByteCallback)callbacks.remove(0); bc.call(b); @@ -105,21 +98,49 @@ public class FtdiBoard extends Fpslic implements Board { }.start(); } - public synchronized void scanFPGA(boolean on) throws IOException { - if (on) { - out.writeByte(3); - out.flush(); - } else { - // FIXME + + // Programming /////////////////////////////////////////////////////////////////////////////// + + private byte[][][] cache = new byte[24][][]; + public 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]; + } + + public void mode4(int z, int y, int x, int d) { + try { + 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); + + out.writeByte(1); + out.writeByte(z); + out.writeByte(y); + out.writeByte(x); + out.writeByte(d); + } catch (IOException e) { + throw new RuntimeException(e); } } - // fixme! - public static int retval = 0; + + public void flush() { try { out.flush(); } catch (IOException e) { throw new RuntimeException(e); } } + + + // Callbacks ////////////////////////////////////////////////////////////////////////////// + + private Vector callbacks = new Vector(); + + public static abstract class ByteCallback { + public int result; + public abstract void call(byte b) throws Exception; + } + public synchronized int readCount() { try { ByteCallback bc = new ByteCallback() { public synchronized void call(byte b) throws Exception { - retval = + result = ((b & 0xff) << 24) | ((in.read() & 0xff) << 16) | ((in.read() & 0xff) << 8) | @@ -129,20 +150,14 @@ public class FtdiBoard extends Fpslic implements Board { }; synchronized(bc) { callbacks.add(bc); - out.writeByte(6); + out.writeByte(3); out.flush(); bc.wait(); } - return retval; + return bc.result; } catch (Exception e) { throw new RuntimeException(e); } } - public static interface ByteCallback { - public void call(byte b) throws Exception; - } - - private Vector callbacks = new Vector(); - public synchronized void readBus(ByteCallback bc) throws IOException { callbacks.add(bc); out.writeByte(2); @@ -151,50 +166,17 @@ public class FtdiBoard extends Fpslic implements Board { public synchronized void readInterrupts(ByteCallback bc) throws IOException { callbacks.add(bc); - out.writeByte(6); + out.writeByte(3); out.flush(); } - 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); - } - } + // Util ////////////////////////////////////////////////////////////////////////////// private String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); } + public static String pad(String s, int i) { + if (s.length() >= i) return s; + return "0"+pad(s, i-1); + } } diff --git a/src/edu/berkeley/slipway/FtdiBoardSlave.c b/src/edu/berkeley/slipway/FtdiBoardSlave.c index 8429018..b5dd1a3 100644 --- a/src/edu/berkeley/slipway/FtdiBoardSlave.c +++ b/src/edu/berkeley/slipway/FtdiBoardSlave.c @@ -202,7 +202,7 @@ int main() { send(readFPGA()); break; - case 6: { + case 3: { int32_t local_interrupt_count = interrupt_count; interrupt_count = 0; send((local_interrupt_count >> 24) & 0xff); diff --git a/src/edu/berkeley/slipway/SerialBoard.java b/src/edu/berkeley/slipway/SerialBoard.java index 3a99c03..bc3f41a 100644 --- a/src/edu/berkeley/slipway/SerialBoard.java +++ b/src/edu/berkeley/slipway/SerialBoard.java @@ -43,4 +43,20 @@ public class SerialBoard implements Board { public InputStream getInputStream() { return in; } public OutputStream getOutputStream() { return out; } + + /* + public static SerialPort detectObitsPort() throws Exception { + Enumeration e = CommPortIdentifier.getPortIdentifiers(); + while(e.hasMoreElements()) { + CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement(); + Log.info(Demo.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()); + } + Log.info(Demo.class, "returning null..."); + return null; + } + */ } diff --git a/src/edu/berkeley/slipway/gui/Gui.java b/src/edu/berkeley/slipway/gui/Gui.java index 7ef21b3..37bfaf5 100644 --- a/src/edu/berkeley/slipway/gui/Gui.java +++ b/src/edu/berkeley/slipway/gui/Gui.java @@ -755,7 +755,7 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene int made = 0; - private class BCB implements FtdiBoard.ByteCallback { + private class BCB extends FtdiBoard.ByteCallback { Gui.Cell c; int who; public BCB(Gui.Cell c, int who) { @@ -923,7 +923,6 @@ public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListene public boolean result(boolean x, boolean y, boolean z) { return z ? x : y; } } - public abstract class Buf extends Gate { public void makePath(GeneralPath gp) { gp.moveTo(0, 15); -- 1.7.10.4