Visualization of Verilog Simulation Using TCL/TK

 

 

Contents

*     Introduction

*     Creating Graphical TCL/TK Application

*     Attaching TCL/TK Application to Verilog

*      Verilog Interface

*      TCL Interface

*     Download

 

 

 

Introduction

The following article describes how to visualize a Verilog simulation run and make it interactive.

 

*     First, draw any picture/add text using TKPaint graphical editor.

*     Then, click on the “P” button and add custom procedures to add, delete or modify the properties of graphical objects.

*     Save it as a standalone TCL application.

*     Finally, call TCL procedures from Verilog using $tcleval PLI function, attaching them to the chosen simulation events.

 

The following picture presents TKPaint GUI with three visualization examples:

 

 

Simulation events can modify any graphical objects, for example:

 

*     Fill current state of state machine diagram during simulation

*     Collect statistics and constantly modify packet types histogram

*     Collect statistics of transmitted/received/canceled packets of the switch ports

 

 

Creating Graphical TCL/TK application

 

The first step is a TCL application creation. This can be easily achieved using a modified version of TKPaint TCL/TK-based editor.

 

First, install TKPaint application as described in INSTALL file.

Launch TKPaint and draw any graphical objects / text using a simple and convenient GUI interface:

 

 

When the picture is ready, click on “P” in order to open the following window:

 

 

In order to update the properties of existing graphical objects, write custom procedures inside this window. These procedures should have no input parameters. Use vergetp and verputp procedures in order to communicate between TCL and Verilog domains. For example, “state” variable in the procedure above is passed from Verilog domain.

 

In order to distinguish between different graphical objects, unique object’s tag identifiers must be used. Click on the object while you are in the procedures editing mode in order to get object’s tag. It will appear inside information entry in the bottom of TKPaint window.

 

All graphics modification commands should have the following format:

.c itemconfigure <object_tag_name> -<property_name> <property_value> … . Please, check canvas TCL manual page for more information about this command.

 

The update command should be used at the end of any procedure: graphical widget should be updated after each change.

It is possible to run selected code from procedural window. First, mark selected code lines with the left mouse button. Then, click on “Run Selected” button on the bottom of procedural window to execute selected lines of code.

 

Finally, click on “OK” button to close procedural window and save pictures along with procedural code. Use File -> Save As -> TCL Application menubutton for this purpose.

 

By doing that, you actually create an independent graphical TCL application, which can be run with the wish <saved_file_name> command.

 

 

Attaching TCL/TK Application to Verilog

 

Use ver-tcl-bridge package in order to attach TCL/TK applications to Verilog. Please, check README file for installation details.

See examples in examples/ directory for graphical and non-graphical verilog-to-tcl application examples.

 

Verilog Interface

TCL-to-Verilog bridge defines $tcleval PLI function to be used in verilog files. All data communication and TCL procedures invocation should be done using this function.

First, invoke TCL/TK application in the very beginning of simulation run:

  initial $tcleval("source examples/state.tcl");

 

Then, use $tcleval function to invoke TCL procedures, passing to these procedures specified parameter(s). Invocation of this function should be attached to chosen simulation event:

  always @(posedge clk) $tcleval("mark_states", st1.state);

 

TCL interface

In TCL domain, the following functions ar introduced:

vergetp <parameter ordering number> - passes to TCL the value from Verilog domain. The first parameter in verilog domain corresponds to second one in TCL.

 

For example, in order to pass the value of st1.state to TCL, we must use the following code line within “mark_states” procedural body:

   set mark_states [vergetp 2]  in TCL domain and invoke this procedure from Verilog domain using

   $tcleval(“mark_states”, current_state);   statement.

 

verputp <parameter ordering number> - passes the value from TCL domain to verilog. Note, that vergetp and verputp functions can be used in the same procedure, passing parameter from verilog to tcl domain, updating it (if required) and finally passing it back. So, PLI functions can be realized as well using verilog-to-tcl bridge.

 

verprint <string_to_print> - prints specified string in verilog simulation log

 

vertime  - returns current simulation timestamp to TCL domain

 

Please, see examples/tb.v and examples/tb.tcl inside ver-tcl-bridge package for demonstration of these functions.

 

 

Download

 

TKPaint Application    -     tkpaint.tar.gz

Verilog-to-TCL bridge -     ver-tcl-bridge.tar.gz