From: adam Date: Mon, 1 Jan 2007 03:01:04 +0000 (-0800) Subject: cleanup X-Git-Url: http://git.megacz.com/?p=eltron.git;a=commitdiff_plain;h=0178b34d5fde3c1cfbc18ae48ec1798b28a1af21;ds=sidebyside cleanup darcs-hash:20070101030104-5007d-4a7207d203ffe93a8119d2632bb12f08651102cb.gz --- diff --git a/jar/ibex.jar b/jar/ibex.jar new file mode 100644 index 0000000..27cad7a Binary files /dev/null and b/jar/ibex.jar differ diff --git a/lib/RXTXcomm.jar b/lib/RXTXcomm.jar new file mode 100644 index 0000000..fb8cc20 Binary files /dev/null and b/lib/RXTXcomm.jar differ diff --git a/lib/librxtxSerial.jnilib b/lib/librxtxSerial.jnilib new file mode 100644 index 0000000..2d3f20d Binary files /dev/null and b/lib/librxtxSerial.jnilib differ diff --git a/lib/librxtxSerial.so b/lib/librxtxSerial.so new file mode 100644 index 0000000..d340dcb Binary files /dev/null and b/lib/librxtxSerial.so differ diff --git a/src/com/megacz/eltron/Eltron.java b/src/com/megacz/eltron/Eltron.java new file mode 100644 index 0000000..a7881a8 --- /dev/null +++ b/src/com/megacz/eltron/Eltron.java @@ -0,0 +1,144 @@ +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> 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); + } + +} diff --git a/src/edu/berkeley/cs/obits/Atmel.java b/src/edu/berkeley/cs/obits/Atmel.java deleted file mode 100644 index 1f01adb..0000000 --- a/src/edu/berkeley/cs/obits/Atmel.java +++ /dev/null @@ -1,201 +0,0 @@ -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> 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 { - } - */ - diff --git a/src/edu/berkeley/cs/obits/AtmelSerial.java b/src/edu/berkeley/cs/obits/AtmelSerial.java deleted file mode 100644 index b43d0f9..0000000 --- a/src/edu/berkeley/cs/obits/AtmelSerial.java +++ /dev/null @@ -1,125 +0,0 @@ -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> 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); - } - -} diff --git a/src/edu/berkeley/cs/obits/Device.java b/src/edu/berkeley/cs/obits/Device.java deleted file mode 100644 index 8f26d34..0000000 --- a/src/edu/berkeley/cs/obits/Device.java +++ /dev/null @@ -1,19 +0,0 @@ -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); } - } - -} diff --git a/src/edu/berkeley/cs/obits/device/atmel/AtmelDevice.java b/src/edu/berkeley/cs/obits/device/atmel/AtmelDevice.java deleted file mode 100644 index 42425cf..0000000 --- a/src/edu/berkeley/cs/obits/device/atmel/AtmelDevice.java +++ /dev/null @@ -1,247 +0,0 @@ -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 { 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> { } - public class EPR> { - public abstract Drives driver(); - public abstract void driver(Drives); - } - - public class Joins> { } - public abstract class Bus> { - public Set> drivers(); - } - public interface Drives { } - - - public static interface EPR { - } - public static interface Drives { } - public static interface Bus extends EPR { } - public static interface Joins> extends Bus { } - //public static interface Joins extends Bus { } - public static interface Has { - public Drives getDriver(E e); - public void setDriver(E e, Drives driver); - } - //public static interface HasBus { public Set> on(B b); } - public interface Input { } - public interface Output { } - public interface InOut { } - - public static abstract class LUT implements EPR { } - public static abstract class And implements EPR { } - public static abstract class Reg { } - public static abstract class Mux { } - public static abstract class Buf { } - - public enum DiagonalInputs implements Input, Drives { NW, SW, NE, SE; } - public enum OrthogonalInputs implements Input, Drives { N, S, E, W; } - - public , Y extends EPR> void connect(X x, Y y) { } - - public static enum Plane { P0, P1, P2, P3, P4; } - public static class L

implements Bus, Drives, Drives, Drives, Drives { } - - public final class Cell { - public class X implements EPR, Drives, Drives { } - public class Y implements EPR, Drives, Drives { } - public class Z implements EPR, Drives, Drives { } - public class F implements EPR, Drives, Drives, Drives { } - public class W implements EPR, Drives, Drives, Drives { } - public class A implements EPR { } - public class WZ extends And implements EPR, Drives, Drives { } - public class WF extends And implements EPR, Drives, Drives { } - public class CM extends Mux implements EPR, Drives { } - public class XLUT extends LUT implements EPR, Drives, Drives { } - public class YLUT extends LUT implements EPR, Drives, Drives { } - public class C implements EPR, Drives, Drives { } - public class R extends Reg implements EPR, Drives, Drives, Drives{ } - public class XO implements EPR, Output { } - public class YO implements EPR, Output { } - public static class OB extends Buf> implements EPR, Drives, Drives, Drives, Drives, Drives { } - - */ - //public static L1 L1 = new L1(); - /* - public static class CellImpl implements - Has, - Has { - public void setDriver(X x, Drives d) { } - public void setDriver(Y y, Drives d) { } - public void setDriver(Z z, Drives d) { } - public void setDriver(W w, Drives d) { } - public Drives getDriver(X x) { return null; } - public Drives getDriver(Y y) { return null; } - public Drives getDriver(Z z) { return null; } - public Drives getDriver(W w) { return null; } - - public Set> on(L1 l1) { return null; } - public Drives getDriver(Y y) { return null; } - public void setDriver(Y y, Drives d) { } - } - */ - /* - public static abstract class L implements HasPlane, EPR { - 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(0); - L1 = new L(1); - L2 = new L(2); - L3 = new L(3); - L4 = new L(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() { } - - } - */ -} diff --git a/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.c b/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.c deleted file mode 100644 index 0878b4f..0000000 --- a/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.c +++ /dev/null @@ -1,160 +0,0 @@ -// -// YOU MUST COMPILE THIS WITH -O3 OR THE AVR WILL NOT BE ABLE TO KEEP UP!!!! -// - -#define F_CPU 3960000 -#define __AVR_AT94K__ -#include -#include -#include -#include -#include - -unsigned char val = 0; - -volatile unsigned char dataReady = 0; -volatile unsigned char data = 0; - -void initUART1(unsigned int baudRate, unsigned int doubleRate) { - UBRRHI = (((baudRate) >> 8) & 0x000F); - UBRR1 = ((baudRate) & 0x00FF); - UCSR1B |= ((1 << RXEN1) | (1 << TXEN1) | (1 << RXCIE1)); - /* - if (doubleRate) - UCSR1A |= (1 << U2X1); - else - UCSR1A &= ~(1 << U2X1); - */ -} - -#define BUFSIZE (1024 *2) -static char buf[BUFSIZE]; -volatile static int head = 0; -volatile static int tail = 0; - -void send(char c) { - while(!(UCSR1A & (1 << UDRE1))); /* Wait for data Regiester to be empty */ - UDR1 = (int)c; -} - -inline void portd(int bit, int on) { - if (on) { - PORTD &= ~(1<=BUFSIZE) x=0; return x; } -inline int full() { return inc(tail)==head; } -inline int nearlyFull() { - if (tail==head) return 0; - if (tail < head) return (head-tail) < (BUFSIZE/2); - return (tail-head) > (BUFSIZE/2); -} -inline int empty() { return head==tail; } - -inline char recv() { - int q; - char ret; - while(empty()) cts(1); - ret = buf[head]; - head = inc(head); - if (!nearlyFull()) cts(0); - return ret; -} - -void init() { - EIMF = 0xFF; /* Enalbe External Interrrupt*/ - DDRD = 0xFF; /* Configure PORTD as Output */ - DDRE = 1 << 4; /* ability to write to E */ - initUART1(1, 0); - SREG |= 0x80; - sei(); -} - -void conf(int z, int y, int x, int d) { - FPGAX = x; - FPGAY = y; - FPGAZ = z; - FPGAD = d; -} - -void doreset() { - int i; - for(i=0; i<5; i++) { - PORTD = ~0x01; - _delay_ms(50); - PORTD = ~0x02; - _delay_ms(50); - PORTD = ~0x04; - _delay_ms(50); - PORTD = ~0x08; - _delay_ms(50); - } - PORTD = ~0x00; - wdt_enable(WDTO_250MS); - while(1) { } -} - -SIGNAL(SIG_INTERRUPT1) { - doreset(); -} - -void die() { cli(); cts(0); _delay_ms(2000); while(1) { } } -SIGNAL(SIG_UART1_RECV) { - if (UCSR1A & (1 << FE1)) { portd(2,0); portd(3,1); die(); } // framing error, lock up with LED=01 - if ((UCSR1A & (1 << OR1))) { portd(2,1); portd(3,0); die(); } // overflow; lock up with LED=10 - if (full()) { portd(2,1); portd(3,1); die(); } // buffer overrun - buf[tail] = UDR1; - tail = inc(tail); - SREG |= 0x80; - sei(); - if (nearlyFull()) cts(0); -} - -inline int hex(char c) { - if (c >= '0' && c <= '9') return (c - '0'); - if (c >= 'a' && c <= 'f') return ((c - 'a') + 0xa); - if (c >= 'A' && c <= 'F') return ((c - 'A') + 0xa); - return -1; -} - -int main() { - int count; - init(); - cts(0); - send('O'); - send('B'); - send('I'); - send('T'); - send('S'); - send('\n'); - cts(1); - for(;;) { - int i, x=0, y=0, z=0, d=0; - switch(recv()) { - case 1: - z = recv(); - y = recv(); - x = recv(); - d = recv(); - portd(1,1); - conf(z, y, x, d); - portd(1,0); - break; - default: die(); - } - } - return 0; -} - diff --git a/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.java b/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.java deleted file mode 100644 index aa12dce..0000000 --- a/src/edu/berkeley/cs/obits/device/atmel/AvrDrone.java +++ /dev/null @@ -1,71 +0,0 @@ -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); } - -}