JHDL 0.3.39

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


Verification of JHDL Designs Using the Observable Interface

The Observable interface is provided to assist in a variety of tasks including: (1) the writing of self-validating designs, (2) the creation of custom graphical browser elements, and (3) the creation of formatted simulation output. Any JHDL cell can implement this interface. If so, the cell must implement three methods:
  // Called each time the simulator resets
  public void reset();

  // Called each clock cycle after the circuit settles
  public void update();

  // Called each time the JHDL system deems a refresh of all
  // GUI elements is warranted
  public void refresh();

Debug Printing With The Observable Interface

As an example, consider the following simple design for a 4-bit counter and focus in on blue section:
///////////////////////////////////////////////////////////////////////
import byucc.jhdl.base.*;
import byucc.jhdl.Logic.*;

// Class name is TestObservable.  It implements the Observable interface...
public class TestObservable extends Logic implements Observable {

  public static CellInterface[] cell_interface = {
    out ( "q", "WID" ),
    param ("WID", INTEGER),
  };

  Wire q;

  // This is just the constructor as normal
  public TestObservable(
           Node parent,
           Wire q,
           String instanceName
         ) {
    super(parent, instanceName);
    bind("WID", q.getWidth());
    this.q = connect("q", q);

    // Build a simple counter...
    Wire s = wire(q.getWidth(), "sum");
    add_o(q, constant(q.getWidth(), 1), s, "addn");
    reg_o( s, q, "cntOut");
  }

  // The Observable interface stuff follows
  int cycle;           // Current cycle

  public void reset() {
    cycle = 0;
  }

  public void refresh() {
  }

  // Print results to screen as well
  public void update() {
    System.out.println("Cycle = " + cycle + ": " + q.get(this));
    cycle++;
  }
}
///////////////////////////////////////////////////////////////////////
What is being done is that the update() method is being used to print out the current state of the circuit. The simulator will call this method every cycle after the circuit has stabilized. The cycle variable is used to count clock cycles.

This same capability has been successfully to do complex validation of stream-based DSP designs that would be extremely difficult to do by looking at waveforms. For example, consider a system where data arrives infrequently and must be converted from serial to parallel format before any other meaningful processing occurs. The update() method can test the circuit's internal signals each clock cycle and print out key circuit values only on clock cycles when something of interest occurs (a conversion has completed). In addition, this output can be printed in a format that a tool such as Matlab could read in and post-process or plot. It often makes sense to also convert the bits in the circuit to their equivalent floating point representations for viewing (the Jab tools have only integer types available for display).

Creating Self-Validating Designs

It is easy to see that the usage shown above could be easily extended to have the update() method actually check the correctness of the module. This would be done by comparing correct results with those generated by the circuit. The correct results could either be computed right in the update() method or retrieved from a file or remotely running program.

Creating Custom Graphical Browser Elements

The refresh() method makes it also possible to create custom browser elements such as FIFO viewers or memory viewers. For example, consider the modification to the above example in blue below:
  // The Observable interface stuff follows
  int cycle;           // Current cycle
  TestFrame tf;        // Frame to hold cycle count in GUI

  public void reset() {
    // Create a testFrame if one doesn't exist yet
    if (tf != null)
      tf.dispose();
    tf = new TestFrame();
    cycle = 0;
  }

  // Update information in TestFrame
  public void refresh() {
    tf.updateValues(q.get(this));
  }

  // Print results to screen as well
  public void update() {
    System.out.println("Cycle = " + cycle + ": " + q.get(this));
    cycle++;
  }
}
Assuming a graphical viewer class named TestFrame has been defined, this code will create the frame on reset and then update it with new values by calling its updatevalues() method each cycle. When running in single step mode in Jab, the TestFrame will then be updated with a new value each cycle.

The Complete Example

As a complete example, the following three files can be used to demonstrate this capability:
tb_TestObservable.java
The testbench of the 4-bit counter example...
TestObservable.java
The actual 4-bit counter...
TestFrame.java
The GUI element for the 4-bit counter Observable example... 

| 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