revise startCounters()
[fleet.git] / src / com / sun / vlsi / chips / marina / test / Marina.java
1 package com.sun.vlsi.chips.marina.test;
2 /* -*- tab-width: 4 -*- */
3 import com.sun.electric.tool.simulation.test.*;
4
5 import edu.berkeley.fleet.api.Instruction;
6 import edu.berkeley.fleet.marina.MarinaPath;
7
8 /** The Marina object will eventually represent the Marina test chip.  
9  * Right now, it doesn't do much of anything. It just helps me exercise
10  * my test infrastructure. */
11 public class Marina {
12
13     public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE  = 5;
14     public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO = MarinaPath.SIGNAL_BIT_INDEX;
15
16        
17     public static int TOKEN_FIFO_CAPACITY = 3;
18     
19     //public static boolean kesselsCounter = true;
20     public static boolean kesselsCounter = false;
21     public static boolean omegaCounter = false;
22
23     public static final String DATA_CHAIN =    kesselsCounter ? "marina.marina_data" : "marina.ivan_data";      
24     public static final String CONTROL_CHAIN = kesselsCounter ? "marina.marina_control" : "marina.ivan_control";
25     public static final String REPORT_CHAIN =  kesselsCounter ? "marina.marina_report" : "marina.ivan_report";
26     public static final String DUKE_CHAIN   = "marina.duke";
27
28     public static String prefix = "marinaGu@0.outDockW@"+(kesselsCounter?"3":"0")+".marinaOu@"+(kesselsCounter?"1":"0")+".";
29     public static String MASTER_CLEAR = "mc";
30
31
32     /*
33     private static String prefix = "outDockW@"+(kesselsCounter?"3":"0")+".marinaOu@1.";
34     private static String MASTER_CLEAR = "EXTmasterClear";
35     */
36
37     private static final String OLC_PATH_EVEN = 
38         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@1"; // bits 2,4,6
39     private static final String OLC_PATH_ODD = 
40         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@2"; // bits 1,3,5
41     public static final String OLC_PATH_KESSEL = 
42         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.counte@0.adamScan@1.scanEx6h@";
43     private static final String ILC_PATH_ODD = 
44         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@0"; // bits 1,3,5,7
45     private static final String ILC_PATH_EVEN = 
46         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@1"; // bits 2,4,6,8
47     private static final String FLAGS_PATH = 
48         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.scanEx3h@0";
49
50     private static final String INSTR_RING_CONTROL_PATH = 
51         prefix+"southFif@1.tapPropS@1.tapStage@2";
52     private static final String TOK_FIFO_PATH =
53         prefix+"tokenFIF@1";
54     private static final String INSTRUCTION_COUNTER_PATH =
55         prefix+"southFif@1.tapPropS@1.instruct@0";
56     private static final String DATA_COUNTER_PATH =
57         prefix+"northFif@1.fillDrai@1.instruct@0";
58     private static final String TOK_PRED_PATH =
59         prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx2h@0.scanCell@10";
60
61     private static final int COUNTER_LENGTH = 34;
62     private static final int INSTRUCTION_SEND_NDX = 1;
63     private static final int INSTRUCTION_RECIRCULATE_NDX = 0;
64
65     public static final int INSTRUCTION_LENGTH = 36;
66         
67     private static final int A_FLAG_NDX = 0;
68     private static final int B_FLAG_NDX = 1;
69         
70     public static final int SOUTH_RING_CAPACITY = 11;
71         
72     // ILC appears in scan chain as "count[1:6], zLo, i, dLo"
73     public class Ilc {
74         // value is bit reversed and complemented
75         private int value;
76         private Ilc() {
77             shiftReport(true, false);
78             BitVector odd  = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_ODD).bitReverse().not();
79             BitVector even = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_EVEN).bitReverse().not();
80             BitVector ret  = new BitVector(8, "olc");
81             for(int i=0; i<4; i++) {
82                 ret.set(i*2+1, odd.get(i));
83                 ret.set(i*2,   even.get(i));
84             }
85             value = (int)ret.toLong();
86         }
87         /** Get the inner loop counter done bit. */
88         public boolean getDone() {
89             return (value & 0x40) != 0;
90         }
91         /** Get the inner loop counter infinity bit */
92         public boolean getInfinity() {
93             return (value & 0x80) != 0;
94         }
95         /** Get the 6 bits of count of the inner loop counter */
96         public int getCount() {
97             return value & 0x3f;
98         }
99         public String toString() {
100             return "[ilc, count="+getCount()+", infinity="+getInfinity()+", done="+getDone()+"]";
101         }
102     }
103         
104     private final Indenter indenter;
105
106     // The name of the scan chain
107     // The instance path, from the top cell of the netlist, of the instance of infinityWithCover 
108     public final ChainControls cc;           // specifies the scan chain
109     private final ChipModel model;
110     public final ProperStopper data;
111     public final InstructionStopper instrIn;
112     
113     private void prln(String msg) {indenter.prln(msg);}
114     private void pr(String msg) {indenter.pr(msg);}
115     
116     /** Shift the report scan chain */
117     public void shiftReport(boolean readEnable, boolean writeEnable) {
118         cc.shift(REPORT_CHAIN, readEnable, writeEnable);
119     }
120     
121     /** Shift the report scan chain */
122     private void shiftControl(boolean readEnable, boolean writeEnable) {
123         cc.shift(CONTROL_CHAIN, readEnable, writeEnable);
124     }
125         
126     /** Shift the data scan chain */
127     private void shiftData(boolean readEnable, boolean writeEnable) {
128         cc.shift(DATA_CHAIN, readEnable, writeEnable);
129     }
130
131     /** Shift the data scan chain */
132     public void shiftDuke(boolean readEnable, boolean writeEnable) {
133         cc.shift(DUKE_CHAIN, readEnable, writeEnable);
134     }
135
136     public Marina(ChainControls cc, ChipModel model, boolean clockHack, Indenter indenter) {
137         this.cc = cc;
138         this.model = model;
139         this.indenter = indenter;
140         data = new ProperStopper("north fifo",
141                                  prefix+"northFif@1.fillDrai@1.properSt@1",
142                                  cc, model, clockHack, indenter,
143                                  prefix+"northFif@1.fillDrai@1.instruct@0.cntScnTh@1.cntScnOn@1");
144         instrIn = new InstructionStopper("south fifo",
145                                          prefix+"southFif@1.tapPropS@1.properSt@1", 
146                                          cc, model, clockHack, indenter,
147                                          prefix+"southFif@1.tapPropS@1.instruct@0.cntScnTh@1.cntScnOn@1");
148     }
149
150     int northCount = 0;
151     int southCount = 0;
152
153     public void stopAndResetCounters() {
154         instrIn.setCounterEnable(false);
155         data.setCounterEnable(false);
156         cc.shift(DATA_CHAIN, true, false);        
157         northCount = data.getCounterValue();
158         southCount = instrIn.getCounterValue();
159         data.setCounterValue(0);
160         instrIn.setCounterValue(0);
161     }
162     public void startCounters() { startCounters(true, true); }
163     public void startCounters(boolean south, boolean north) {
164         instrIn.setCounterEnable(south);
165         data.setCounterEnable(north);
166     }
167     public int getNorthCount() { return northCount; }
168     public int getSouthCount() { return southCount; }
169
170
171     public void masterClear() {
172         final double WIDTH = 10; // ns
173         // Put a high going pulse on the internal chip master clear signal
174         if (model instanceof VerilogModel) {
175
176             data.clear();
177             instrIn.clear();
178
179             VerilogModel vm = (VerilogModel)model;
180             //
181             // In real life the flags come up with some undefined
182             // value.  In verilog we need to prevent the X'es from
183             // propagating, so we force the flags to a known value
184             //
185             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_", 0);
186             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_", 1);
187             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_", 0);
188             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_", 1);
189
190             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_", 1);
191             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_", 0);
192
193             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50", 0);       // A
194             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50", 0);       // B
195             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_", 0); // C
196
197             // possible C-flag inputs
198             vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]", 0);
199             vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]", 0);
200
201             // force the OLC to zero
202             if (!kesselsCounter)
203                 for(int i=1; i<=6; i++)
204                     vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]", (i==1)?0:1);
205
206             // set the ILC input to 1
207             for(int i=1; i<=8; i++) {
208                 if (i!=7)
209                     vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"]", (i==1)?0:1);
210             }
211
212             vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 1);
213             model.waitNS(1000);
214             vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 0);
215             model.waitNS(1000);
216
217             vm.setNodeState(MASTER_CLEAR, 1);
218             model.waitNS(1000);
219             vm.setNodeState(MASTER_CLEAR, 0);
220             model.waitNS(1000);
221
222             // pulse ilc[load] and olc[load]
223             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_", 1);
224             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_", 1);
225             vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_", 1);
226             if (!kesselsCounter)
227                 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_", 1);
228             model.waitNS(100);
229             model.waitNS(1);
230             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_");
231             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_");
232             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_");
233             if (!kesselsCounter)
234                 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_");
235
236             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_");
237             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_");
238             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_");
239             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_");
240
241             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_");
242             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_");
243
244             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50");
245             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50");
246
247             // Every move instruction, even those with Ti=0,Di=0,
248             // loads the C-flag.  It will get loaded with an "X",
249             // which will then leak into the flags and from there the
250             // predicate.
251             vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_");
252             vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]");
253             vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]");
254             vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire");
255
256             for(int i=1; i<=8; i++) {
257                 if (i!=7)
258                     vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"] ");
259             }
260             model.waitNS(1000);
261
262             if (!kesselsCounter)
263                 for(int i=1; i<=6; i++)
264                     vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]");
265
266             // the proper stopper states come up in an undefined ("X")
267             // state, so under Verilog we need to force them to a
268             // known state
269
270             data.idle();
271             instrIn.idle();
272
273         } else if (model instanceof NanosimModel) {
274             NanosimModel nModel = (NanosimModel) model;
275             /*
276             nModel.setNodeVoltage(prefix+"sid[9]",1.0);
277             nModel.setNodeVoltage(prefix+"sic[9]",1.0);
278             nModel.setNodeVoltage(prefix+"sir[9]",1.0);
279             nModel.waitNS(WIDTH);
280             nModel.setNodeVoltage(prefix+"sid[9]",0.0);
281             nModel.setNodeVoltage(prefix+"sic[9]",0.0);
282             nModel.setNodeVoltage(prefix+"sir[9]",0.0);
283             nModel.waitNS(1);
284             */
285             nModel.setNodeVoltage(MASTER_CLEAR,1.0);
286             nModel.waitNS(WIDTH);
287             nModel.setNodeVoltage(MASTER_CLEAR,0.0);
288             nModel.waitNS(1);
289         } else {
290
291             mc0.setLogicState(true);
292             mc1.setLogicState(true);
293             model.waitNS(1000);
294             mc0.setLogicState(false);
295             mc1.setLogicState(false);
296             model.waitNS(1000);
297
298         }
299         resetAfterMasterClear();
300     }
301
302     JtagLogicLevel mc0;
303     JtagLogicLevel mc1;
304
305     private void resetAfterMasterClear() {
306         // The following call to ChainControl.resetInBits() is vital!
307         // If you forget, then the inBits member initializes 
308         // with random data. Then when you do your first write,
309         // some bits are written randomly.
310         cc.resetInBits();
311
312         // For reset, I want to clear all the stoppers simultaneously
313         data.clear();
314         //tokOut.clear();
315         instrIn.clear();
316         
317         data.stop();
318         //tokOut.stop();
319         instrIn.stop();
320         
321         data.resetAfterMasterClear();
322         //tokOut.resetAfterMasterClear();
323         instrIn.resetAfterMasterClear();
324     }
325
326
327     /** Get the 6 bit outer loop counter. */
328     public int getOLC() {
329         shiftReport(true, false);
330         if (omegaCounter) {
331             BitVector bits = null;
332             for(int i=0; i<4; i++) {
333                 BitVector x = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_KESSEL+i);
334                 //System.out.println("bits are: " + x);
335                 bits = bits==null ? x : bits.cat(x);
336             }
337             System.out.print("  kesselsCounter = ");
338             int ret = 0;
339             boolean done = true;
340             boolean bad = false;
341             for(int bit=5; bit>=0; bit--) {
342                 boolean zeroOrTwo  = bits.get(4+bit*3);
343                 boolean zeroOrDone = bits.get(4+bit*3+1);
344                 if      ( zeroOrTwo && !zeroOrDone) {
345                     ret += (2<<bit);
346                     System.out.print("2");
347                     done = false;
348                 } else if (!zeroOrTwo && !zeroOrDone) {
349                     ret += (1<<bit);
350                     System.out.print("1");
351                     done = false;
352                 } else if ( zeroOrTwo &&  zeroOrDone) {
353                     System.out.print("0");
354                     bad = true;
355                     done = false;
356                 } else if (!zeroOrTwo &&  zeroOrDone) {
357                     System.out.print("_");
358                     if (!done) bad = true;
359                 }
360                 // FIXME: check for unreduced counter and warn about it
361             }
362             if (bad) System.out.print("  WARNING: UNREDUCED COUNTER VALUE!!!!!!");
363             System.out.println();
364             return ret;
365         } else if (kesselsCounter) {
366             BitVector bits = null;
367             for(int i=0; i<4; i++) {
368                 BitVector x = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_KESSEL+i);
369                 //System.out.println("bits are: " + x);
370                 bits = bits==null ? x : bits.cat(x);
371             }
372             //System.out.println("kesselsCounter = " + bits);
373             int first = 0;
374             int second = 0;
375             String hi="";
376             String lo="";
377             String latched="";
378             String res="";
379             for(int i=0; i<6; i++) {
380                 first  |= bits.get(4+i*3)   ? (1<<i) : 0;
381                 second |= bits.get(4+i*3+2) ? (1<<i) : 0;
382                 hi = (bits.get(4+i*3)   ? "1" : "0") + hi;
383                 lo = (bits.get(4+i*3+2)   ? "1" : "0") + lo;
384                 res =
385                     (   bits.get(4+i*3) && !bits.get(4+i*3+2) ? "X"
386                      : !bits.get(4+i*3) && !bits.get(4+i*3+2) ? "0"
387                      : !bits.get(4+i*3) &&  bits.get(4+i*3+2) ? "1"
388                      : "2")
389                     +res;
390                 latched = (bits.get(4+i*3+1)   ? "0" : "1") + latched;
391             }
392             System.out.println("kesselsCounter: "+
393                                "s[1]="+hi+
394                                " s[3]="+lo+
395                                " latched="+latched +
396                                " res="+res+
397                                " do[ins]="+(bits.get(0) ? "1" : "0")+
398                                " dec="+(bits.get(1) ? "1" : "0")+
399                                " flag[D][set]="+(bits.get(2) ? "1" : "0")+
400                                " resetting="+(bits.get(3) ? "1" : "0")+
401                                ""
402                                );
403             return (first+second);
404         } else {
405             BitVector odd = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_ODD).bitReverse();
406             BitVector even = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_EVEN).bitReverse();
407             odd = odd.not();
408             even = even.not();
409             BitVector bv = new BitVector(6, "olc");
410             for(int i=0; i<3; i++) {
411                 bv.set(i*2,   odd.get(i));
412                 bv.set(i*2+1, even.get(i));
413             }
414             return (int)bv.toLong();
415         }
416     }
417     /** Get the 7 bit inner loop counter. The MSB is the zero bit.
418      * The low order 6 bits are the count */
419     public Ilc getILC() {
420         return new Ilc();
421     }
422     /** Get the A flag */
423     public boolean getFlagA() {
424         shiftReport(true, false);
425         return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(A_FLAG_NDX);
426     }
427     /** Get the B flag */
428     public boolean getFlagB() {
429         shiftReport(true, false);
430         return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(B_FLAG_NDX);
431     }
432     /** return value of instruction counter. Instruction counter counts 
433      * the instructions flowing through 1/2 of alternating FIFO.
434      * Caution: instruction counter is written by all scans, 
435      * regardless of readEnable or writeEnable! */
436     public long getInstructionCounter() {
437         shiftData(true, false);
438         BitVector count = cc.getOutBits(DATA_CHAIN+"."+INSTRUCTION_COUNTER_PATH);
439         int sz = count.getNumBits(); 
440         MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
441                          " expected: "+COUNTER_LENGTH);
442         return count.bitReverse().toLong();
443     }
444     /** return value of data counter. Data counter counts items flowing
445      * through drain stage of data proper stopper. 
446      * Caution: data counter is written by all scans, 
447      * regardless of readEnable or writeEnable! */
448     public long getDataCounter() {
449         shiftData(true, false);
450         BitVector count = cc.getOutBits(DATA_CHAIN+"."+DATA_COUNTER_PATH);
451         int sz = count.getNumBits(); 
452         MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
453                          " expected: "+COUNTER_LENGTH);
454         return count.bitReverse().toLong();
455     }
456     /** Fill the "North" Fifo ring */
457     public void fillNorthProperStopper() {
458         BitVector data = new BitVector(37, "empty");
459         BitVector addr = new BitVector(14, "empty");
460         for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
461         for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
462         fillNorthProperStopper(new MarinaPacket(data, false, addr));
463     }
464     /** Fill the "North" Fifo ring */
465     public void fillNorthProperStopper(MarinaPacket mp) {
466         prln("inserting into north: " + mp);
467         this.data.fill(mp.toSingleBitVector());
468     }
469     /** Enable the transmission of instructions from the instruction
470      * ring test structure to the EPI FIFO. */
471     public void enableInstructionSend(boolean b) {
472         BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
473         bv.set(INSTRUCTION_SEND_NDX, b);
474         cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
475         shiftControl(false, true);
476     } 
477     /** Enable the recirculation of instructions within the South FIFO */
478     public void enableInstructionRecirculate(boolean b) {
479         BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
480         bv.set(INSTRUCTION_RECIRCULATE_NDX, b);
481         cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
482         shiftControl(false, true);
483     }
484     /** get the number of tokens in the token FIFO.
485      * This includes the Token successor wire, the token FIFO wires,
486      * and Token predecessor wire.
487      * Master clear clears the token FIFO. */
488     public int getNumTokens() {
489         shiftReport(true, false);
490         // get the token successor and token FIFO wires
491         BitVector bv = cc.getOutBits(REPORT_CHAIN+"."+TOK_FIFO_PATH);
492         int sz = bv.getNumBits();
493         MarinaTest.fatal(sz!=3, "wrong token FIFO size: "+sz+" expected: 3");
494         
495         // get the token predecessor wire
496         BitVector pred = cc.getOutBits(REPORT_CHAIN+"."+TOK_PRED_PATH);
497         sz = pred.getNumBits();
498         MarinaTest.fatal(sz!=1, "wrong token predecessor size: "+sz+" expected: 1");
499
500         // concatenate them
501         bv = bv.cat(pred);
502         sz = bv.getNumBits();
503         prln("Token state wires: "+bv.getState());
504         
505         int nbTok = 0;
506         for (int i=0; i<sz; i++) if (bv.get(i)) nbTok++;
507         return nbTok;
508     }
509     /** Configure the test probe so it measures the throughput of
510      * the north data FIFO. The test probe frequency is 8192 
511      * times slower than the FIFO throughput. This control has
512      * highest priority. */
513     public void probeDataCounter(Boolean b) {
514         data.setGeneralPurposeOutput(b);
515     }
516     /** Configure the test probe so it measures the throughput of
517      * the alternating instruction FIFO. The test probe frequency is
518      * 1/16384 of the FIFO throughput. This control has second
519      * highest priority. Thus the following two calls probe the
520      * instruction counter: 
521      *      probeDataCounter(false);
522      *      probeInstructionCounter(true)
523      */
524     public void enableInstructionCounter(Boolean b) {
525         instrIn.setGeneralPurposeOutput(b);
526     }
527
528     public void fillSouthProperStopper(Instruction i) {
529         instrIn.fill(i);
530     }
531     public void fillSouthProperStopper(Instruction[] instructions) { fillSouthProperStopper(instructions, false); }
532     public void fillSouthProperStopper(Instruction[] instructions, boolean repeat) { fillSouthProperStopper(instructions, repeat, false); }
533     public void fillSouthProperStopper(Instruction[] instructions, boolean repeat, boolean leaveStopped) {
534         enableInstructionSend(false);
535         enableInstructionRecirculate(true);
536         for(Instruction i : instructions)
537             if (i!=null) {
538                 instrIn.fill(i);
539             } else {
540                 instrIn.fillTorpedo();
541             }
542         enableInstructionRecirculate(repeat);
543         enableInstructionSend(true);
544         if (!leaveStopped) instrIn.run();
545     }
546
547     
548 }