1 package edu.berkeley.obits.device.atmel;
3 import com.atmel.fpslic.*;
4 import edu.berkeley.slipway.*;
5 import edu.berkeley.obits.*;
6 import org.ibex.util.Log;
11 /** the "host" side of the AVR Drone; see AvrDrone.c for the other side */
12 public class AvrDrone extends Fpslic {
14 private final DataInputStream in;
15 private final DataOutputStream out;
16 private final Board board;
18 public AvrDrone(Board b) throws IOException {
20 this.out = new DataOutputStream(b.getOutputStream());
21 this.in = new DataInputStream(b.getInputStream());
25 public void reset() throws IOException {
29 private void init() throws IOException {
30 byte[] bytes = new byte[6];
36 // read any crap that might be left in the buffer
38 System.arraycopy(bytes, 1, bytes, 0, 5);
39 bytes[5] = in.readByte();
41 System.out.print("\rsignature: read \"" + new String(bytes) + "\" ");
42 if (bytes[0] == (byte)'O' &&
43 bytes[1] == (byte)'B' &&
44 bytes[2] == (byte)'I' &&
45 bytes[3] == (byte)'T' &&
46 bytes[4] == (byte)'S') {
47 System.out.println("\rsignature: got proper signature ");
54 public synchronized void scanFPGA(boolean on) throws IOException {
63 public static int retval = 0;
64 public synchronized int readCount() {
70 ByteCallback bc = new ByteCallback() {
71 public synchronized void call(byte b) throws Exception {
74 ((in.read() & 0xff) << 16) |
75 ((in.read() & 0xff) << 8) |
76 ((in.read() & 0xff) << 0);
87 } catch (Exception e) { throw new RuntimeException(e); }
90 public static interface ByteCallback {
91 public void call(byte b) throws Exception;
94 private Vector callbacks = new Vector();
96 private Thread reader = new Thread() {
98 System.out.println("*** reader thread begun");
101 byte b = in.readByte();
102 ByteCallback bc = (ByteCallback)callbacks.remove(0);
104 } catch (Exception e) {
111 public synchronized void readBus(ByteCallback bc) throws IOException {
115 if (reader != null) {
121 public synchronized void readInterrupts(ByteCallback bc) throws IOException {
125 if (reader != null) {
131 private byte[][][] cache = new byte[24][][];
132 public /*synchronized*/ byte mode4(int z, int y, int x) {
133 if (cache[x]==null) return 0;
134 if (cache[x][y]==null) return 0;
135 return cache[x][y][z];
141 public static int save = 0;
142 public static int saveof = 0;
143 public /*synchronized*/ void mode4(int z, int y, int x, int d) {
155 if (cache[x & 0xff]==null) cache[x & 0xff] = new byte[24][];
156 if (cache[x & 0xff][y & 0xff]==null) cache[x & 0xff][y & 0xff] = new byte[256];
157 cache[x & 0xff][y & 0xff][z & 0xff] = (byte)(d & 0xff);
158 } catch (IOException e) {
159 throw new RuntimeException(e);
163 public /*synchronized*/ void flush() {
166 } catch (IOException e) {
167 throw new RuntimeException(e);
171 private String pad(int i, String s) { if (s.length()>i) return s; return "0"+pad((i-1),s); }