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