--- /dev/null
+package com.megacz.eltron;
+
+import org.ibex.util.*;
+import org.ibex.graphics.*;
+import java.io.*;
+import java.util.*;
+import gnu.io.*;
+
+public class Eltron {
+
+ public static SerialPort detectObitsPort() throws Exception {
+ Enumeration e = CommPortIdentifier.getPortIdentifiers();
+ while(e.hasMoreElements()) {
+ CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
+ Log.info(Eltron.class, "detected " + cpi.getName());
+ if (cpi.getName().indexOf("usbserial")!=-1) {
+ SerialPort ret = new RXTXPort(cpi.getName());
+ Log.info(Eltron.class, "returning " + ret);
+ return ret;
+ }
+ }
+ SerialPort ret = new RXTXPort("/dev/ttyS0");
+ Log.info(Eltron.class, "returning " + ret);
+ return ret;
+ }
+
+ public static void main(String[] s) throws Exception {
+ SerialPort sp = detectObitsPort();
+ //sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
+
+ sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
+ //sp.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
+ //sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
+ OutputStream out = sp.getOutputStream();
+ InputStream in = sp.getInputStream();
+ int count = 0;
+ PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
+ pw.println();
+ pw.flush();
+
+ /*
+ System.out.println("rebooting device...");
+ pw.println("^@");
+ pw.println("^@");
+ pw.println("^@");
+ pw.flush();
+ System.out.println("rebooted.");
+ try { Thread.sleep(3000); } catch (Exception e) { }
+ System.out.println("setting comm parameters...");
+ pw.println();
+ pw.flush();
+ pw.println();
+ pw.println("Y38,N,8,1");
+ pw.flush();
+ System.out.println("set.");
+ try { Thread.sleep(2000); } catch (Exception e) { }
+ System.exit(0);
+ */
+
+ pw.println("^@");
+ pw.println("^@");
+ pw.println("^@");
+ pw.flush();
+ try { Thread.sleep(2000); } catch (Exception e) { }
+
+ pw.println("OD");
+ pw.println("N");
+ pw.println("D14");
+ pw.println("S1");
+ //pw.println("Q609,24");
+ pw.println("q780");
+ //pw.println("R0,0");
+
+ //int MAXWIDTH = 200 * 4 - 10;
+ //int MAXHEIGHT = 200 * 6 - 10;
+ int MAXWIDTH = 200 * 5 - 10;
+ int MAXHEIGHT = 200 * 7 - 10;
+ Picture p = new Picture(System.in);
+ int[] data = p.data;
+ int owidth = ((int)Math.floor(Math.min(MAXWIDTH, p.height)/8.0)) * 8; // FIXME: should be ceil
+ int oheight = Math.min(MAXHEIGHT, p.width);
+ int[] data2 = new int[owidth * oheight];
+ for(int y=0; y<owidth; y++)
+ for(int x=0; x<oheight; x++)
+ data2[y+x*owidth] = data[x+(owidth-y-1)*p.width];
+ data = data2;
+
+ for(int y=0; y<oheight; y++) {
+ pw.println("GW0,"+y+","+owidth/8+",1");
+ pw.flush();
+ DataOutputStream dout = new DataOutputStream(out);
+ System.out.println("y="+y);
+ for(int x=0; x<owidth; x+=8) {
+ byte b = 0;
+ for(int i=0; i<Math.min(8, owidth-x); i++) {
+ int dat = data[y*owidth+x+i];
+ dat &= 0x00ffffff;
+ if (dat==0) continue;
+ b |= 1 << (7-i);
+ }
+ dout.writeByte(b);
+ }
+ dout.flush();
+ pw.println();
+ }
+ pw.println();
+ pw.println();
+ pw.println();
+ pw.flush();
+
+
+ //pw.println("GI");
+ //pw.flush();
+
+
+ pw.println("P1");
+ pw.flush();
+
+ /*
+ */
+ //Log.debug(this, "consuming any leftover data on the serial port");
+
+ /*
+ AvrDrone device = new AvrDrone(detectObitsPort());
+ 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(Eltron.class, "wrote " + count + " configuration octets");
+ }
+ device.flush();
+ long end = System.currentTimeMillis();
+ Log.info(Eltron.class, "finished in " + ((end-begin)/1000) + "s");
+ System.exit(0);
+ } catch (Exception e) { e.printStackTrace(); }
+ */
+ System.exit(0);
+ }
+
+}
+++ /dev/null
-package edu.berkeley.cs.obits;
-import java.util.*;
-import java.io.*;
-import org.ibex.util.*;
-
-public class Atmel {
-
- public static String pad(int len, String s) { if (s.length() >= len) return s.toUpperCase(); return "0"+pad(len-1,s); }
- public static String hex32(int i) { return pad(8, Long.toString(i & 0xffffffffffffffffL, 16)); }
- public static String hex24(int i) { return pad(6, Integer.toString((i & 0xffffff), 16)); }
- public static String hex8(int i) { return pad(2, Integer.toString((i & 0xff), 16)); }
- public static String bin8(int i) { return pad(8, Integer.toString((i & 0xff), 2)); }
- public static String dec2(int i) { return pad(2, Integer.toString(i & 0xff)); }
-
- public static void main(String[] s) throws Exception {
- Log.level = Log.DEBUG;
- new Bits().read(System.in);
- }
-
- private static class Bits {
- private byte[] bits = new byte[0];
- //public int get(int whichByte, int whichBit, int len) { }
- //public void set(int whichByte, int whichBit, int len, int val) { }
-
- private int control = 0;
- public int control() { return control; }
- public void control(int control) { this.control = control; }
-
- public void read2(InputStream bitstream) throws IOException {
- DataInputStream dis = new DataInputStream(new Encode.Ascii.In(16, bitstream));
- try {
- while(true) {
- dis.readUnsignedByte();
- dis.readUnsignedByte();
- dis.readUnsignedByte();
- int i = dis.readUnsignedByte();
- System.out.println(bin8(i));
- }
- } catch (EOFException e) {
- }
- }
- public void read(InputStream bitstream) throws IOException {
- DataInputStream dis = new DataInputStream(new Encode.Ascii.In(2, bitstream));
- int b = dis.readUnsignedByte();
- if (b != 0x00) throw new Error("bitstream did not start with zero-byte; got " + b);
- Log.debug(this, "saw leading zero-byte");
- b = dis.readUnsignedByte();
- if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + b);
- Log.debug(this, "saw preamble byte");
- control(dis.readInt());
- Log.debug(this, "set control register to " + hex32(control()));
- int numWindows = dis.readShort();
- Log.debug(this, "this bitstream has " + numWindows + " window(s)");
- int count = 0;
- for(int i=0; i<numWindows; i++) {
- int start = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
- int end = (dis.readUnsignedByte() << 16) | (int)dis.readShort();
- count = 0;
- Log.debug(this, " window " + dec2(i) + " spans addresses " + hex24(start) + " - " + hex24(end) + "[count="+count+"]");
- int _z = (start & 0x0000ff) >> 0;
- int _y = (start & 0x00ff00) >> 8;
- int _x = (start & 0xff0000) >> 16;
- int z_ = (end & 0x0000ff) >> 0;
- int y_ = (end & 0x00ff00) >> 8;
- int x_ = (end & 0xff0000) >> 16;
- int z = (start & 0x0000ff) >> 0;
- int y = (start & 0x00ff00) >> 8;
- int x = (start & 0xff0000) >> 16;
-
- while(true) {
- count++;
- mode4(x, y, z, dis.readUnsignedByte());
- x++;
- if (x > 15) { x = 0; y++; }
- if (y > 15) { y = 0; z++; }
- do {
- z++;
- if (z > 77) {
- z = _z;
- x++;
- if (x > 15) {
- x = _x;
- y++;
- if (y > y_) break;
- }
- }
- } while(!valid(x,y,z));
- }
- //Log.debug(this, " read " + count + " bytes (" + hex24(count)+")");
- }
- /*
- Log.debug(this, "done " + count);
- b = dis.readUnsignedByte();
- if (b != 0xB7) throw new Error("bitstream did not start with preamble byte B7; got " + bin8(b));
- Log.debug(this, "done2");
- */
- }
-
- public boolean valid(int x, int y, int z) {
- switch(z) {
- case 0x00: case 0x01: break;
- }
- if (x > 15) return false;
- if (y > 15) return false;
- return true;
- }
-
- public void mode4(int x, int y, int z, int d) {
- //Log.debug(this, " ("+dec2(x)+","+dec2(y)+"):"+hex8(z)+" = "+bin8(d));
- //System.out.println(hex8(z)+hex8(y)+hex8(x)+hex8(d));
- }
- }
-}
- /*
- public static class At40k extends FPGA {
-
-
- public At40k(int width, int height) { this.width = width; this.height = height; }
-
- public static class At40k10 extends At40k { public At40k10() { super(24, 24); } }
-
- public Sector sector(int col, int row) { return new Sector(col, row); }
- public final class Sector {
- public final int col;
- public final int row;
- public Sector(int col, int row) {
- if (row % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 row");
- if (col % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 col");
- this.row = row;
- this.col = col;
- }
- }
-
- public Cell cell(int col, int row) { return new Cell(col, row); }
- public final class Cell {
- public final int col;
- public final int row;
- public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); }
- public Cell(int col, int row) {
- this.row = row;
- this.col = col;
- }
- }
-
- public class Sector {
- Cell[][] = new Cell[4][4];
- Ram ram = new Ram();
-
- Buf[] west = new Buf[4];
- Buf[] east = new Buf[4];
- Buf[] north = new Buf[4];
- Buf[] south = new Buf[4];
- Pip pass = new Pip[4][4][5][2];
- }
-
-
- public class Cell {
-
- public final Port[] h = new Port[5] { port(), port(), port(), port(), port() };
- public final Port[] v = new Port[5] { port(), port(), port(), port(), port() };
- public final Port[] s = new Port[5] { port(), port(), port(), port(), port() };
- public final Port nw, sw, se, ne;
- public final Port n, s, w, e;
- public final Port xout, yout;
-
- public final Pip zin = pip( s[0], s[1], s[2], s[3], s[4]);
- public final Pip win = pip( s[0], s[1], s[2], s[3], s[4]);
- public final Pip xin = pip(nw, ne, sw, se, s[0], s[1], s[2], s[3], s[4]);
- public final Pip yin = pip(n, s, e, w, s[0], s[1], s[2], s[3], s[4]);
-
- public final Pip wpip = pip(win, zin, and(win, zin), fb);
- public final Pip zpip = pip(zin, one, zero);
-
- public final Lut xlut = lut(xpip, wmux, ypip);
- public final Lut ylut = lut(xpip, wmux, ypip);
- public final Mux zmux = mux(xlut, ylut, zpip);
- public final Reg reg = reg(zmux);
- public final Pip center = pip(reg, zmux);
-
- public final Pip fb = pip(zmux, reg);
-
- public final Pip center = pip(zmux, reg);
- public final Pip xout = pip(xlut, center);
- public final Pip yout = pip(ylut, center);
-
- public final Pip oe = pip(one, h[4], v[4]);
- public final Buf out = buf(fb, oe);
-
- public final Pip[] o = pip5(out, s);
- public final Pip[] h = pip5(h, s);
- public final Pip[] v = pip5(v, s);
- }
-
-
- }
-
-
- public class At94k extends At40k {
- }
- */
-
+++ /dev/null
-package edu.berkeley.cs.obits;
-
-import edu.berkeley.cs.obits.device.atmel.*;
-import org.ibex.util.*;
-import java.io.*;
-import java.util.*;
-import gnu.io.*;
-
-public class AtmelSerial {
-
- public static SerialPort detectObitsPort() throws Exception {
- Enumeration e = CommPortIdentifier.getPortIdentifiers();
- while(e.hasMoreElements()) {
- CommPortIdentifier cpi = (CommPortIdentifier)e.nextElement();
- Log.info(AtmelSerial.class, "trying " + cpi.getName());
- }
- SerialPort ret = new RXTXPort("/dev/cu.usbserial-FTBUODP4");
- Log.info(AtmelSerial.class, "returning " + ret);
- return ret;
- }
-
- public static void main(String[] s) throws Exception {
- SerialPort sp = detectObitsPort();
- sp.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
- //sp.setFlowControlMode(sp.FLOWCONTROL_NONE);
- OutputStream out = sp.getOutputStream();
- InputStream in = sp.getInputStream();
- int count = 0;
- PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
- /*
- pw.println("Y38,N,8,1");
- pw.flush();
- sp.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
-
- pw.println("GI");
- pw.flush();
- */
-
- pw.println();
- pw.flush();
- pw.println("^@");
- pw.println("^@");
- pw.println("^@");
- pw.flush();
- try { Thread.sleep(3000); } catch (Exception e) { }
-
- pw.println("GK\"IMG\"");
- pw.println("GK\"IMG\"");
- pw.println();
- pw.flush();
- try { Thread.sleep(1000); } catch (Exception e) { }
- /*
- pw.println("GI");
- pw.flush();
- */
- int[] data = new int[104 * 104];
- for(int i=0; i<104*104; i++) data[i] = 1;
- for(int i=0; i<104; i++) data[i*104+i] = 0;
- for(int i=0; i<104; i++) data[i*104+(104-i)] = 0;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- PCX.dump(104, 104, data, new DataOutputStream(baos));
- byte[] outb = baos.toByteArray();
- int len = outb.length;
- pw.println("GM\"IMG\""+len);
- pw.flush();
- DataOutputStream dout = new DataOutputStream(out);
- for(int i=0; i<len; i++) {
- System.out.println("wrote " + i + "/"+outb.length);
- dout.writeByte(outb[i]);
- dout.flush();
- }
- dout.flush();
-
- pw.println();
- pw.println("GI");
- pw.flush();
-
- try { Thread.sleep(2000); } catch (Exception e) { }
-
- pw.println();
- pw.println("OD");
- pw.println("N");
- pw.println("D14");
- pw.println("S1");
- pw.println("Q609,24");
- pw.println("q754");
- //pw.println("R0,0");
- pw.println("A170,5,0,1,5,5,N,\"WORLDWIDE\"");
- pw.println("LO5,230,765,10");
- pw.println("A10,265,0,1,3,3,R,\"MODEL:\"");
- pw.println("A280,265,0,1,3,3,N,\"Bar Code Printer\"");
- pw.println("A10,340,0,1,3,3,R,\" CODE: \"");
- pw.println("B280,340,0,3C,2,6,120,B,\"BCP-1234\"");
- pw.println("LO5,520,765,10");
- pw.println("A100,550,0,1,2,2,N,\"ISO9000 Made In USA\"");
- pw.println("GG0,0,\"IMG2\"");
- pw.println("P1");
- pw.flush();
-
- /*
- */
- //Log.debug(this, "consuming any leftover data on the serial port");
-
- /*
- AvrDrone device = new AvrDrone(detectObitsPort());
- 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();
- long end = System.currentTimeMillis();
- Log.info(AtmelSerial.class, "finished in " + ((end-begin)/1000) + "s");
- System.exit(0);
- } catch (Exception e) { e.printStackTrace(); }
- */
- System.exit(0);
- }
-
-}
+++ /dev/null
-package edu.berkeley.cs.obits;
-
-import java.util.*;
-
-/** a physical or virtual reconfigurable device */
-public interface Device {
-
- /** reset the device */
- public void reset() throws DeviceException;
-
- /** flush any commands issued so far, blocking until they have taken effect */
- public void flush() throws DeviceException;
-
- public static class DeviceException extends Exception {
- public DeviceException(String s) { super(s); }
- public DeviceException(Throwable t) { super(t); }
- }
-
-}
+++ /dev/null
-package edu.berkeley.cs.obits.device.atmel;
-
-import edu.berkeley.cs.obits.*;
-//import static edu.berkeley.cs.obits.device.atmel.Wires.*;
-import java.util.*;
-
-public abstract class AtmelDevice extends Bits implements Device {
-
- /** issue a command to the device in Mode4 format; see Gosset's documentation for further details */
- public abstract void mode4(int z, int y, int x, int d) throws DeviceException;
- /*
- public Sector sector(int col, int row) { return new Sector(col, row); }
- public final class Sector {
- public final int col;
- public final int row;
- public Sector(int col, int row) {
- if (row % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 row");
- if (col % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 col");
- this.row = row;
- this.col = col;
- }
- }
-
- public static interface Driver { }
-
- public static interface HasPlane { public int getPlane(); }
-
- public static interface XI extends Driver { }
- public static interface YI extends Driver { }
- */
- /*
- public static void foo(Direction f) { }
- public static enum Direction implements Drives<Y> { N, S, E, W; }
- public static enum Bar { A, B, C; }
- public static Object B = new Object();
- public static Direction foo = null;
- static {
- switch(foo) {
- case N:
- case S:
- case W:
- }
- }
-
- public class Drives<E extends EPR<E>> { }
- public class EPR<E extends EPR<E>> {
- public abstract Drives<E> driver();
- public abstract void driver(Drives<E>);
- }
-
- public class Joins<B extends Bus<B>> { }
- public abstract class Bus<B extends Bus<B>> {
- public Set<Joins<E>> drivers();
- }
- public interface Drives<E extends EPR> { }
-
-
- public static interface EPR {
- }
- public static interface Drives<E extends EPR> { }
- public static interface Bus extends EPR { }
- public static interface Joins<J extends Joins, B extends Bus & Joins<B,J>> extends Bus { }
- //public static interface Joins<B extends Bus> extends Bus { }
- public static interface Has<E extends EPR> {
- public Drives<E> getDriver(E e);
- public void setDriver(E e, Drives<E> driver);
- }
- //public static interface HasBus<B extends Bus> { public Set<OnBus<B>> on(B b); }
- public interface Input { }
- public interface Output { }
- public interface InOut { }
-
- public static abstract class LUT<A extends EPR, B extends EPR, C extends EPR> implements EPR { }
- public static abstract class And<A extends EPR, B extends EPR> implements EPR { }
- public static abstract class Reg<A extends EPR> { }
- public static abstract class Mux<Sel extends EPR, Zero extends EPR, One extends EPR> { }
- public static abstract class Buf<Sel extends EPR> { }
-
- public enum DiagonalInputs implements Input, Drives<X> { NW, SW, NE, SE; }
- public enum OrthogonalInputs implements Input, Drives<Y> { N, S, E, W; }
-
- public <X extends Drives<Y>, Y extends EPR> void connect(X x, Y y) { }
-
- public static enum Plane { P0, P1, P2, P3, P4; }
- public static class L<P extends Plane> implements Bus, Drives<X>, Drives<Y>, Drives<Z>, Drives<W> { }
-
- public final class Cell {
- public class X implements EPR, Drives<XLUT>, Drives<YLUT> { }
- public class Y implements EPR, Drives<XLUT>, Drives<YLUT> { }
- public class Z implements EPR, Drives<A>, Drives<WZ> { }
- public class F implements EPR, Drives<A>, Drives<WF>, Drives<OB> { }
- public class W implements EPR, Drives<A>, Drives<WZ>, Drives<WF> { }
- public class A implements EPR { }
- public class WZ extends And<W, Z> implements EPR, Drives<XLUT>, Drives<YLUT> { }
- public class WF extends And<W, F> implements EPR, Drives<XLUT>, Drives<YLUT> { }
- public class CM extends Mux<Z, Y, X> implements EPR, Drives<C> { }
- public class XLUT extends LUT<X, Y, A> implements EPR, Drives<CM>, Drives<XO> { }
- public class YLUT extends LUT<A, X, Y> implements EPR, Drives<CM>, Drives<YO> { }
- public class C implements EPR, Drives<R>, Drives<F> { }
- public class R extends Reg<C> implements EPR, Drives<F>, Drives<XO>, Drives<YO>{ }
- public class XO implements EPR, Output { }
- public class YO implements EPR, Output { }
- public static class OB extends Buf<F>> implements EPR, Drives<L0>, Drives<L1>, Drives<L2>, Drives<L3>, Drives<L4> { }
-
- */
- //public static L1 L1 = new L1();
- /*
- public static class CellImpl implements
- Has<X>,
- Has<Y> {
- public void setDriver(X x, Drives<X> d) { }
- public void setDriver(Y y, Drives<Y> d) { }
- public void setDriver(Z z, Drives<Z> d) { }
- public void setDriver(W w, Drives<W> d) { }
- public Drives<X> getDriver(X x) { return null; }
- public Drives<Y> getDriver(Y y) { return null; }
- public Drives<Z> getDriver(Z z) { return null; }
- public Drives<W> getDriver(W w) { return null; }
-
- public Set<OnBus<L1>> on(L1 l1) { return null; }
- public Drives<Y> getDriver(Y y) { return null; }
- public void setDriver(Y y, Drives<Y> d) { }
- }
- */
- /*
- public static abstract class L<D extends C> implements HasPlane, EPR<C> {
- private final int plane;
- L(int plane) { this.plane = plane; }
- public int getPlane() { return plane; }
- public boolean h();
- public void h(boolean connected);
- public boolean v();
- public void v(boolean connected);
- public boolean f();
- public void f(boolean connected);
- }
-
- L0 = new L<L0>(0);
- L1 = new L<L1>(1);
- L2 = new L<L2>(2);
- L3 = new L<L3>(3);
- L4 = new L<L4>(4);
-
-
-
- public static enum L implements XI, YI {
- L0(0), L1(1), L2(2), L3(3) { public int foo() { return 2; } }, L4(4);
-
- public final int plane;
- public L(int plane) { this.plane = plane; }
-
- }
- */
-
- //public static interface L0 extends XI, YI { } public static L0 L0 = new L0() { };
-
- /*
-
- public static enum Xi { NONE, L0, L1, L2, L3, NW, SW, NE, SE, L4; }
- public static enum Yi { NONE, L0, L1, L2, L3, E, W, S, N, L4; }
- public static enum Wi { NONE, L0, L1, L4, L3, L2; }
- public static enum Zi { NONE, L0, L1, L2, L3, L4; }
- public static enum Ti { W, Z, F, WZ, WF, ONE; }
- public static enum Ci { X, Y, CMux; }
- public static enum Fi { R, C; }
- public static enum Bi { R, C; }
- public static enum Xo { X, B; }
- public static enum Yo { Y, B; }
- public static enum Oe { ONE, H4, V4; }
-
- public Cell cell(int col, int row) { return new Cell(col, row); }
- public final class Cell {
- public final int col;
- public final int row;
- */
- /** assumes LITTLE endian */
- /*
- protected int onehot(int val) {
- int ret = -1;
- for(int i=0; i<32; i++) {
- if ((val & (1 << i)) != 0) {
- if (ret != -1) throw new Error("two bits set in a one-hot encoded value");
- ret = i;
- }
- }
- return ret+1;
- }
- protected int bits(int octet, int bit, int count) {
- return AtmelDevice.this.bits.get(offset, count);
- }
-
- public void set(Xi xi) { }
- public void set(Yi xi) { }
- public void set(Ti xi) { }
- public void set(Ci xi) { }
- public void set(Fi xi) { }
- public void set(Bi xi) { }
- public void set(Xo xo) { }
- public void set(Yo yo) { }
- public void set(Oe oe) { }
-
- public Xi xi() { return Xi.values()[onehot((bits(3,3,1)<<8)|bits(5,0,8))]; }
- public Yi yi() { return Yi.values()[onehot((bits(2,1,1)<<8)|bits(4,0,8))]; }
- public Wi wi() { return Wi.values()[onehot((bits(3,0,3)<<2)|bits(3,4,2))]; }
- public Zi zi() { return Zi.values()[onehot((bits(2,0,1)<<4)|bits(2,2,4))]; }
- public Ti ti() { return null; }
- public Ci ci() { return null; }
- public Fi fi() { return null; }
- public Bi bi() { return null; }
- public Xo xo() { return Xo.values()[onehot(bits(1,6,1))]; }
- public Yo yo() { return Yo.values()[onehot(bits(1,7,1))]; }
- public Oe oe() { return Oe.values()[onehot(bits(3,6,2))]; }
-
- public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); }
- public Cell(int col, int row) {
- this.row = row;
- this.col = col;
- }
-
-
-
-
- public static enum EPR { L0, L1, L2, L3, L4 }
- public static enum XInputDriver extends InputDriver {
- public static enum YInputDriver extends InputDriver { N, S, E, W }
- public XInputDriver xi() { }
- public void xi(XInputDriver) { }
- public YInputDriver yi() { }
- public void yi(YInputDriver) { }
- public InputDriver zi() { }
- public void zi(InputDriver) { }
- public InputDriver wi() { }
- public void wi(InputDriver) { }
-
- public byte xlut() { }
- public xlut(byte) { }
- public byte ylut() { }
- public ylut(byte) { }
-
- public static enum CInputDriver { XL, YL, C }
- public static enum FDriver { R, C }
-
- public boolean cRegistered() { }
-
- }
- */
-}
+++ /dev/null
-//\r
-// YOU MUST COMPILE THIS WITH -O3 OR THE AVR WILL NOT BE ABLE TO KEEP UP!!!!\r
-//\r
-\r
-#define F_CPU 3960000\r
-#define __AVR_AT94K__\r
-#include <avr/wdt.h>\r
-#include <avr/delay.h>\r
-#include <avr/io.h>\r
-#include <avr/signal.h>\r
-#include <avr/interrupt.h>\r
-\r
-unsigned char val = 0;\r
-\r
-volatile unsigned char dataReady = 0;\r
-volatile unsigned char data = 0;\r
-\r
-void initUART1(unsigned int baudRate, unsigned int doubleRate) {\r
- UBRRHI = (((baudRate) >> 8) & 0x000F); \r
- UBRR1 = ((baudRate) & 0x00FF); \r
- UCSR1B |= ((1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1)); \r
- /*\r
- if (doubleRate)\r
- UCSR1A |= (1 << U2X1);\r
- else\r
- UCSR1A &= ~(1 << U2X1);\r
- */\r
-}\r
-\r
-#define BUFSIZE (1024 *2)\r
-static char buf[BUFSIZE];\r
-volatile static int head = 0;\r
-volatile static int tail = 0;\r
-\r
-void send(char c) {\r
- while(!(UCSR1A & (1 << UDRE1))); /* Wait for data Regiester to be empty */\r
- UDR1 = (int)c;\r
-}\r
-\r
-inline void portd(int bit, int on) {\r
- if (on) {\r
- PORTD &= ~(1<<bit);\r
- } else {\r
- PORTD |= (1<<bit);\r
- }\r
-}\r
-inline void cts(int c) {\r
- if (c) {\r
- PORTE &= ~(1 << 4);\r
- portd(0, 1);\r
- } else {\r
- PORTE |= (1 << 4);\r
- portd(0, 0);\r
- }\r
-}\r
-\r
-inline int inc(int x) { x++; if (x>=BUFSIZE) x=0; return x; }\r
-inline int full() { return inc(tail)==head; }\r
-inline int nearlyFull() {\r
- if (tail==head) return 0;\r
- if (tail < head) return (head-tail) < (BUFSIZE/2);\r
- return (tail-head) > (BUFSIZE/2);\r
-}\r
-inline int empty() { return head==tail; }\r
-\r
-inline char recv() {\r
- int q;\r
- char ret;\r
- while(empty()) cts(1);\r
- ret = buf[head];\r
- head = inc(head);\r
- if (!nearlyFull()) cts(0);\r
- return ret;\r
-}\r
-\r
-void init() {\r
- EIMF = 0xFF; /* Enalbe External Interrrupt*/ \r
- DDRD = 0xFF; /* Configure PORTD as Output */\r
- DDRE = 1 << 4; /* ability to write to E */\r
- initUART1(1, 0);\r
- SREG |= 0x80;\r
- sei();\r
-}\r
-\r
-void conf(int z, int y, int x, int d) {\r
- FPGAX = x;\r
- FPGAY = y;\r
- FPGAZ = z;\r
- FPGAD = d;\r
-}\r
-\r
-void doreset() {\r
- int i;\r
- for(i=0; i<5; i++) {\r
- PORTD = ~0x01;\r
- _delay_ms(50);\r
- PORTD = ~0x02;\r
- _delay_ms(50);\r
- PORTD = ~0x04;\r
- _delay_ms(50);\r
- PORTD = ~0x08;\r
- _delay_ms(50);\r
- }\r
- PORTD = ~0x00;\r
- wdt_enable(WDTO_250MS);\r
- while(1) { }\r
-}\r
-\r
-SIGNAL(SIG_INTERRUPT1) {\r
- doreset();\r
-}\r
-\r
-void die() { cli(); cts(0); _delay_ms(2000); while(1) { } }\r
-SIGNAL(SIG_UART1_RECV) {\r
- if (UCSR1A & (1 << FE1)) { portd(2,0); portd(3,1); die(); } // framing error, lock up with LED=01\r
- if ((UCSR1A & (1 << OR1))) { portd(2,1); portd(3,0); die(); } // overflow; lock up with LED=10\r
- if (full()) { portd(2,1); portd(3,1); die(); } // buffer overrun\r
- buf[tail] = UDR1;\r
- tail = inc(tail);\r
- SREG |= 0x80;\r
- sei();\r
- if (nearlyFull()) cts(0);\r
-}\r
-\r
-inline int hex(char c) {\r
- if (c >= '0' && c <= '9') return (c - '0');\r
- if (c >= 'a' && c <= 'f') return ((c - 'a') + 0xa);\r
- if (c >= 'A' && c <= 'F') return ((c - 'A') + 0xa);\r
- return -1;\r
-}\r
-\r
-int main() {\r
- int count;\r
- init();\r
- cts(0);\r
- send('O');\r
- send('B');\r
- send('I');\r
- send('T');\r
- send('S');\r
- send('\n');\r
- cts(1);\r
- for(;;) {\r
- int i, x=0, y=0, z=0, d=0;\r
- switch(recv()) {\r
- case 1:\r
- z = recv();\r
- y = recv();\r
- x = recv();\r
- d = recv();\r
- portd(1,1);\r
- conf(z, y, x, d);\r
- portd(1,0);\r
- break;\r
- default: die();\r
- }\r
- }\r
- return 0;\r
-} \r
-\r
+++ /dev/null
-package edu.berkeley.cs.obits.device.atmel;
-
-import edu.berkeley.cs.obits.*;
-import org.ibex.util.Log;
-import java.io.*;
-import java.util.*;
-import gnu.io.*;
-
-/** the "host" side of the AVR Drone; see AvrDrone.c for the other side */
-public class AvrDrone extends AtmelDevice {
-
- final DataInputStream in;
-
- final DataOutputStream out;
-
- final SerialPort sp;
-
- public AvrDrone(SerialPort sp) throws IOException, UnsupportedCommOperationException, InterruptedException, DeviceException {
- this.sp = sp;
- sp.setSerialPortParams(115200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
- sp.setFlowControlMode(sp.FLOWCONTROL_RTSCTS_OUT);
- this.out = new DataOutputStream(sp.getOutputStream());
- this.in = new DataInputStream(sp.getInputStream());
- Log.debug(this, "consuming any leftover data on the serial port");
- while(in.available() > 0) in.read();
- reset();
- Log.debug(this, "waiting for device to identify itself");
- if (in.readByte() != (byte)'O') throw new RuntimeException("didn't get the proper signature");
- if (in.readByte() != (byte)'B') throw new RuntimeException("didn't get the proper signature");
- if (in.readByte() != (byte)'I') throw new RuntimeException("didn't get the proper signature");
- if (in.readByte() != (byte)'T') throw new RuntimeException("didn't get the proper signature");
- if (in.readByte() != (byte)'S') throw new RuntimeException("didn't get the proper signature");
- if (in.readByte() != (byte)'\n') throw new RuntimeException("didn't get the proper signature");
- Log.info(this, "device correctly identified itself; ready for operation");
- }
-
- public void reset() throws DeviceException {
- try {
- Log.info(this, "resetting device");
- sp.setDTR(true);
- Thread.sleep(500);
- sp.setDTR(false);
- Thread.sleep(3000);
- } catch (InterruptedException e) { throw new DeviceException(e); }
- }
-
- public void mode4(int z, int y, int x, int d) throws DeviceException {
- try {
- Log.debug(this, "writing configuration frame [zyxd]: " +
- pad(2, Integer.toString(z, 16)) + " " +
- pad(2, Integer.toString(y, 16)) + " " +
- pad(2, Integer.toString(x, 16)) + " " +
- pad(2, Integer.toString(d, 16))
- );
- out.writeByte(1);
- out.writeByte(z);
- out.writeByte(y);
- out.writeByte(x);
- out.writeByte(d);
- } catch (IOException e) { throw new DeviceException(e); }
- }
-
- public void flush() throws DeviceException {
- try {
- out.flush();
- } catch (IOException e) { throw new DeviceException(e); }
- }
-
- private String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); }
-
-}