move ExperimentUtils to demos directory
[slipway.git] / src / edu / berkeley / slipway / demos / ExperimentUtils.java
1 package edu.berkeley.slipway.demos;
2
3 import java.io.*;
4 import java.util.*;
5 import java.awt.*;
6 import com.atmel.fpslic.*;
7 import edu.berkeley.slipway.*;
8 import edu.berkeley.slipway.gui.*;
9 import static com.atmel.fpslic.FpslicConstants.*;
10
11 /** useful test structures */
12 public class ExperimentUtils {
13
14     /** 
15      *  Creates a 2x2 cell frequency divider with top left corner at
16      *  c, taking input from c.north() and providing output on the
17      *  orthogonal axis at c.south().  Returns c.south().south() for
18      *  easy daisy-chaining.
19      */
20     public static FpslicDevice.Cell divider(FpslicDevice.Cell c) {
21         FpslicDevice.Cell detect1 = c;
22         FpslicDevice.Cell detect2 = c.east();
23
24         detect1.yi(NORTH);
25         detect1.ylut(LUT_SELF);
26         detect1.xlut(LUT_OTHER & (~LUT_Z));
27         detect1.c(YLUT);
28         detect1.t(TMUX_FB);
29         detect1.f(false);
30         detect1.b(false);
31
32         detect2.xi(NW);
33         detect2.ylut(LUT_OTHER);
34         detect2.xlut((~LUT_SELF) & LUT_Z);
35         detect2.c(YLUT);
36         detect2.t(TMUX_FB);
37         detect2.f(false);
38         detect2.b(false);
39
40         detect1.south().yi(EAST);
41         detect1.south().xi(NE);
42         detect1.south().c(YLUT);
43         detect1.south().t(TMUX_FB);
44         detect1.south().f(false);
45         detect1.south().b(false);
46         detect1.south().ylut( (LUT_OTHER    & (~LUT_SELF)) |
47                               ((~LUT_OTHER) &   LUT_Z)
48                               );
49         detect1.south().xlut( (LUT_SELF    & (~LUT_OTHER)) |
50                               ((~LUT_SELF) &   LUT_Z)
51                               );
52
53         detect2.south().yi(WEST);
54         detect2.south().xi(NW);
55         detect2.south().c(YLUT);
56         detect2.south().t(TMUX_FB);
57         detect2.south().f(false);
58         detect2.south().b(false);
59         detect2.south().ylut( (LUT_OTHER    & (LUT_SELF)) |
60                               ((~LUT_OTHER) &   LUT_Z)
61                               );
62         detect2.south().xlut( (LUT_SELF    & (~LUT_OTHER)) |
63                               ((~LUT_SELF) &   LUT_Z)
64                               );
65
66         if (c.south().south()==null) return null;
67         if (c.south().south().south()==null) return null;
68         return c.south().south();
69     }
70
71     /** set up the scan cell */
72     public static void setupScanCell(FpslicDevice fpslic) {
73         fpslic.cell(23,15).h(3, true);
74         fpslic.cell(23,15).yi(L3);
75         fpslic.cell(23,15).ylut(0xAA);
76         fpslic.iob_right(15, true).enableOutput(WEST);
77
78         fpslic.cell(23,0).ylut(0x00);
79         fpslic.iob_right(0, true).enableOutput(WEST);
80         fpslic.flush();
81     }
82
83 }