1db7833823765329e70866a899e8504de54e160c
[fleet.git] / testCode / com / sun / vlsi / chips / marina / test / Marina.java
1 package com.sun.vlsi.chips.marina.test;
2 /* -*- tab-width: 4 -*- */
3 import com.sun.async.test.BitVector;
4 import com.sun.async.test.ChainControl;
5 import com.sun.async.test.ChipModel;
6 import com.sun.async.test.JtagTester;
7 import com.sun.async.test.NanosimModel;
8 import com.sun.async.test.VerilogModel;
9
10 import edu.berkeley.fleet.api.Instruction;
11 import edu.berkeley.fleet.marina.MarinaPath;
12
13 /** The Marina object will eventually represent the Marina test chip.  
14  * Right now, it doesn't do much of anything. It just helps me exercise
15  * my test infrastructure. */
16 public class Marina {
17
18     public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE  = 5;
19     public static final int INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO = MarinaPath.SIGNAL_BIT_INDEX;
20
21     public static final String DATA_CHAIN =    "marina.marina_data";      
22     public static final String CONTROL_CHAIN = "marina.marina_control";
23     public static final String REPORT_CHAIN =  "marina.marina_report";
24         
25     private static final String OLC_PATH_EVEN = 
26         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@1"; // bits 2,4,6
27     private static final String OLC_PATH_ODD = 
28         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@2"; // bits 1,3,5
29     private static final String ILC_PATH_ODD = 
30         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@0"; // bits 1,3,5,7
31     private static final String ILC_PATH_EVEN = 
32         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@1"; // bits 2,4,6,8
33     private static final String FLAGS_PATH = 
34         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.scanEx3h@0";
35
36     private static final String INSTR_RING_CONTROL_PATH = 
37         "southFif@1.tapPropS@1.tapStage@2";
38     private static final String TOK_FIFO_PATH =
39         "tokenFIF@1";
40     private static final String INSTRUCTION_COUNTER_PATH =
41         "southFif@1.tapPropS@1.instruct@0";
42     private static final String DATA_COUNTER_PATH =
43         "northFif@1.fillDrai@1.instruct@0";
44     private static final String TOK_PRED_PATH =
45         "outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx2h@0.scanCell@10";
46
47     private static final int COUNTER_LENGTH = 34;
48     private static final int INSTRUCTION_SEND_NDX = 1;
49     private static final int INSTRUCTION_RECIRCULATE_NDX = 0;
50
51     public static final int INSTRUCTION_LENGTH = 36;
52         
53     private static final int A_FLAG_NDX = 0;
54     private static final int B_FLAG_NDX = 1;
55         
56     public static final int SOUTH_RING_CAPACITY = 11;
57         
58     // ILC appears in scan chain as "count[1:6], zLo, i, dLo"
59     public class Ilc {
60         // value is bit reversed and complemented
61         private int value;
62         private Ilc() {
63             shiftReport(true, false);
64             BitVector odd  = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_ODD).bitReverse().not();
65             BitVector even = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_EVEN).bitReverse().not();
66             BitVector ret  = new BitVector(8, "olc");
67             for(int i=0; i<4; i++) {
68                 ret.set(i*2+1, odd.get(i));
69                 ret.set(i*2,   even.get(i));
70             }
71             value = (int)ret.toLong();
72         }
73         /** Get the inner loop counter done bit. */
74         public boolean getDone() {
75             return (value & 0x40) != 0;
76         }
77         /** Get the inner loop counter infinity bit */
78         public boolean getInfinity() {
79             return (value & 0x80) != 0;
80         }
81         /** Get the 6 bits of count of the inner loop counter */
82         public int getCount() {
83             return value & 0x3f;
84         }
85         public String toString() {
86             return "[ilc, count="+getCount()+", infinity="+getInfinity()+", done="+getDone()+"]";
87         }
88     }
89         
90     private final Indenter indenter;
91
92     // The name of the scan chain
93     // The instance path, from the top cell of the netlist, of the instance of infinityWithCover 
94     private final ChainControls cc;           // specifies the scan chain
95     private final ChipModel model;
96     public final ProperStopper data;
97     public final InstructionStopper instrIn;
98     
99     private void prln(String msg) {indenter.prln(msg);}
100     private void pr(String msg) {indenter.pr(msg);}
101     
102     /** Shift the report scan chain */
103     private void shiftReport(boolean readEnable, boolean writeEnable) {
104         cc.shift(REPORT_CHAIN, readEnable, writeEnable);
105     }
106     
107     /** Shift the report scan chain */
108     private void shiftControl(boolean readEnable, boolean writeEnable) {
109         cc.shift(CONTROL_CHAIN, readEnable, writeEnable);
110     }
111         
112     /** Shift the data scan chain */
113     private void shiftData(boolean readEnable, boolean writeEnable) {
114         cc.shift(DATA_CHAIN, readEnable, writeEnable);
115     }
116
117     public Marina(ChainControls cc, ChipModel model, boolean clockHack, Indenter indenter) {
118         this.cc = cc;
119         this.model = model;
120         this.indenter = indenter;
121         data = new ProperStopper("north fifo",
122                                  "northFif@1.fillDrai@1.properSt@1",
123                                  CONTROL_CHAIN, 
124                                  DATA_CHAIN,  
125                                  REPORT_CHAIN,
126                                  cc, model, clockHack, indenter);
127         instrIn = new InstructionStopper("south fifo",
128                                          "southFif@1.tapPropS@1.properSt@1", 
129                                          CONTROL_CHAIN,
130                                          DATA_CHAIN,
131                                          REPORT_CHAIN,
132                                          cc, model, clockHack, indenter);
133     }
134     public void masterClear() {
135         final double WIDTH = 10; // ns
136         // Put a high going pulse on the internal chip master clear signal
137         if (model instanceof VerilogModel) {
138
139             data.clear();
140             instrIn.clear();
141
142             VerilogModel vm = (VerilogModel)model;
143             //
144             // In real life the flags come up with some undefined
145             // value.  In verilog we need to prevent the X'es from
146             // propagating, so we force the flags to a known value
147             //
148             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_", 0);
149             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_", 1);
150             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_", 0);
151             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_", 1);
152             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_", 0);
153             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_", 1);
154             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50", 0);       // A
155             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50", 0);       // B
156             vm.setNodeState("outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_", 0); // C
157
158             // possible C-flag inputs
159             vm.setNodeState("northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]", 0);
160             vm.setNodeState("northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]", 0);
161
162             // force the OLC to zero
163             for(int i=1; i<=6; i++)
164                 vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]", (i==1)?0:1);
165
166             // set the ILC input to 1
167             for(int i=1; i<=8; i++) {
168                 if (i!=7)
169                     vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"]", (i==1)?0:1);
170             }
171
172             vm.setNodeState("northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 1);
173             model.waitNS(1000);
174             vm.setNodeState("northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 0);
175             model.waitNS(1000);
176
177             vm.setNodeState("sid[9]", 1);
178             vm.setNodeState("sic[9]", 1);
179             vm.setNodeState("sir[9]", 1);
180             model.waitNS(1000);
181             vm.setNodeState("sid[9]", 0);
182             vm.setNodeState("sic[9]", 0);
183             vm.setNodeState("sir[9]", 0);
184             model.waitNS(1000);
185
186             // pulse ilc[load] and olc[load]
187             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_", 1);
188             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_", 1);
189             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_", 1);
190             vm.setNodeState("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_", 1);
191             model.waitNS(100);
192             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_");
193             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_");
194             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_");
195             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_");
196
197             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_");
198             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_");
199             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_");
200             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_");
201             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_");
202             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_");
203             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50");
204             vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50");
205
206             // Every move instruction, even those with Ti=0,Di=0,
207             // loads the C-flag.  It will get loaded with an "X",
208             // which will then leak into the flags and from there the
209             // predicate.
210             vm.releaseNode("outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_");
211             vm.releaseNode("northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]");
212             vm.releaseNode("northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]");
213             vm.releaseNode("northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire");
214
215             for(int i=1; i<=8; i++) {
216                 if (i!=7)
217                     vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"] ");
218             }
219             model.waitNS(1000);
220             for(int i=1; i<=6; i++)
221                 vm.releaseNode("outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]");
222
223             // the proper stopper states come up in an undefined ("X")
224             // state, so under Verilog we need to force them to a
225             // known state
226
227             data.idle();
228             instrIn.idle();
229
230         } else {
231             NanosimModel nModel = (NanosimModel) model;
232             nModel.setNodeVoltage("sid[9]",1.0);
233             nModel.setNodeVoltage("sic[9]",1.0);
234             nModel.setNodeVoltage("sir[9]",1.0);
235             nModel.waitNS(WIDTH);
236             nModel.setNodeVoltage("sid[9]",0.0);
237             nModel.setNodeVoltage("sic[9]",0.0);
238             nModel.setNodeVoltage("sir[9]",0.0);
239             nModel.waitNS(1);
240         }
241         resetAfterMasterClear();
242     }
243     private void resetAfterMasterClear() {
244         // The following call to ChainControl.resetInBits() is vital!
245         // If you forget, then the inBits member initializes 
246         // with random data. Then when you do your first write,
247         // some bits are written randomly.
248         cc.resetInBits();
249
250         // For reset, I want to clear all the stoppers simultaneously
251         data.clear();
252         //tokOut.clear();
253         instrIn.clear();
254         
255         data.stop();
256         //tokOut.stop();
257         instrIn.stop();
258         
259         data.resetAfterMasterClear();
260         //tokOut.resetAfterMasterClear();
261         instrIn.resetAfterMasterClear();
262     }
263     /** Get the 6 bit outer loop counter. */
264     public int getOLC() {
265         shiftReport(true, false);
266         BitVector odd = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_ODD).bitReverse().not();
267         BitVector even = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_EVEN).bitReverse().not();
268         BitVector ret = new BitVector(6, "olc");
269         for(int i=0; i<3; i++) {
270             ret.set(i*2,   odd.get(i));
271             ret.set(i*2+1, even.get(i));
272         }
273         return (int)ret.toLong();
274     }
275     /** Get the 7 bit inner loop counter. The MSB is the zero bit.
276      * The low order 6 bits are the count */
277     public Ilc getILC() {
278         return new Ilc();
279     }
280     /** Get the A flag */
281     public boolean getFlagA() {
282         shiftReport(true, false);
283         return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(A_FLAG_NDX);
284     }
285     /** Get the B flag */
286     public boolean getFlagB() {
287         shiftReport(true, false);
288         return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(B_FLAG_NDX);
289     }
290     /** return value of instruction counter. Instruction counter counts 
291      * the instructions flowing through 1/2 of alternating FIFO.
292      * Caution: instruction counter is written by all scans, 
293      * regardless of readEnable or writeEnable! */
294     public long getInstructionCounter() {
295         shiftData(true, false);
296         BitVector count = cc.getOutBits(DATA_CHAIN+"."+INSTRUCTION_COUNTER_PATH);
297         int sz = count.getNumBits(); 
298         MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
299                          " expected: "+COUNTER_LENGTH);
300         return count.bitReverse().toLong();
301     }
302     /** return value of data counter. Data counter counts items flowing
303      * through drain stage of data proper stopper. 
304      * Caution: data counter is written by all scans, 
305      * regardless of readEnable or writeEnable! */
306     public long getDataCounter() {
307         shiftData(true, false);
308         BitVector count = cc.getOutBits(DATA_CHAIN+"."+DATA_COUNTER_PATH);
309         int sz = count.getNumBits(); 
310         MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
311                          " expected: "+COUNTER_LENGTH);
312         return count.bitReverse().toLong();
313     }
314     /** Fill the "North" Fifo ring */
315     public void fillNorthProperStopper() {
316         BitVector data = new BitVector(37, "empty");
317         BitVector addr = new BitVector(14, "empty");
318         for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
319         for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
320         fillNorthProperStopper(new MarinaPacket(data, false, addr));
321     }
322     /** Fill the "North" Fifo ring */
323     public void fillNorthProperStopper(MarinaPacket mp) {
324         this.data.fill(mp.toSingleBitVector());
325     }
326     /** Enable the transmission of instructions from the instruction
327      * ring test structure to the EPI FIFO. */
328     public void enableInstructionSend(boolean b) {
329         BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
330         bv.set(INSTRUCTION_SEND_NDX, b);
331         cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
332         shiftControl(false, true);
333     } 
334     /** Enable the recirculation of instructions within the South FIFO */
335     public void enableInstructionRecirculate(boolean b) {
336         BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
337         bv.set(INSTRUCTION_RECIRCULATE_NDX, b);
338         cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv); 
339         shiftControl(false, true);
340     }
341     /** get the number of tokens in the token FIFO.
342      * This includes the Token successor wire, the token FIFO wires,
343      * and Token predecessor wire.
344      * Master clear clears the token FIFO. */
345     public int getNumTokens() {
346         shiftReport(true, false);
347         // get the token successor and token FIFO wires
348         BitVector bv = cc.getOutBits(REPORT_CHAIN+"."+TOK_FIFO_PATH);
349         int sz = bv.getNumBits();
350         MarinaTest.fatal(sz!=3, "wrong token FIFO size: "+sz+" expected: 3");
351         
352         // get the token predecessor wire
353         BitVector pred = cc.getOutBits(REPORT_CHAIN+"."+TOK_PRED_PATH);
354         sz = pred.getNumBits();
355         MarinaTest.fatal(sz!=1, "wrong token predecessor size: "+sz+" expected: 1");
356
357         // concatenate them
358         bv = bv.cat(pred);
359         sz = bv.getNumBits();
360         prln("Token state wires: "+bv.getState());
361         
362         int nbTok = 0;
363         for (int i=0; i<sz; i++) if (bv.get(i)) nbTok++;
364         return nbTok;
365     }
366     /** Configure the test probe so it measures the throughput of
367      * the north data FIFO. The test probe frequency is 8192 
368      * times slower than the FIFO throughput. This control has
369      * highest priority. */
370     public void probeDataCounter(Boolean b) {
371         data.setGeneralPurposeOutput(b);
372     }
373     /** Configure the test probe so it measures the throughput of
374      * the alternating instruction FIFO. The test probe frequency is
375      * 1/16384 of the FIFO throughput. This control has second
376      * highest priority. Thus the following two calls probe the
377      * instruction counter: 
378      *      probeDataCounter(false);
379      *      probeInstructionCounter(true)
380      */
381     public void enableInstructionCounter(Boolean b) {
382         instrIn.setGeneralPurposeOutput(b);
383     }
384
385     public void fillSouthProperStopper(Instruction[] instructions) { fillSouthProperStopper(instructions, false); }
386     public void fillSouthProperStopper(Instruction[] instructions, boolean repeat) {
387         enableInstructionSend(false);
388         enableInstructionRecirculate(true);
389         for(Instruction i : instructions)
390             instrIn.fill(i);
391         enableInstructionRecirculate(repeat);
392         enableInstructionSend(true);
393         instrIn.run();
394     }
395
396     
397 }