JHDL 0.3.39

| JHDL Doc Home Page | User's Manual Home Page |


JHDL Cells, Wires, and Other General Concepts


Hierarchical Design in JHDL

As was shown in the Getting Started section, hierarchical design is straightforward in JHDL.  The FullAdder design used built-in logic gates to build a full adder circuit.  The NBitAdder design then instanced as many of those as it needed to create an n-bit adder.  At each level of hierarchy there are both port wires and local wires.  Port wires are those connected to the ports of the module (they are passed into the constructor call as parameters and connect() calls hook them up to the ports on the cell's interface).  Local wires are those created internal to a cell.  These can then be passed as parameters into the constructors for lower-level cells.

Cell Interface Declarations

Ports in JHDL can be of three types: in, out, and inout.  The use of inout ports is an advanced topic and is documented in the Advanced Topics section of the User's Manual.

The  NBitAdder.java example shows the use of generic-width ports.  Important points include:

  1. The generic port width expression must be enclosed in double quotes.
  2. The generic port width express can be an arbitrary, parenthesized arithmetic expression involving any declared PARAM's, integer constants, and the usual arithmetic operators (-, +, ...).
  3. The PARAM must also be declared.  INTEGER is the only currently supported type.

Cell Constructors

The cell constructor is the constructor (subroutine) called to create an instance of a cell.  It is an arbitrary Java constructor and can take parameters of any type.  Thus, here is the first line of a complex constructor:
  public multiplier(Node parent, boolean signed, String style, Wire a, Wire b, Wire q) {
In addition to the wires, this constructor also takes a boolean and a String to indicate the kind of constructor desired.  Since the constructor code is regular Java, it can do anything it sees fit with these parameters.  The only requirement is that it call its super constructor before it does anything else and that it connect() the wires passed in to the cell's ports from the CellInterface.

The Super Constructor

If a circuit class extends any other class , it must call that class's super constructor as the first thing it does (passing the parent parameter it received on):
  super(parent);
In addition, if it desires to specify a String instance name, the following variation is allowed:
  super(parent, instanceName);

Bind and Connect Calls

Any generic parameters must be bound prior to connect() calls being made.  Thus, a typical constructor might look like this:
 
  public myCell(Node parent, 
     Wire a,
     Wire b,
     Wire q,
     String instanceName) {
    super(parent, instanceName);
    bind("WIDTH", q.getWidth());
    connect("a", a);
    connect("b", b);
    connect("q", q);

The Constructor Body

Once the above has been completed, the circuit logic is built by calling constructors for wires and other cells.  Any Java language constructs desired can be used to aid in this process.

Constructors and TBone

Do we have to say anything special here about TBone and the structure of constructors for it to all work?  We will document defining parameters in the TBone section.

Creating Wires

One of the most common errors in writing JHDL is with the creation of wires.  Remember - a wire is an object.  It must be created before it is used.  In the n-bit adder example from Getting Started, the carry wires were locally created while the a, b, and sum wires were passed in from the outside of the cell (and presumably created out there).  Merely declaring a wire like this:
    Wire w;
doesn't actually create the wire object - it just creates a Java variable suitable for referencing a wire.  If you want a actually the create the wire you must do this:
    Wire w = wire(1);
to get a 1-bit wide wire object.  Further, this will create a 4-bit named wire:
    Wire w = wire(4, "abc");
When a wire is created this way, the name provided will be the one used throughout the JHDL design.  If no wire name is provided, the system will automatically create one that it will use.

Slicing and dicing wires

A crucial part of structural design is splitting and merging busses. The Wire class has two primary methods for splitting busses: getWire() returns a single bit of the wire, and range() returns a range of bits from the bus. The wire accessor methods have the following prototypes: Also note that the abbreviation gw() exists which exactly mirrors the prototypes and function of the getWire() methods. Another useful shortcut is the getWidth() method which returns the width of the wire.

To merge wires together into a bus, you can use the concat() method of the Logic class. This method takes a list of 2 to 16 input wires, each of arbitrary width, and concatenates them into a single bus. The first parameter occupies the most significant position in the bus, and the last parameter occupies the least significant position. All of the wire slicing and dicing methods are exemplified below:

   Wire a = wire(8), b = wire(8), c = wire(8), d = wire(8);
   Wire t;

   t = a.getWire(3);     // t = a[3]
   t = b.gw(5);          // t = b[5]
   t = c.range(6, 4);    // t = c[6:4]

   t = concat(a, b, c);  // t = { a[7:0]; b[7:0]; c[7:0] }
                         // t.getWire(23) = a[7]
                         // t.getWire(0)  = c[0]

   t = concat(a.range(5,3), b.getWire(6), c.range(2, 2));
                         // t = { a[5:3]; b[6]; c[2] }

   int i = t.getWidth(); // i = 5
While the concat method is a member of the Logic class, you can still perform concatenation outside of the Logic class using the static versions of the methods. These version require you to pass in a Node as the parent of the new wire:
   Wire myBus = Logic.concat(this, wire1, wire2, wire3);

| 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: $Date: 2003/04/24 14:15:11 $