bda75e8abc72308b87042963a87da05cd7898784
[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() {
19         super("funnel");
20         Module.SinkPort    outp = createOutputPort("out", WIDTH_PACKET, "");
21         Module.SourcePort  in1p = createInputPort("in1", WIDTH_PACKET);
22         Module.SourcePort  in2p = createInputPort("in2", WIDTH_PACKET);
23         new Event(new Object[] { in1p, outp },
24                   new Action[] { in1p, outp,
25                                  new AssignAction(outp, in1p) });
26         new Event(new Object[] { in2p, outp },
27                   new Action[] { in2p, outp,
28                                  new AssignAction(outp, in2p) });
29     }
30
31     public static class FunnelInstance extends Module.InstantiatedModule implements FabricElement {
32         private FabricElement in1 = null;
33         private FabricElement in2 = null;
34         public FabricElement out = null;
35         public Module.Port getOutputPort() { return getOutputPort("out"); }
36         public Module.Port getInputPort()  { throw new RuntimeException("funnel has multiple inputs"); }
37         public FunnelInstance(Module thisModule, Module.Port p1, Module.Port p2) {
38             super(thisModule, new FunnelModule());
39             p1.connect(this.getInputPort("in1"));
40             p2.connect(this.getInputPort("in2"));
41         }
42         public FunnelInstance(Module thisModule, FabricElement in1, FabricElement in2) {
43             super(thisModule, new FunnelModule());
44             this.in1 = in1;
45             this.in2 = in2;
46             in1.addOutput(this, this.getInputPort("in1"));
47             in2.addOutput(this, this.getInputPort("in2"));
48         }
49         public void addOutput(FabricElement out, Module.Port outPort) {
50             this.out = out;
51             getOutputPort("out").connect((Module.SinkPort)outPort);
52         }
53         public void addInput(FabricElement in, Module.Port source) {
54             throw new RuntimeException("cannot add inputs to a funnel once constructed");
55         }
56         public FpgaPath getPath(FabricElement dest, BitVector signal) {
57             return out.getPath(dest, signal);
58         }
59     }
60
61 }