FPGA-Fleet updates
[fleet.git] / src / edu / berkeley / fleet / slipway / SlipwayBenkoBox.java
1 package edu.berkeley.fleet.slipway;
2 import edu.berkeley.fleet.api.*;
3 import edu.berkeley.fleet.api.BenkoBox;
4 import java.util.*;
5
6 /** anything that has a destination address on the switch fabric */
7 public class SlipwayBenkoBox extends BenkoBox {
8         
9     private final String name;
10     private final SlipwayShip ship;
11     private  Destination[] ports;
12         
13     public Iterable<Destination> getDestinations() {
14         ArrayList<Destination> ret = new ArrayList<Destination>();
15         for(Destination d : ports) ret.add(d);
16         return ret;
17     }
18     private static int default_addr;
19     private static int default_instr_addr;
20
21     public int bits;
22     public int addr = (default_addr++);
23     public int instr_bits;
24     public int instr_addr = (default_instr_addr++);
25     protected boolean special = false;
26     protected boolean ihorn = false;
27     protected boolean dhorn = false;
28     void service() { }
29     public boolean special() { return special; }
30     public boolean ihorn() { return ihorn; }
31     public boolean dhorn() { return dhorn; }
32     public boolean inbox;
33     public boolean isInbox() { return inbox; }
34     public boolean isOutbox() { return !inbox; }
35     public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name) {
36         this(inbox, ship, name, false, false, false);
37     }
38     public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name, boolean special) {
39         this(inbox, ship, name, special, false, false);
40     }
41     public SlipwayBenkoBox(boolean inbox, SlipwayShip ship, String name, boolean special, boolean ihorn, boolean dhorn) {
42         this.inbox = inbox;
43         this.special = special;
44         this.dhorn = dhorn;
45         this.ihorn = ihorn;
46         this.ship = ship;
47         this.name = name;
48         String[] ports = new String[] { "" };
49         this.ports = new Destination[ports.length];
50         for(int i=0; i<ports.length; i++)
51             this.ports[i] =
52                 ports[i].equals("")
53                 ? this
54                 : new VirtualPort(ports[i]);
55         ship.addBenkoBox(name, this);
56     }
57
58     public void addDestination(String dest) {
59         Destination[] newports = new Destination[ports.length+1];
60         System.arraycopy(ports, 0, newports, 0, ports.length);
61         newports[newports.length-1] = new VirtualPort(dest);
62         ports = newports;
63     }
64
65     public class VirtualPort extends Destination {
66         public String name;
67         public VirtualPort(String name) { this.name = name; }
68         public String getDestinationName() { return name; }
69         public Ship getShip() { return SlipwayBenkoBox.this.getShip(); }
70         public void addDataFromFabric(long data) { SlipwayBenkoBox.this.addDataFromFabric(name, (int)data); }
71         public String toString() { return getShip()+"."+getName(); }
72         // fixme
73         public long addr = (default_addr++);
74     }
75         
76     /** adds one token to the port from the switch fabric side */
77     void addTokenFromFabric() { addDataFromFabric(0); }
78         
79     /** adds the included datum to the port from the switch fabric  side */
80     void addDataFromFabric(int datum)  { throw new RuntimeException("this should never happen!"); }
81     void addDataFromFabric(String name, int datum)  {
82         addDataFromFabric(datum);   
83     }
84
85     /** adds one token to the port from the ship side */
86     public void addTokenFromShip() { addDataFromShip(0); }
87         
88     /** adds the included datum to the port from the switch fabric side */
89     public void addDataFromShip(int datum) { throw new RuntimeException("this should never happen!"); }
90
91     public Ship getShip() { return ship; }
92
93     public Fleet getFleet() { return getShip().getFleet(); }
94
95     public String toString() { return ship+"."+name; }
96
97     public String getName() { return name; }
98
99     public int getInstructionFifoLength() { return 4; }
100
101 }