1 package edu.berkeley.cs.obits;
2 import org.ibex.util.*;
6 public static String pad(int len, String s) { if (s.length() >= len) return s; return "0"+pad(len-1,s); }
7 public static String hex24(int i) { return pad(6, Integer.toString((i & 0xffffff), 16)); }
8 public static String hex8(int i) { return pad(2, Integer.toString((i & 0xff), 16)); }
9 public static String bin8(int i) { return pad(8, Integer.toString((i & 0xff), 2)); }
10 public static String dec2(int i) { return pad(2, Integer.toString(i & 0xff)); }
12 private static class Bits {
13 private byte[] bits = new byte[0];
14 public int get(int whichByte, int whichBit, int len) { }
15 public void set(int whichByte, int whichBit, int len, int val) { }
17 private int control = 0;
18 public int control() { return control; }
19 public void control(int control) { this.control = control; }
21 public void read(InputStream bitstream) {
22 DataInputStream dis = new DataInputStream(new Encode.Ascii.Binary(bitstream));
23 if (dis.readByte() != (byte)0x00) throw new Error("bitstream did not start with zero-byte");
24 Log.debug(this, "saw leading zero-byte");
25 if (dis.readByte() != (byte)0xB7) throw new Error("bitstream did not start with preamble byte B7");
26 Log.debug(this, "saw preamble byte");
27 control(dis.readInt());
28 Log.debug(this, "set control register to " + control());
29 int numWindows = dis.readShort();
30 Log.debug(this, "this bitstream has " + numWindows + " window(s)");
31 for(int i=0; i<numWindows; i++) {
32 int start = (((int)dis.readByte()) << 16) | (int)dis.readShort();
33 int end = (((int)dis.readByte()) << 16) | (int)dis.readShort();
34 Log.debug(this, " window " + i + " spans addresses " + hex24(start) + " - " + hex24(end));
35 for(int j=start; j<=end; j++) {
36 int z = (j & 0x0000ff) >> 0;
37 int y = (j & 0x00ff00) >> 8;
38 int x = (j & 0xff0000) >> 16;
39 mode4(x, y, z, dis.readByte());
44 public void mode4(int x, int y, int z, int d) {
45 Log.debug(this, " ("+dec2(x)+","+dec2(y)+"):"+hex8(z)+" = "+bin8(d));
50 public static class At40k extends FPGA {
53 public At40k(int width, int height) { this.width = width; this.height = height; }
55 public static class At40k10 extends At40k { public At40k10() { super(24, 24); } }
57 public Sector sector(int col, int row) { return new Sector(col, row); }
58 public final class Sector {
61 public Sector(int col, int row) {
62 if (row % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 row");
63 if (col % 4 != 0) throw new Error("Sector must be created with a multiple-of-4 col");
69 public Cell cell(int col, int row) { return new Cell(col, row); }
70 public final class Cell {
73 public Sector getSector() { return sector(col - (col % 4), row - (row % 4)); }
74 public Cell(int col, int row) {
81 Cell[][] = new Cell[4][4];
84 Buf[] west = new Buf[4];
85 Buf[] east = new Buf[4];
86 Buf[] north = new Buf[4];
87 Buf[] south = new Buf[4];
88 Pip pass = new Pip[4][4][5][2];
94 public final Port[] h = new Port[5] { port(), port(), port(), port(), port() };
95 public final Port[] v = new Port[5] { port(), port(), port(), port(), port() };
96 public final Port[] s = new Port[5] { port(), port(), port(), port(), port() };
97 public final Port nw, sw, se, ne;
98 public final Port n, s, w, e;
99 public final Port xout, yout;
101 public final Pip zin = pip( s[0], s[1], s[2], s[3], s[4]);
102 public final Pip win = pip( s[0], s[1], s[2], s[3], s[4]);
103 public final Pip xin = pip(nw, ne, sw, se, s[0], s[1], s[2], s[3], s[4]);
104 public final Pip yin = pip(n, s, e, w, s[0], s[1], s[2], s[3], s[4]);
106 public final Pip wpip = pip(win, zin, and(win, zin), fb);
107 public final Pip zpip = pip(zin, one, zero);
109 public final Lut xlut = lut(xpip, wmux, ypip);
110 public final Lut ylut = lut(xpip, wmux, ypip);
111 public final Mux zmux = mux(xlut, ylut, zpip);
112 public final Reg reg = reg(zmux);
113 public final Pip center = pip(reg, zmux);
115 public final Pip fb = pip(zmux, reg);
117 public final Pip center = pip(zmux, reg);
118 public final Pip xout = pip(xlut, center);
119 public final Pip yout = pip(ylut, center);
121 public final Pip oe = pip(one, h[4], v[4]);
122 public final Buf out = buf(fb, oe);
124 public final Pip[] o = pip5(out, s);
125 public final Pip[] h = pip5(h, s);
126 public final Pip[] v = pip5(v, s);
133 public class At94k extends At40k {