6c5ea2d88078a514bf2fb6df1c30499ffe8458aa
[fleet.git] / src / edu / berkeley / fleet / marina / ChainControls.java
1 package edu.berkeley.fleet.marina;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import com.sun.electric.tool.simulation.test.*;
6
7 /** One or more ChainControl. If we have a JTAG controller then one
8  * ChainControl. If we don't have a JTAG controller then we need
9  * one ChainControl per scan chain.
10  * 
11  * ChainControls duplicates much of the ChainControl interface. It
12  * allows the testing code to remain oblivious of whether or not the
13  * JTAG controller exists. 
14  */
15 public class ChainControls {
16     private Map<String,ChainControl> chainToControl = 
17         new HashMap<String,ChainControl>();
18         
19     /** The path has the form:
20      *  chipName.chainName.instanceName1.instanceName2 ...
21      */
22     public ChainControl getChainControlFromPath(String path) {
23         for (String chainName : chainToControl.keySet()) {
24             if (path.startsWith(chainName)) return chainToControl.get(chainName);
25         }
26         MarinaTest.fatal(true, "Can't find chain for path: "+path);
27         return null;
28     }
29     public void addChain(String chain, ChainControl control) {
30         chainToControl.put(chain, control);
31     }
32         
33     //--------------------------------------------------------------------------------
34     // Replicate interface of ChainControl
35     public BitVector getInBits(String path) {
36         ChainControl cc = getChainControlFromPath(path);
37         return cc.getInBits(path);
38     }
39     public BitVector getOutBits(String path) {
40         ChainControl cc = getChainControlFromPath(path);
41         return cc.getOutBits(path);
42     }
43     public void setInBits(String path, BitVector bits) {
44         ChainControl cc = getChainControlFromPath(path);
45         cc.setInBits(path, bits);
46     }
47     public void shift(String chainName, boolean readEnable, boolean writeEnable) {
48         ChainControl cc = getChainControlFromPath(chainName);
49         cc.shift(chainName, readEnable, writeEnable);
50     }
51     public void resetInBits() {
52         for (String chainName : chainToControl.keySet()) {
53             ChainControl cc = chainToControl.get(chainName);
54             cc.resetInBits();
55         }
56     }
57 }