cleanup of Marina test code
[fleet.git] / src / edu / berkeley / fleet / marina / InstructionStopper.java
1 package edu.berkeley.fleet.marina;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import com.sun.electric.tool.simulation.test.*;
7
8 import edu.berkeley.fleet.api.Dock;
9 import edu.berkeley.fleet.api.Instruction;
10 import edu.berkeley.fleet.marina.MarinaFleet;
11
12 import static edu.berkeley.fleet.marina.Marina.INSTRUCTION_LENGTH;
13
14 /**
15  * InstructionStopper is a scaffold that lets us create a 36 bit propperStopper
16  * by using a 52 bit propperStopper and throwing away the unused bits.
17  */
18 public class InstructionStopper extends ProperStopper {
19
20     private static final int INSTRUCTION_SEND_NDX = 1;
21     private static final int INSTRUCTION_RECIRCULATE_NDX = 0;
22     private final String INSTR_RING_CONTROL_PATH;
23
24     public InstructionStopper(String propInst,
25                               ChainControl controlChain,
26                               ChainControl dataChain,
27                               ChainControl reportChain,
28                               ChipModel model,
29                               boolean clockHack,
30                               Indenter indenter, String counterPath) {
31         super(propInst, controlChain, dataChain, reportChain, model, clockHack, indenter, counterPath);
32         INSTR_RING_CONTROL_PATH = propInst+".tapStage@2";
33     }
34
35     /** put one Instruction into InstructionStopper */
36     public void fill(Instruction inst) {
37         MarinaPacket mp = new MarinaPacket(inst);
38         MarinaTest.indenter.prln("  inserting instruction: " +
39                                  inst.toString().substring(inst.toString().indexOf(':')+1)
40                                  +"\n      "+mp);
41         super.fill(mp);
42     }
43
44     /* put a torpedo into the InstructionStopper */
45     public void fillTorpedo() {
46         MarinaTest.indenter.prln("  inserting torpedo");
47         super.fill(new MarinaPacket(MarinaPacket.null_word, true, MarinaPacket.null_path));
48     }
49
50     public void fill(Instruction[] instructions) { fill(instructions, false); }
51     public void fill(Instruction[] instructions, boolean repeat) { fill(instructions, repeat, false); }
52     public void fill(Instruction[] instructions, boolean repeat, boolean leaveStopped) {
53         enableInstructionSend(false);
54         enableInstructionRecirculate(true);
55         for(Instruction i : instructions)
56             if (i!=null) {
57                 fill(i);
58             } else {
59                 fillTorpedo();
60             }
61         enableInstructionRecirculate(repeat);
62         enableInstructionSend(true);
63         if (!leaveStopped) run();
64     }
65     public void enableInstructionSend(boolean b) {
66         BitVector bv = controlChain.getInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
67         bv.set(INSTRUCTION_SEND_NDX, b);
68         controlChain.setInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
69         controlChain.shift(Marina.CONTROL_CHAIN, false, true);
70     } 
71     public void enableInstructionRecirculate(boolean b) {
72         BitVector bv = controlChain.getInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
73         bv.set(INSTRUCTION_RECIRCULATE_NDX, b);
74         controlChain.setInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
75         controlChain.shift(Marina.CONTROL_CHAIN, false, true);
76     }
77 }