add new urjtag-based code, fjmem
[fleet.git] / src / edu / berkeley / fleet / fpga / FunnelModule.java
1 package edu.berkeley.fleet.fpga;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.two.*;
4 import edu.berkeley.fleet.*;
5 import java.lang.reflect.*;
6 import edu.berkeley.sbp.chr.*;
7 import edu.berkeley.sbp.misc.*;
8 import edu.berkeley.sbp.meta.*;
9 import edu.berkeley.sbp.util.*;
10 import java.util.*;
11 import java.io.*;
12 import static edu.berkeley.fleet.two.FleetTwoFleet.*;
13 import static edu.berkeley.fleet.fpga.verilog.Verilog.*;
14
15
16 public class FunnelModule extends Module {
17
18     public FunnelModule(Fpga fpga) {
19         super("funnel");
20         Module.SinkPort    outp = createOutputPort("out", fpga.WIDTH_PACKET);
21         Module.SourcePort  in1p = createInputPort("in1", fpga.WIDTH_PACKET);
22         Module.SourcePort  in2p = createInputPort("in2", fpga.WIDTH_PACKET);
23
24         // FIXME: biased towards in2p side
25         new Event(new Object[] { in1p, outp, "!"+in2p.isFull() },
26                   new Action[] { in1p, outp,
27                                  new AssignAction(outp, in1p) });
28         new Event(new Object[] { in2p, outp },
29                   new Action[] { in2p, outp,
30                                  new AssignAction(outp, in2p) });
31     }
32
33     public static class FunnelInstance extends Module.InstantiatedModule implements FabricElement {
34         private FabricElement in1 = null;
35         private FabricElement in2 = null;
36         public FabricElement out = null;
37         public Module.SourcePort getOutputPort() { return getOutputPort("out"); }
38         public Module.Port getInputPort()  { throw new RuntimeException("funnel has multiple inputs"); }
39         public FunnelInstance(Fpga fpga, Module thisModule, Module.SourcePort p1, Module.SourcePort p2) {
40             super(thisModule, new FunnelModule(fpga));
41             if (p1 != null) p1.connect(this.getInputPort("in1"));
42             if (p2 != null) p2.connect(this.getInputPort("in2"));
43         }
44         public FunnelInstance(Fpga fpga, Module thisModule, FabricElement in1, FabricElement in2) {
45             super(thisModule, new FunnelModule(fpga));
46             this.in1 = in1;
47             this.in2 = in2;
48             in1.addOutput(this, this.getInputPort("in1"));
49             in2.addOutput(this, this.getInputPort("in2"));
50         }
51         public void addOutput(FabricElement out, Module.Port outPort) {
52             this.out = out;
53             getOutputPort("out").connect((Module.SinkPort)outPort);
54         }
55         public void addInput(FabricElement in, Module.Port source) {
56             throw new RuntimeException("cannot add inputs to a funnel once constructed");
57         }
58         public int      getPathLength(FpgaDestination dest) { return out.getPathLength(dest)+1; }
59         public FpgaPath getPath(FpgaDestination dest, BitVector signal) {
60             return out.getPath(dest, signal);
61         }
62     }
63
64 }