JHDL 0.3.39

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


Clocks, Pads, and Netlisting JHDL Designs

The tutorial presented earlier in the documentation illustrated the simplest use of JHDL: a single-clock design with only input and output pads. For this type of design, the default simulation and netlisting functionality is likely sufficient for your needs. In this section we outline the methods used to declare your own clocks and control the insertion of pads, buffers, clock DLL's, and drivers in an FPGA. This section will use Xilinx Virtex as an example.

 First, we discuss how to declare your own clocks for multi-clock design. Next, we tell you how to do your own pad insertion using Logic calls or direct instantiation. Finally, we outline what automated facilities JHDL has to help you in the insertion of pads.

Multi-Clock Design

When a user defines a clock of his own we say that the design is a "multi-clock design" (there is no reason to define a clock unless you intend on defining multiple clocks since the Default Global Clock in JHDL should suffice otherwise).

Consider the following multi-clock design:

import byucc.jhdl.base.*;
import byucc.jhdl.Logic.*;
import byucc.jhdl.Xilinx.Virtex.*;

public class flipflops extends Logic {

  public static CellInterface[] cell_interface = {
    in ("clkIn", 1), in ("clk2In", 1),
    in ("a", 1),
    out ("q", 1), out ("q2", 1),
  };

  public flipflops(Node parent, Wire clkIn, Wire clk2In,
                   wire a, Wire q, Wire q2) {
    super(parent);
    connect("clkIn", clkIn);    connect("clk2In", clk2In);
    connect("a", a);
    connect("q", q);            connect("q2", q2);


    Wire clk = clockDriver(clkIn, "0001", "clk");

    // Build this clockDriver with a DLL!
    String[] mods = {"DLL"};
    Wire clk2 = clockDriver(clk2In, "0101", "clk2", mods);


    // Build a flip flop clocked by "clk"

    setDefaultClock(clk);

    reg_o(a, q);

    // Build a flip flop clocked by "clk2" - explicitly specify clock

    reg_o(clk2, a, q2);

  }
}
The red text shows two clocks being defined and two registers being created - one is clocked by each clock. The 2nd parameter to the clockDriver() calls tell how the two clocks are related - "clk2" runs twice as fast as "clk". It is an error to declare two clocks whose schedules are different lengths - 4 phases in this case. Also, the first clock driver is instantiated with a DLL - a Virtex-specific feature.

The setDefaultClock() method deserves further discussion. Consider the following code fragment:

    Wire clk = clockDriver(clkIn, "0001", "clk");
    Wire clk2 = clockDriver(clk2In, "0101", "clk2");

    setDefaultClock(clk);
    new myreg(this, a, q);

    setDefaultClock(clk2);
    new myreg(this, a, q2);
Although neither clock wire is passed into either of the myreg() constructors, the first myreg will receive "clk" as in implicit port and the second will receive "clk2". However, if each myreg() call needed to build some of its circuitry using "clk" and some using "clk2" then both would have had to be passed in as parameters to those calls. It should be obvious that the use of setDefaultClock() can eliminate much typing for you.

NOTE: in the design above "clkIn" is shown as the input to the clockDriver() call. It should be noted that in simulation "clkIn" will never change - the clockDriver() call sets up the simulator to use the phase pattern specified to drive the "clk" signal with alternating 1's and 0's (in this case). Thus, watching "clkIn" in the waveform viewer will not show any signal transitions. However, in real life, the clock will enter this module on "clkIn".

The rest of the JHDL tool suite handles multiple clocks correctly. Jab has options for both Step and Cycle and all viewers are updated every phase. If you do determine to use multiple clocks and you have written testbench code which counts clock cycles, you will need to modify that code since it will now get called every phase.

Pad Insertion Methods in Logic

In this section we outline how to do all of your own pad insertion. In a later section we will discuss in more detail how you can get JHDL to do some of the work for you as was shown in the tutorial.

The first step is to tell JHDL you are going to do your own pads insertion:

    VirtexTechMapper tm = new VirtexTechMapper( true );
    Logic.setDefaultTechMapper( tm );
    ...  ...
    tm.setInsertPads(false);
    tm.netlist( my_cell, "my_cell.edn" );
The line in red is what you add to a normal testbench to prevent pad insertion from automatically being done.

It should be clear that since pads and buffers are primitive cells in every FPGA library that they could be instanced as primitive objects in a design like this:

    new ibuf(this, padWire, cktWire, "myibuf");
However, the Logic class in JHDL provides convenience functions to aid in the insertion of pads and drivers. In particular, Logic calls are technology independent and hide much of the detail from the user. Logic includes the following calls: Consider a design consisting of a single 4-bit counter with clr and increment shown below:
  import byucc.jhdl.base.*;
  import byucc.jhdl.Logic.*;

  public class cntWithPads extends Logic {

    public static CellInterface[] cell_interface = {
      in ( "clkPad", 1 ),
      in ( "clrPad", 1 ),
      out ( "qPad", 4 ),
    };

    Wire clkPad, clrPad, qPad;

    public cntWithPads(Node parent,
                       Wire clkPad,
                       Wire clrPad,
                       Wire qPad,
                       String instanceName) {
      super(parent, instanceName);
      connect("clkPad", clkPad);
      connect("clrPad", clrPad);
      connect("qPad", qPad);

      // Insert clock pad and buffer, return clock to use on "clk" signal.
      Wire clk = padClock(clkPad, null, "clk");

      // Input pad and wire for clr signal - unregistered
      Wire clr = padIn(clrPad, false, null, "clr");

      // Output pad for q signal - unregistered but FAST
      String[] mods = {"FAST"};
      Wire q = padOut(qPad, false, mods, "q");

      // Instance actual counter
      new cnt(this, clk, clr, q);
    }
  }
This design is simply a wrapper to insert pads and then instance a basic 4-bit counter. This is a recommended approach: use a separate layer of hierarchy to wrap your design and put all pads in that layer of hierarchy. Some more items to note:
  1. All of the calls take a String[] to specify technology-specific modifiers. In this example the output was requested to have attribute "FAST" attached to it. The modifiers allowed in each call are technology-dependent.
  2. All calls except padClock() have a parameter to specify whether the driver should include a register. This is useful for forcing registers into IOB's to meet board-level timings.
  3. You should consult the Logic API documentation for details on how to call the above methods.

Letting JHDL Automatically Insert Pads For You

At netlisting time, the default netlister behavior is to automatically generate pads and clock buffers for your top-level design entity. Specifically, the netlister will do the following:
  1. For each input at your design's top level, insert an input pad and buffer. Each pad inserted will have a wire name of "a_IPAD_IN" where "a" is the port name.
  2. For each output at your design's top level, insert an output pad and buffer. Each pad inserted will have a wire name of "a_OPAD_OUT" where "a" is the port name.
  3. If your design has no user-defined clocks, insert an input pad and buffer for the default global clock signal. The clock pad wire name will be "CLK_IPAD_IN".
  4. If your design has user-defined clocks, insert an input pad and buffer suitable for a clock for each of the user-defined clocks. The naming of the pad wire will be similar to inputs above ("a_IPAD_IN" where "a" is the clock port name).
The wire names specified can help you in preparing a .UCF file for the Xilinx tools (or whatever is appropriate to your technology) to map the pads to specific FPGA locations. NOTE: the pad wire name is formed using the port name as a basis, NOT the wire in your circuit connected to that port. Also, note that inout ports are ignored by the above behavior.

The netlisting behavior described above is limited --- if your design contains tri-state outputs or bidirectional pins the above default JHDL mechanisms will be insufficient.

One strategy would then be to do all of your pad insertion manually by instructing JHDL to not insert pads using:

    tm.setInsertPads(false);
in your testbench code.

Another strategy would be to let JHDL do what it can and then do the rest manually. For example, by marking all ports you do not wish JHDL to netlist as inout ports you can force JHDL to leave them alone and you can handle them as you desire (using the methods described previously).

Accessing the Default Global Clock

There is one situation not covered by the above discussion. That is when your design is NOT a multi-clock design but you are doing all your own pad insertion. The question arises: how do you get hold of the Default Global Clock wire and use it in a call to padClock()? This code fragment will do so:
  Wire CLK = getGlobalClock(getSystem());
  Wire CLKPAD = wire(1, "CLK_IPAD_IN");
  padClock_o(CLKPAD, CLK, null);

Netlisting

Netlisting can be as simple as executing the following in your testbench:
    tm.netlist( my_chip, "chip.edn" );
However, there are a collection of options that can be set to get the behavior your want. Here they are:
  tm.setInsertPads(boolean flg);  -- default is true
This allows you to control whether JHDL will automatically insert pads on your top level ports. There are 2 cases where you would set this to false. First, you may want to insert the pads yourself. Second, you may want to generate a black box netlist of your design. That is, you don't want any pads on the design since you are going to take the netlist that JHDL generates and use it in another CAD tool as a black box.

The second flag is:

  tm.setInsertTopLevelPorts(boolean flg);  -- default is false
This allows you to control whether a port interface is emitted for your top level design. Usually (when generating EDIF for a whole chip) you want the default of false. However, you would want to set this to true for generating a black box netlist.

To summarize, here is a discussion of the four possible uses of these two flags:

Inserting Drop-Ins and Other Circuitry

Regardless of whether you let JHDL do some of the work of inserting pads for you, there are cases where you will need to insert additional pads, drivers, and drop-ins. Here are a few examples for Virtex:
  1. The Virtex library contains a "startup_virtex" block. Wiring an input from a pad to its GSR port provides a system-wide asynchronous reset capability. Wiring an input from a pad to its GTS port allows an outside signal to tri-state all output pins on the FPGA. Consult the Xilinx Library Guide for further information. Note that JHDL will NOT simulate this functionality. Nevertheless you may want to include it for proper hardware execution.
  2. Xilinx FPGA's provide a readback capability which is accessed via a readback drop-in and specific pins. Consult the Xilinx Library Guide for further information.
  3. Many FPGA boards require special memory or FIFO drop-ins for proper operation.
NOTE: the JHDL libraries for Xilinx 4K and Virtex are relatively complete. However, some cells (such as the startup and readback blocks) are there for completeness for netlisting and for importing external EDIF designs and do NOT contain simulation models. Consult the library API documentation for more details. 

| 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