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 edu.berkeley.fleet.api.Dock;
9 import edu.berkeley.fleet.api.Instruction;
10 import edu.berkeley.fleet.marina.MarinaFleet;
13 * This class encapsulates a "packet" -- a data item in flight plus
14 * its tokenhood and path.
16 * This should be the only class that knows how to turn a packet into
17 * its constituent parts and vice versa.
19 public class MarinaPacket {
21 public static final int PATH_WIDTH = 14;
22 public static final int WORD_WIDTH = 37;
23 public static final int PACKET_WIDTH = PATH_WIDTH+WORD_WIDTH+1;
25 public final BitVector data;
26 public final boolean tokenhood;
27 public final BitVector path;
28 private final boolean is_instruction;
30 public static final BitVector null_path = new BitVector(PATH_WIDTH, "null_path");
31 public static final BitVector null_word = new BitVector(WORD_WIDTH, "null_word");
33 null_path.set(0, PATH_WIDTH, false);
34 null_word.set(0, WORD_WIDTH, false);
37 /** "parse" a token from the raw bits in the north proper stopper */
38 public MarinaPacket(BitVector singleBitVector) {
39 MarinaUtils.expectLength(singleBitVector,PACKET_WIDTH);
40 this.data = new BitVector(WORD_WIDTH, "marina packet data");
41 this.path = new BitVector(PATH_WIDTH, "marina packet path");
42 this.tokenhood = !singleBitVector.get(0);
43 this.is_instruction = false;
44 for(int i=0; i<PATH_WIDTH; i++) path.set(i, singleBitVector.get(i+1));
45 for(int i=0; i<WORD_WIDTH; i++) data.set(i, singleBitVector.get(i+PATH_WIDTH+1));
48 /** manually assemble a packet */
49 public MarinaPacket(BitVector data, boolean tokenhood, BitVector path) {
50 MarinaUtils.expectLength(data, WORD_WIDTH);
51 MarinaUtils.expectLength(path, PATH_WIDTH);
53 this.tokenhood = tokenhood;
55 this.is_instruction = false;
58 /** another constructor which uses an all-zeroes path, for convenience */
59 public MarinaPacket(Instruction inst) {
61 MarinaUtils.berkToSun(MarinaTest.marinaFleet.encodeInstruction(MarinaTest.marinaFleet.getOnlyInputDock(), inst));
62 MarinaUtils.expectLength(instr, MarinaPacket.WORD_WIDTH);
65 // Due to what Ivan calls "geometric inconvenience", incoming
66 // bit 19 is dropped, and all the higher bits are shifted
67 // downward by one position. So we have to compensate for
68 // this by inserting a bogus bit at position #19.
70 BitVector pad = new BitVector(1, "pad");
72 this.data = instr.get(0, 18).cat(pad).cat(instr.get(18,18));
73 this.path = null_path;
74 this.tokenhood = false;
75 this.is_instruction = true;
78 /** convert a packet into a single BitVector, suitable for insertion in the north proper stopper */
79 public BitVector toSingleBitVector() {
80 BitVector bv = new BitVector(PACKET_WIDTH, "marina packet");
81 bv.set(0, !tokenhood);
82 for(int i=0; i<PATH_WIDTH; i++) bv.set(i+1, path.get(i));
83 for(int i=0; i<WORD_WIDTH; i++) bv.set(i+PATH_WIDTH+1, data.get(i));
87 public String toString() {
89 "tokenhood="+(tokenhood ? "token" : "data")
90 + ", path["+PATH_WIDTH+":1]=" + path.bitReverse().getState()
91 + ", data["+WORD_WIDTH+":1]=" +
93 ? (data.get(19,18).bitReverse().getState()+"_"+data.get(0,18).bitReverse().getState())
94 : data.bitReverse().getState());