1 package edu.berkeley.slipway.demos;
3 import static java.awt.event.KeyEvent.*;
4 import edu.berkeley.slipway.*;
5 import com.atmel.fpslic.*;
6 import static com.atmel.fpslic.FpslicConstants.*;
7 import static com.atmel.fpslic.FpslicUtil.*;
8 import edu.berkeley.slipway.gui.*;
10 import java.awt.event.*;
11 import java.awt.color.*;
12 import org.ibex.util.*;
16 public class Demo4 implements KeyListener {
18 public static void main(String[] s) throws Exception {
21 public SlipwayBoard board;
22 public FpslicDevice device;
23 public Demo4() throws Exception {
24 board = new SlipwayBoard();
25 device = (FpslicDevice)board.getDevice();
27 public void go() throws Exception {
28 long begin = System.currentTimeMillis();
29 //FpslicUtil.readMode4(new ProgressInputStream("configuring fabric", System.in, 111740), device);
30 long end = System.currentTimeMillis();
31 Log.info(Demo.class, "finished in " + ((end-begin)/1000) + "s");
35 Log.info(Demo.class, "issuing command");
37 FpslicDevice.Cell root = device.cell(5,5);
67 device.iob_bot(12, false).enableOutput(NW);
68 FpslicDevice.Cell c = device.cell(12, 0);
70 while(c.east() != null && c.east().east() != null) {
76 FpslicDevice.Cell div = device.cell(19, 21);
78 AsyncPaperDemo.divider(div);
79 div = div.south().south();
80 if (div == null) break;
85 for(int x=2; x<MAX+1; x++) {
86 c = device.cell(x, 20);
87 FpslicDevice.Cell bridge = x==2 ? c.sw() : c.nw();
88 FpslicDevice.Cell pred = x==MAX ? c.south() : c.east();
89 FpslicDevice.Cell next = x==2 ? c.south() : c.west();
90 muller(c, pred, bridge, next);
93 bridge = x==MAX ? c.ne() : c.se();
94 pred = x==2 ? c.north() : c.west();
95 next = x==MAX ? c.north() : c.east();
96 muller(c, pred, bridge, next);
98 //device.cell(MAX+0,20).yi(WEST);
99 //device.cell(MAX+0,20).ylut(LUT_SELF);
100 //device.cell(MAX+1,20).yi(WEST);
101 //device.cell(MAX+1,20).ylut(LUT_SELF);
102 device.cell(MAX+2,20).yi(WEST);
103 device.cell(MAX+2,20).ylut(LUT_SELF);
104 device.cell(MAX+2,20).xlut(LUT_OTHER);
105 device.cell(18,20).ylut(LUT_SELF);
110 public void go2() throws Exception {
114 vis = new Gui3(device, board);
115 vis.addKeyListener(this);
116 Frame fr = new Frame();
117 fr.setLayout(new BorderLayout());
118 fr.add(vis, BorderLayout.CENTER);
120 fr.setSize(900, 900);
124 //synchronized(Demo.class) { Demo.class.wait(); }
126 try { Thread.sleep(500); } catch (Exception e) { }
133 public void muller(FpslicDevice.Cell c, FpslicDevice.Cell pred, FpslicDevice.Cell bridge, FpslicDevice.Cell next) {
135 bridge.xlut(LUT_OTHER);
143 c.ylut((LUT_SELF & ~LUT_OTHER) |
144 (LUT_Z & ~LUT_OTHER) |
148 public void setupScanCell() {
149 FpslicDevice fpslic = (FpslicDevice)device;
150 fpslic.cell(23,15).h(3, true);
151 fpslic.cell(23,15).yi(L3);
152 fpslic.cell(23,15).ylut(0xAA);
153 fpslic.iob_right(15, true).enableOutput(WEST);
155 fpslic.cell(23,0).ylut(0x00);
156 fpslic.iob_right(0, true).enableOutput(WEST);
160 public void keyTyped(KeyEvent k) { }
161 public void keyReleased(KeyEvent k) { }
162 public void keyPressed(KeyEvent k) {
163 switch(k.getKeyCode()) {
170 for(int x=0; x<4; x++)
171 for(int y=0; y<4; y++)
173 for(int x=0; x<4; x++)
174 for(int y=0; y<4; y++)
177 public void scan(final GuiCell c) {
179 final FpslicDevice.Cell cell = (FpslicDevice.Cell)(Object)c.fpslicCell;
180 scan(device, cell, YLUT, true);
183 board.readFpgaData(new BCB(c));
184 scan(device, cell, YLUT, false);
185 } catch (IOException e) {
186 throw new RuntimeException(e);
190 public static void scan(FpslicDevice dev, FpslicDevice.Cell cell, int source, boolean setup) {
192 //if (source != NONE) cell.c(source);
193 if (cell.b()) cell.b(false);
194 if (cell.f()) cell.f(false);
196 if (cell.out(L3)!=setup) cell.out(L3, setup);
197 if (cell.vx(L3)!=setup) cell.v(L3, setup);
199 FpslicDevice.SectorWire sw = cell.vwire(L3);
200 //System.out.println("wire is: " + sw);
202 if (sw.row > (12 & ~0x3) && sw.north()!=null && sw.north().drives(sw))
203 sw.north().drives(sw, false);
204 while(sw.row > (12 & ~0x3) && sw.south() != null) {
205 //System.out.println(sw + " -> " + sw.south());
206 if (sw.drives(sw.south())!=setup) sw.drives(sw.south(), setup);
209 if (sw.row < (12 & ~0x3) && sw.south() != null && sw.south().drives(sw))
210 sw.north().drives(sw, false);
211 while(sw.row < (12 & ~0x3) && sw.north() != null) {
212 //System.out.println(sw + " -> " + sw.north());
213 if (sw.drives(sw.north())!=setup) sw.drives(sw.north(), setup);
217 //cell = dev.cell(19, 15);
218 cell = dev.cell(cell.col, 15);
220 System.out.println("cell is " + cell);
229 if (cell.hx(L3) != setup) cell.h(L3, setup);
230 if (cell.vx(L3) != setup) cell.v(L3, setup);
233 if (sw.west()!=null && sw.west().drives(sw)) { sw.west().drives(sw, false); }
234 while(sw.east() != null) {
235 //System.out.println(sw + " -> " + sw.east());
236 if (sw.drives(sw.east())!=setup) sw.drives(sw.east(), setup);
243 private class BCB extends SlipwayBoard.ByteCallback {
245 public BCB(GuiCell c) {
248 public void call(byte b) throws Exception {
249 boolean on = (b & 0x80) != 0;