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;
10 import edu.berkeley.fleet.api.Instruction;
11 import edu.berkeley.fleet.marina.MarinaPath;
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. */
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;
22 public static int TOKEN_FIFO_CAPACITY = 3;
24 public static boolean kesselsCounter = true;
25 //public static boolean kesselsCounter = false;
27 public static final String DATA_CHAIN = kesselsCounter ? "marina.marina_data" : "marina.ivan_data";
28 public static final String CONTROL_CHAIN = kesselsCounter ? "marina.marina_control" : "marina.ivan_control";
29 public static final String REPORT_CHAIN = kesselsCounter ? "marina.marina_report" : "marina.ivan_report";
31 public static String prefix = "marinaGu@0.outDockW@"+(kesselsCounter?"3":"0")+".marinaOu@"+(kesselsCounter?"1":"0")+".";
32 public static String MASTER_CLEAR = "mc";
36 private static String prefix = "outDockW@"+(kesselsCounter?"3":"0")+".marinaOu@1.";
37 private static String MASTER_CLEAR = "EXTmasterClear";
40 private static final String OLC_PATH_EVEN =
41 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@1"; // bits 2,4,6
42 private static final String OLC_PATH_ODD =
43 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.scanEx3h@2"; // bits 1,3,5
44 private static final String OLC_PATH_KESSEL =
45 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.counte@0.adamScan@1.scanEx6h@";
46 private static final String ILC_PATH_ODD =
47 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@0"; // bits 1,3,5,7
48 private static final String ILC_PATH_EVEN =
49 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx4h@1"; // bits 2,4,6,8
50 private static final String FLAGS_PATH =
51 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.scanEx3h@0";
53 private static final String INSTR_RING_CONTROL_PATH =
54 prefix+"southFif@1.tapPropS@1.tapStage@2";
55 private static final String TOK_FIFO_PATH =
57 private static final String INSTRUCTION_COUNTER_PATH =
58 prefix+"southFif@1.tapPropS@1.instruct@0";
59 private static final String DATA_COUNTER_PATH =
60 prefix+"northFif@1.fillDrai@1.instruct@0";
61 private static final String TOK_PRED_PATH =
62 prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.scanEx2h@0.scanCell@10";
64 private static final int COUNTER_LENGTH = 34;
65 private static final int INSTRUCTION_SEND_NDX = 1;
66 private static final int INSTRUCTION_RECIRCULATE_NDX = 0;
68 public static final int INSTRUCTION_LENGTH = 36;
70 private static final int A_FLAG_NDX = 0;
71 private static final int B_FLAG_NDX = 1;
73 public static final int SOUTH_RING_CAPACITY = 11;
75 // ILC appears in scan chain as "count[1:6], zLo, i, dLo"
77 // value is bit reversed and complemented
80 shiftReport(true, false);
81 BitVector odd = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_ODD).bitReverse().not();
82 BitVector even = cc.getOutBits(REPORT_CHAIN+"."+ILC_PATH_EVEN).bitReverse().not();
83 BitVector ret = new BitVector(8, "olc");
84 for(int i=0; i<4; i++) {
85 ret.set(i*2+1, odd.get(i));
86 ret.set(i*2, even.get(i));
88 value = (int)ret.toLong();
90 /** Get the inner loop counter done bit. */
91 public boolean getDone() {
92 return (value & 0x40) != 0;
94 /** Get the inner loop counter infinity bit */
95 public boolean getInfinity() {
96 return (value & 0x80) != 0;
98 /** Get the 6 bits of count of the inner loop counter */
99 public int getCount() {
102 public String toString() {
103 return "[ilc, count="+getCount()+", infinity="+getInfinity()+", done="+getDone()+"]";
107 private final Indenter indenter;
109 // The name of the scan chain
110 // The instance path, from the top cell of the netlist, of the instance of infinityWithCover
111 private final ChainControls cc; // specifies the scan chain
112 private final ChipModel model;
113 public final ProperStopper data;
114 public final InstructionStopper instrIn;
116 private void prln(String msg) {indenter.prln(msg);}
117 private void pr(String msg) {indenter.pr(msg);}
119 /** Shift the report scan chain */
120 private void shiftReport(boolean readEnable, boolean writeEnable) {
121 cc.shift(REPORT_CHAIN, readEnable, writeEnable);
124 /** Shift the report scan chain */
125 private void shiftControl(boolean readEnable, boolean writeEnable) {
126 cc.shift(CONTROL_CHAIN, readEnable, writeEnable);
129 /** Shift the data scan chain */
130 private void shiftData(boolean readEnable, boolean writeEnable) {
131 cc.shift(DATA_CHAIN, readEnable, writeEnable);
134 public Marina(ChainControls cc, ChipModel model, boolean clockHack, Indenter indenter) {
137 this.indenter = indenter;
138 data = new ProperStopper("north fifo",
139 prefix+"northFif@1.fillDrai@1.properSt@1",
143 cc, model, clockHack, indenter);
144 instrIn = new InstructionStopper("south fifo",
145 prefix+"southFif@1.tapPropS@1.properSt@1",
149 cc, model, clockHack, indenter);
151 public void masterClear() {
152 final double WIDTH = 10; // ns
153 // Put a high going pulse on the internal chip master clear signal
154 if (model instanceof VerilogModel) {
159 VerilogModel vm = (VerilogModel)model;
161 // In real life the flags come up with some undefined
162 // value. In verilog we need to prevent the X'es from
163 // propagating, so we force the flags to a known value
165 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_", 0);
166 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_", 1);
167 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_", 0);
168 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_", 1);
170 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_", 1);
171 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_", 0);
173 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50", 0); // A
174 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50", 0); // B
175 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_", 0); // C
177 // possible C-flag inputs
178 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]", 0);
179 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]", 0);
181 // force the OLC to zero
183 for(int i=1; i<=6; i++)
184 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]", (i==1)?0:1);
186 // set the ILC input to 1
187 for(int i=1; i<=8; i++) {
189 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"]", (i==1)?0:1);
192 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 1);
194 vm.setNodeState(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire", 0);
197 vm.setNodeState(MASTER_CLEAR, 1);
199 vm.setNodeState(MASTER_CLEAR, 0);
202 // pulse ilc[load] and olc[load]
203 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_", 1);
204 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_", 1);
205 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_", 1);
207 vm.setNodeState(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_", 1);
210 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_load_");
211 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_decLO_");
212 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.ilc_torpLO_");
214 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.olc_load_");
216 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__set_");
217 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_A__clr_");
218 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__set_");
219 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_B__clr_");
221 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__set_");
222 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flag_D__clr_");
224 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@0.net_50");
225 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.flags@0.aFlag@1.net_50");
227 // Every move instruction, even those with Ti=0,Di=0,
228 // loads the C-flag. It will get loaded with an "X",
229 // which will then leak into the flags and from there the
231 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.litDandP@0.latch2in@0.hi2inLat@0.latchKee@0.out_B_");
232 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ONE+1)+"]");
233 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.ain["+(INDEX_OF_ADDRESS_BIT_COPIED_TO_C_FLAG_WHEN_DC_EQUALS_ZERO+1)+"]");
234 vm.releaseNode(prefix+"northFif@1.upDown8w@2.weakStag@22.addr1in2@0.fire");
236 for(int i=1; i<=8; i++) {
238 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.ilcMoveO@0.ilc@0.\\inLO["+i+"] ");
243 for(int i=1; i<=6; i++)
244 vm.releaseNode(prefix+"outputDo@0.outM1Pre@0.outDockP@0.outDockC@0.olcWcont@0.olc@0.inLO["+i+"]");
246 // the proper stopper states come up in an undefined ("X")
247 // state, so under Verilog we need to force them to a
254 NanosimModel nModel = (NanosimModel) model;
256 nModel.setNodeVoltage(prefix+"sid[9]",1.0);
257 nModel.setNodeVoltage(prefix+"sic[9]",1.0);
258 nModel.setNodeVoltage(prefix+"sir[9]",1.0);
259 nModel.waitNS(WIDTH);
260 nModel.setNodeVoltage(prefix+"sid[9]",0.0);
261 nModel.setNodeVoltage(prefix+"sic[9]",0.0);
262 nModel.setNodeVoltage(prefix+"sir[9]",0.0);
265 nModel.setNodeVoltage(MASTER_CLEAR,1.0);
266 nModel.waitNS(WIDTH);
267 nModel.setNodeVoltage(MASTER_CLEAR,0.0);
270 resetAfterMasterClear();
272 private void resetAfterMasterClear() {
273 // The following call to ChainControl.resetInBits() is vital!
274 // If you forget, then the inBits member initializes
275 // with random data. Then when you do your first write,
276 // some bits are written randomly.
279 // For reset, I want to clear all the stoppers simultaneously
288 data.resetAfterMasterClear();
289 //tokOut.resetAfterMasterClear();
290 instrIn.resetAfterMasterClear();
294 /** Get the 6 bit outer loop counter. */
295 public int getOLC() {
296 shiftReport(true, false);
297 if (kesselsCounter) {
298 BitVector bits = null;
299 for(int i=0; i<4; i++) {
300 BitVector x = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_KESSEL+i);
301 //System.out.println("bits are: " + x);
302 bits = bits==null ? x : bits.cat(x);
304 //System.out.println("kesselsCounter = " + bits);
307 for(int i=0; i<6; i++) first |= bits.get(4+i*3) ? (1<<i) : 0;
308 for(int i=0; i<6; i++) second |= bits.get(4+i*3+2) ? (1<<i) : 0;
309 return (first+second);
311 BitVector odd = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_ODD).bitReverse();
312 BitVector even = cc.getOutBits(REPORT_CHAIN+"."+OLC_PATH_EVEN).bitReverse();
315 BitVector bv = new BitVector(6, "olc");
316 for(int i=0; i<3; i++) {
317 bv.set(i*2, odd.get(i));
318 bv.set(i*2+1, even.get(i));
320 return (int)bv.toLong();
323 /** Get the 7 bit inner loop counter. The MSB is the zero bit.
324 * The low order 6 bits are the count */
325 public Ilc getILC() {
328 /** Get the A flag */
329 public boolean getFlagA() {
330 shiftReport(true, false);
331 return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(A_FLAG_NDX);
333 /** Get the B flag */
334 public boolean getFlagB() {
335 shiftReport(true, false);
336 return cc.getOutBits(REPORT_CHAIN+"."+FLAGS_PATH).get(B_FLAG_NDX);
338 /** return value of instruction counter. Instruction counter counts
339 * the instructions flowing through 1/2 of alternating FIFO.
340 * Caution: instruction counter is written by all scans,
341 * regardless of readEnable or writeEnable! */
342 public long getInstructionCounter() {
343 shiftData(true, false);
344 BitVector count = cc.getOutBits(DATA_CHAIN+"."+INSTRUCTION_COUNTER_PATH);
345 int sz = count.getNumBits();
346 MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
347 " expected: "+COUNTER_LENGTH);
348 return count.bitReverse().toLong();
350 /** return value of data counter. Data counter counts items flowing
351 * through drain stage of data proper stopper.
352 * Caution: data counter is written by all scans,
353 * regardless of readEnable or writeEnable! */
354 public long getDataCounter() {
355 shiftData(true, false);
356 BitVector count = cc.getOutBits(DATA_CHAIN+"."+DATA_COUNTER_PATH);
357 int sz = count.getNumBits();
358 MarinaTest.fatal(sz!=COUNTER_LENGTH, "wrong number of counter bits: "+sz+
359 " expected: "+COUNTER_LENGTH);
360 return count.bitReverse().toLong();
362 /** Fill the "North" Fifo ring */
363 public void fillNorthProperStopper() {
364 BitVector data = new BitVector(37, "empty");
365 BitVector addr = new BitVector(14, "empty");
366 for(int i=0; i<data.getNumBits(); i++) data.set(i, false);
367 for(int i=0; i<addr.getNumBits(); i++) addr.set(i, false);
368 fillNorthProperStopper(new MarinaPacket(data, false, addr));
370 /** Fill the "North" Fifo ring */
371 public void fillNorthProperStopper(MarinaPacket mp) {
372 prln("inserting into north: " + mp);
373 this.data.fill(mp.toSingleBitVector());
375 /** Enable the transmission of instructions from the instruction
376 * ring test structure to the EPI FIFO. */
377 public void enableInstructionSend(boolean b) {
378 BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
379 bv.set(INSTRUCTION_SEND_NDX, b);
380 cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv);
381 shiftControl(false, true);
383 /** Enable the recirculation of instructions within the South FIFO */
384 public void enableInstructionRecirculate(boolean b) {
385 BitVector bv = cc.getInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH);
386 bv.set(INSTRUCTION_RECIRCULATE_NDX, b);
387 cc.setInBits(CONTROL_CHAIN+"."+INSTR_RING_CONTROL_PATH, bv);
388 shiftControl(false, true);
390 /** get the number of tokens in the token FIFO.
391 * This includes the Token successor wire, the token FIFO wires,
392 * and Token predecessor wire.
393 * Master clear clears the token FIFO. */
394 public int getNumTokens() {
395 shiftReport(true, false);
396 // get the token successor and token FIFO wires
397 BitVector bv = cc.getOutBits(REPORT_CHAIN+"."+TOK_FIFO_PATH);
398 int sz = bv.getNumBits();
399 MarinaTest.fatal(sz!=3, "wrong token FIFO size: "+sz+" expected: 3");
401 // get the token predecessor wire
402 BitVector pred = cc.getOutBits(REPORT_CHAIN+"."+TOK_PRED_PATH);
403 sz = pred.getNumBits();
404 MarinaTest.fatal(sz!=1, "wrong token predecessor size: "+sz+" expected: 1");
408 sz = bv.getNumBits();
409 prln("Token state wires: "+bv.getState());
412 for (int i=0; i<sz; i++) if (bv.get(i)) nbTok++;
415 /** Configure the test probe so it measures the throughput of
416 * the north data FIFO. The test probe frequency is 8192
417 * times slower than the FIFO throughput. This control has
418 * highest priority. */
419 public void probeDataCounter(Boolean b) {
420 data.setGeneralPurposeOutput(b);
422 /** Configure the test probe so it measures the throughput of
423 * the alternating instruction FIFO. The test probe frequency is
424 * 1/16384 of the FIFO throughput. This control has second
425 * highest priority. Thus the following two calls probe the
426 * instruction counter:
427 * probeDataCounter(false);
428 * probeInstructionCounter(true)
430 public void enableInstructionCounter(Boolean b) {
431 instrIn.setGeneralPurposeOutput(b);
434 public void fillSouthProperStopper(Instruction[] instructions) { fillSouthProperStopper(instructions, false); }
435 public void fillSouthProperStopper(Instruction[] instructions, boolean repeat) {
436 enableInstructionSend(false);
437 enableInstructionRecirculate(true);
438 for(Instruction i : instructions)
441 enableInstructionRecirculate(repeat);
442 enableInstructionSend(true);