marina: add some additional control over the proper stopper counter
[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) {
25         super(propInst, controlChain, dataChain, reportChain, model, clockHack, indenter,
26               propInst+".instruct@0.cntScnTh@1.cntScnOn@1");
27         INSTR_RING_CONTROL_PATH = propInst+".tapStage@2";
28     }
29
30     /** put one Instruction into InstructionStopper */
31     public void fill(Instruction inst) {
32         MarinaPacket mp = new MarinaPacket(inst);
33         MarinaTest.indenter.prln("  inserting instruction: " +
34                                  inst.toString().substring(inst.toString().indexOf(':')+1)
35                                  +"\n      "+mp);
36         super.fill(mp);
37     }
38
39     /* put a torpedo into the InstructionStopper */
40     public void fillTorpedo() {
41         MarinaTest.indenter.prln("  inserting torpedo");
42         super.fill(new MarinaPacket(MarinaPacket.null_word, true, MarinaPacket.null_path));
43     }
44
45     public void fill(Instruction[] instructions) { fill(instructions, false); }
46     public void fill(Instruction[] instructions, boolean repeat) { fill(instructions, repeat, false); }
47     public void fill(Instruction[] instructions, boolean repeat, boolean leaveStopped) {
48         enableInstructionSend(false);
49         enableInstructionRecirculate(true);
50         for(Instruction i : instructions)
51             if (i!=null) {
52                 fill(i);
53             } else {
54                 fillTorpedo();
55             }
56         enableInstructionRecirculate(repeat);
57         enableInstructionSend(true);
58         if (!leaveStopped) run();
59     }
60     public void enableInstructionSend(boolean b) {
61         BitVector bv = controlChain.getInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
62         bv.set(INSTRUCTION_SEND_NDX, b);
63         controlChain.setInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
64         controlChain.shift(Marina.CONTROL_CHAIN, false, true);
65     } 
66     public void enableInstructionRecirculate(boolean b) {
67         BitVector bv = controlChain.getInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
68         bv.set(INSTRUCTION_RECIRCULATE_NDX, b);
69         controlChain.setInBits(Marina.CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
70         controlChain.shift(Marina.CONTROL_CHAIN, false, true);
71     }
72 }