| JHDL Doc Home Page | User's
Manual Home Page |
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/qAlso, beware of this common 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?
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
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.Keep these rules in mind when coding up your behavioral models -- each output wire to your cell should be put() exactly once in each and every execution of your clock() or propagate() methods. This requires particular attention if you have any branching statements in your model -- for example, this model of an enabled flip-flop will produce annoying "wire undriven" messages whenever clock-enable is not asserted:
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-2003 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.
Documentation Revision: 19 Mar, 2001