JHDL 0.2
| JHDL Doc Home Page | User's Manual Home Page | << | < | > | >>
Each time we access a wire value the simulator checks to see if we are "authorized" to do so, i.e. if the cell is a valid sink or source. This is an important check in making sure that the circuit structure is correct (and therefore netlistable). A wire is a valid sink if it was passed through any port of the cell that is calling get(). A wire is a valid source if it was passed through an out-port of the cell that is calling put(). Also, if a cell constructs a new wire and passes itself as the parent of that wire, it can do both get()s and put()s on that wire. The critical point to remember is that there are two general methods to get your wires to have the proper scope:
Wire myPortWire, myConstructedWire;
/* The constructor */
public MyCell(Node parent, Wire t1) {
super(this);
myPortWire = connect("someport", t1);
myConstructedWire = wire(5);
}
public void clock() {
myPortWire.get(this, 2);
myConstructedWire.get(this);
myConstructedWire.put(this, 15);
}
This clock() method is correct -- myPortWire has correct
scope in this cell because it is the return value of a
connect() call. myConstructedWire has correct scope
because it was constructed in this cell.
Now for the incorrect example:
Wire myPortWire, myConstructedWire1, myConstructedWire2;
/* The constructor */
public MyCell(Node parent, Wire t1) {
super(this);
connect("someport", t1);
myPortWire = t1;
myConstructedWire1 = Logic.wire(parent, 5);
myConstructedWire2 = myConstructedWire1.getWire(2);
}
public void clock() {
myPortWire.get(this, 2);
myConstructedWire1.get(this);
myConstructedWire2.put(this, 15);
}
This clock() method will die a hard death. myPortWire
is still pointing to the "t1" parameter, but did not get the return
value of the corresponding connect() call. Therefore it has
incorrect scope.
myConstructedWire1 fails because it was constructed with a
different cell (parent) as its parent.
myConstructedWire2 fails because it was constructed with no
parent. A correct alternative for this case would be to construct it as
follows:
myConstructedWire2 = myConstructedWire1.range(this, 2, 2)The JHDL simulator will report these errors with a message like this:
byucc.jhdl.base.PutGetException: Illegal put by Cell: tb_MyCell-0/MyCell-0 on Wire: tb_MyCell-0/q
Also, beware of this commmon error, which is a Java-scope problem:
Wire sum;
public MyCell(Node parent, Wire sum) {
super(parent);
sum = connect("sum", sum);
}
public void clock() {
sum.put(this, 1);
}
Do you see the problem? Why will this cause a null-pointer exception?
Wire get()s and put()s come in three flavors, depending on the width of the wire:
public void clock() {
int[] a = { 0x77778888, 0x55556666, 0x33334444, 0x11112222 };
myWire.putA(this, a);
}
To summarize: you can call getA() on a 32-bit wire, but you
cannot call get() on a 128-bit wire. If you make a call that
isn't wide enough for the wire, you will get an error message like
this:
byucc.jhdl.base.WireSizeException: Cell: tb_MyCell-0/MyCell-0 is put()ing a value not wide enough for wire: tb_MyCell-0/MyCell-0/Xwire-0. Input width: 32 bits, wire width: 128
Simply put, you cannot call put() on a wire that is connected to an in-port. If a wire is connected to an out-port, or if the wire was constructed in this cell, you can call both put() and get() on that wire.
The simulator counts the number of get()s and put()s on each wire in each simulation cycle. This helps it detect multiple drivers on a wire, dangling wires, etc. for reporting purposes. You should be aware of two basic rules:
ERROR! Wire: tb_MyCell-0/q[0] was floating during clock cycle: 0.
ERROR! Wire: tb_MyCell-0/q[0] had multiple sources during clock cycle: 0.
public void clock() {
if (ce.get(this) == 1)
q.put(this, d.get(this);
}
Therefore a better model (for the sanity of those who use your
flip-flop and don't like the messages) would be:
public void clock() {
if (ce.get(this) == 1)
q.put(this, d.get(this));
else
q.put(this, q.get(this));
}
| JHDL Doc Home Page | User's Manual Home Page | << | < | > | >>
Copyright (c) 1998-1999 Brigham Young University. All
rights reserved.
Reproduction in whole or in part in any form or
medium without express permission of Brigham Young University is
prohibited.