## slipway ############################################################################
run: slipway.jar
- java -cp slipway.jar edu.berkeley.obits.AtmelSerial < bitstreams/led0.md4
+ java -cp slipway.jar edu.berkeley.slipway.Demo < bitstreams/led0.md4
build/src/com/ftdi/usb/FtdiUart.c: src/com/ftdi/usb/FtdiUart.i
mkdir -p `dirname $@`
public class FakeFpslic extends Fpslic {
+ public FakeFpslic(int width, int height) { super(width, height); }
+
public void mode4(int z, int y, int x, int d) { }
public byte mode4(int z, int y, int x) {
// FIXME
public abstract class Fpslic {
- public static class Util {
- public static int lutSwap(int x) {
- return
- (x & 0x80) |
- ((x & 0x20) << 1) |
- ((x & 0x40) >> 1) |
- (x & 0x10) |
- (x & 0x08) |
- ((x & 0x02) << 1) |
- ((x & 0x04) >> 1) |
- (x & 0x01);
- }
- }
-
- /** issue a command to the device in Mode4 format; see Gosset's documentation for further details */
- public int getWidth() { return 24; }
- public int getHeight() { return 24; }
-
- private static String hex2(int i) {
- String ret = Integer.toString(i, 16);
- while(ret.length() < 2) ret = "0"+ret;
- return ret.toUpperCase();
- }
+ public Fpslic(int width, int height) { this.width = width; this.height = height; }
- public void readMode4(InputStream in) throws IOException {
- int count = 0;
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- for(String str = br.readLine(); str != null; str = br.readLine()) {
- long foo = Long.parseLong(str, 16);
- mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
- count++;
- }
- flush();
- in.close();
- }
+ private int width;
+ private int height;
+ public int getWidth() { return width; }
+ public int getHeight() { return height; }
public abstract void flush();
-
- public void writeMode4(Writer w) throws IOException {
- for(int x=0; x<getWidth(); x++)
- for(int y=0; y<getWidth(); y++)
- for(int z=0; z<255; z++) {
- if ((z > 0x09 && z < 0x10) ||
- (z > 0x11 && z < 0x20) ||
- (z > 0x29 && z < 0x30) ||
- (z > 0x39 && z < 0x40) ||
- (z > 0x41 && z < 0x60) ||
- (z > 0x67 && z < 0x70) ||
- (z > 0x77 && z < 0xD0) ||
- (z > 0xD3))
- continue;
- w.write(hex2(z));
- w.write(hex2(y));
- w.write(hex2(x));
- w.write(hex2(mode4(z, y, x) & 0xff));
- w.write('\n');
- }
- w.flush();
- }
-
-
public abstract void mode4(int z, int y, int x, int d);
public abstract byte mode4(int z, int y, int x);
+
public byte mode4zyx(int zyx) { return mode4(zyx>>24, (zyx>>16)&0xff, (zyx>>8)&0xff); }
public void mode4zyx(int zyx, int d, int invmask) { mode4(zyx>>24, (zyx>>16)&0xff, (zyx>>8)&0xff, d, invmask); }
public void mode4(int z, int y, int x, int d, int invmask) {
mode4(z, y, x, old);
}
- // Fpslic ///////////////////////////////////////////////////////////////////////////////
-
-
+ // Inner Classes ///////////////////////////////////////////////////////////////////////////////
public final class Sector {
public final int col;
public void lut(int xlut, int ylut) { xlut(xlut); ylut(ylut); }
public void xlut(int table) { mode4(7, row, col, (byte)(table & 0xff)); }
public byte xlut() { return (byte)(mode4(7, row, col) & 0xff); }
- public String printXLut() { return printLut(xlut(), "x", "y", "t"); }
- public String printXLutX() { return printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti_source(), "t")); }
+ public String printXLut() { return FpslicUtil.printLut(xlut(), "x", "y", "t"); }
+ public String printXLutX() { return FpslicUtil.printLut(xlut(), str(xi(), "x"), str(yi(), "y"), str(ti_source(), "t")); }
public String str(int x, String def) {
switch(x) {
/* bit positions mean: [MSB] zxy zx_ z_y z__ _xy _x_ __y ___ [LSB] */
public void ylut(int table) { mode4(6, row, col, (byte)(table & 0xff)); }
public byte ylut() { return (byte)(mode4(6, row, col) & 0xff); }
- public String printYLut() { return printLut(ylut(), "y", "x", "t"); }
- public String printYLutX() { return printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti_source(), "t")) + Integer.toString(ylut() & 0xff, 16); }
+ public String printYLut() { return FpslicUtil.printLut(ylut(), "y", "x", "t"); }
+ public String printYLutX() { return FpslicUtil.printLut(ylut(), str(yi(), "y"), str(xi(), "x"), str(ti_source(), "t")) + Integer.toString(ylut() & 0xff, 16); }
public void ff_reset_value(boolean value) {
//mode4( /* FIXME WRONG!!! */, row, col, 3, !value); return;
}
- public static void main(String[] s) throws Exception {
- System.out.println(printLut(0x39, "se", "n", "L0"));
- }
- public static synchronized String printLut(int lut, String xn, String yn, String zn) {
- try {
- File f = File.createTempFile("mvsis", ".mvs");
- f.deleteOnExit();
-
- FileOutputStream fos = new FileOutputStream(f);
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
- pw.println(".model clb");
- pw.println(".inputs "+xn+" "+yn+" "+zn);
- pw.println(".outputs O");
- pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
- for(int i=8; i>=0; i--) {
- int x = ((i & 0x01)!=0 ? 1 : 0);
- int y = ((i & 0x02)!=0 ? 1 : 0);
- int z = ((i & 0x04)!=0 ? 1 : 0);
- pw.print(" "+x+" ");
- pw.print(" "+y+" ");
- pw.print(" "+z+" ");
- //pw.print(" "+(x ^ y)+" ");
- //pw.print(" "+(y ^ z)+" ");
- //pw.print(" "+(z ^ y)+" ");
- pw.print((lut & (1<<i))==0 ? 0 : 1);
- pw.println();
- }
- pw.println(".end");
- pw.flush();
- pw.close();
- Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
- new Gobble("mvsis: ", p.getErrorStream()).start();
- //new Gobble("mvsis: ", p.getInputStream()).start();
- BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
- String ret = br.readLine();
- //f.delete();
- return ret.trim();
- } catch (Exception e) {
- e.printStackTrace();
- return "*mvsis_error*";
- }
- }
-
- public static class Gobble extends Thread {
- private final String header;
- private final BufferedReader br;
- public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
- public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
- public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
- public void run() {
- try {
- for(String s = br.readLine(); s!=null; s=br.readLine())
- System.err.println(header + s);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
}
--- /dev/null
+package com.atmel.fpslic;
+
+import java.io.*;
+import java.util.*;
+
+public class FpslicUtil {
+
+ public static int lutSwap(int x) {
+ return
+ (x & 0x80) |
+ ((x & 0x20) << 1) |
+ ((x & 0x40) >> 1) |
+ (x & 0x10) |
+ (x & 0x08) |
+ ((x & 0x02) << 1) |
+ ((x & 0x04) >> 1) |
+ (x & 0x01);
+ }
+
+ public static void readMode4(InputStream in, Fpslic fpslic) throws IOException {
+ int count = 0;
+ BufferedReader br = new BufferedReader(new InputStreamReader(in));
+ for(String str = br.readLine(); str != null; str = br.readLine()) {
+ long foo = Long.parseLong(str, 16);
+ fpslic.mode4((int)(foo >> 24), (int)(foo >> 16), (int)(foo >> 8), (int)(foo >> 0));
+ count++;
+ }
+ fpslic.flush();
+ in.close();
+ }
+
+ public static void writeMode4(Writer w, Fpslic fpslic) throws IOException {
+ for(int x=0; x<fpslic.getWidth(); x++)
+ for(int y=0; y<fpslic.getWidth(); y++)
+ for(int z=0; z<255; z++) {
+ if ((z > 0x09 && z < 0x10) ||
+ (z > 0x11 && z < 0x20) ||
+ (z > 0x29 && z < 0x30) ||
+ (z > 0x39 && z < 0x40) ||
+ (z > 0x41 && z < 0x60) ||
+ (z > 0x67 && z < 0x70) ||
+ (z > 0x77 && z < 0xD0) ||
+ (z > 0xD3))
+ continue;
+ w.write(hex2(z));
+ w.write(hex2(y));
+ w.write(hex2(x));
+ w.write(hex2(fpslic.mode4(z, y, x) & 0xff));
+ w.write('\n');
+ }
+ w.flush();
+ }
+
+ private static String hex2(int i) {
+ String ret = Integer.toString(i, 16);
+ while(ret.length() < 2) ret = "0"+ret;
+ return ret.toUpperCase();
+ }
+
+ public static synchronized String printLut(int lut, String xn, String yn, String zn) {
+ try {
+ File f = File.createTempFile("mvsis", ".mvs");
+ f.deleteOnExit();
+
+ FileOutputStream fos = new FileOutputStream(f);
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos));
+ pw.println(".model clb");
+ pw.println(".inputs "+xn+" "+yn+" "+zn);
+ pw.println(".outputs O");
+ pw.println(".table "+xn+" "+yn+" "+zn+/*("X_xor_Y X_xor_Z Y_xor_Z")+*/ " -> O");
+ for(int i=8; i>=0; i--) {
+ int x = ((i & 0x01)!=0 ? 1 : 0);
+ int y = ((i & 0x02)!=0 ? 1 : 0);
+ int z = ((i & 0x04)!=0 ? 1 : 0);
+ pw.print(" "+x+" ");
+ pw.print(" "+y+" ");
+ pw.print(" "+z+" ");
+ //pw.print(" "+(x ^ y)+" ");
+ //pw.print(" "+(y ^ z)+" ");
+ //pw.print(" "+(z ^ y)+" ");
+ pw.print((lut & (1<<i))==0 ? 0 : 1);
+ pw.println();
+ }
+ pw.println(".end");
+ pw.flush();
+ pw.close();
+ Process p = Runtime.getRuntime().exec(new String[] { "mvsis", "-c", "simplify;print_factor", f.getAbsolutePath() });
+ new Gobble("mvsis: ", p.getErrorStream()).start();
+ //new Gobble("mvsis: ", p.getInputStream()).start();
+ BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ String ret = br.readLine();
+ //f.delete();
+ return ret.trim();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "*mvsis_error*";
+ }
+ }
+
+ public static class Gobble extends Thread {
+ private final String header;
+ private final BufferedReader br;
+ public Gobble(String header, BufferedReader br) { this.br = br; this.header = header; }
+ public Gobble(String header, Reader r) { this(header, new BufferedReader(r)); }
+ public Gobble(String header, InputStream is) { this(header, new InputStreamReader(is)); }
+ public void run() {
+ try {
+ for(String s = br.readLine(); s!=null; s=br.readLine())
+ System.err.println(header + s);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
-package edu.berkeley.obits;
+package edu.berkeley.slipway;
import edu.berkeley.slipway.*;
import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.device.atmel.*;
-import edu.berkeley.obits.gui.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.gui.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.color.*;
import java.util.*;
import gnu.io.*;
-public class AtmelSerial {
+public class Demo {
//public static boolean mullers = false;
public static boolean mullers = true;
Enumeration e = CommPortIdentifier.getPortIdentifiers();
while(e.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
- Log.info(AtmelSerial.class, "trying " + cpi.getName());
+ 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(AtmelSerial.class, "returning null...");
+ Log.info(Demo.class, "returning null...");
return null;
}
public static int PIPELEN=20;
Fpslic at40k = device;
try {
long begin = System.currentTimeMillis();
- device.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740));
+ FpslicUtil.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740), device);
long end = System.currentTimeMillis();
- Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
+ Log.info(Demo.class, "finished in " + ((end-begin)/1000) + "s");
Thread.sleep(1000);
- Log.info(AtmelSerial.class, "issuing command");
+ Log.info(Demo.class, "issuing command");
//at40k.iob_top(2, true).oe(false);
//at40k.iob_top(2, false).oe(false);
vis.repaint();
fr.repaint();
fr.show();
- synchronized(AtmelSerial.class) { AtmelSerial.class.wait(); }
+ synchronized(Demo.class) { Demo.class.wait(); }
device.flush();
Thread.sleep(3000);
- Log.info(AtmelSerial.class, "issuing command");
+ Log.info(Demo.class, "issuing command");
at40k.iob_top(1, true).pulldown();
device.flush();
*/
- Log.info(AtmelSerial.class, "done");
+ Log.info(Demo.class, "done");
System.exit(0);
} catch (Exception e) { e.printStackTrace(); }
}
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 */
+ if (!falling) c.ylut(FpslicUtil.lutSwap(0x0C)); /* x & !z */
+ else c.ylut(FpslicUtil.lutSwap(0x30)); /* !x & z */
c.xlut(LUT_SELF);
break;
}
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 */
+ if (!invert) cell.xlut(FpslicUtil.lutSwap(0xB8)); /* yo = x ? yi : z => 1011 1000 */
+ else cell.xlut(FpslicUtil.lutSwap(0x74)); /* yo = x ? !yi : z => 0111 0100 */
cell.xi(xi);
cell.yi(yi);
}
public OutputStream getOutputStream() { return out; }
public FtdiBoard() throws Exception {
+ super(24, 24);
chip = new FpslicBoot(new FpslicBootPinsUsb(new FtdiUart(0x6666, 0x3133, 1500 * 1000)));
String bstFile = this.getClass().getName();
bstFile = bstFile.substring(0, bstFile.lastIndexOf('.'));
-package edu.berkeley.obits.gui;
+package edu.berkeley.slipway.gui;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import edu.berkeley.obits.device.atmel.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
-package edu.berkeley.obits.gui;
+package edu.berkeley.slipway.gui;
import com.atmel.fpslic.*;
import edu.berkeley.slipway.*;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import edu.berkeley.obits.device.atmel.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
-import static edu.berkeley.obits.gui.GuiConstants.*;
+import static edu.berkeley.slipway.gui.GuiConstants.*;
public class Gui extends ZoomingPanel implements KeyListener, MouseMotionListener {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(this);
Writer pw = new OutputStreamWriter(new FileOutputStream(fc.getSelectedFile()));
- drone.writeMode4(pw);
+ FpslicUtil.writeMode4(pw, drone);
pw.flush();
pw.close();
System.err.println("done writing");
try {
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showOpenDialog(this);
- drone.readMode4(new FileInputStream(fc.getSelectedFile()));
+ FpslicUtil.readMode4(new FileInputStream(fc.getSelectedFile()), drone);
System.err.println("done reading");
repaint();
} catch (Exception e) {
public void scan(final Gui.Cell c) {
try {
final Fpslic.Cell cell = c.cell;
- AtmelSerial.scan(at40k, cell, NONE, true);
+ Demo.scan(at40k, cell, NONE, true);
boolean safe = !cell.fb_relevant();
if (cell.xo()) safe = false;
if (cell.yo()) safe = false;
}
}
- AtmelSerial.scan(at40k, cell, NONE, false);
+ Demo.scan(at40k, cell, NONE, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
-package edu.berkeley.obits.gui;
+package edu.berkeley.slipway.gui;
import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import edu.berkeley.obits.device.atmel.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
-package edu.berkeley.obits.gui;
+package edu.berkeley.slipway.gui;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import edu.berkeley.obits.device.atmel.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
-package edu.berkeley.obits.gui;
+package edu.berkeley.slipway.gui;
import com.atmel.fpslic.*;
import static com.atmel.fpslic.FpslicConstants.*;
-import static com.atmel.fpslic.Fpslic.Util.*;
-import edu.berkeley.obits.*;
-import edu.berkeley.obits.device.atmel.*;
+import static com.atmel.fpslic.FpslicUtil.*;
+import edu.berkeley.slipway.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;