This is an excerpt from the Chapter 1 of the book Principles of Verilog PLI by Swapnajit Mittra published from Kluwer Academic Publishers. ISBN: 0-7923-8477-6 [All copyright reserved. No portion of this text can be used for for commercial purpose without explicit permission from the author nor can it be used for re-print in hardcopy or electronic form.] Order the book here.


Previous | Next


Traditionally, the main body of a PLI code is written in a file, which is called veriuser.c by convention. Though this name is completely user-defined, but while making a script for the compilation in Verilog XL, the vconfig tool will assume this name by default (We will discuss about this later in this chapter). For our discussion, we will assume that our PLI routine will be saved in the file veriuser.c.

To illustrate the basic steps for creating a PLI routine, the following problem is taken. This problem is much simplified compared to the actual 'real life' problems solved using PLI. However, this example shows all the basic steps that are required in all PLI routines.

Problem description
Create a system call $print_reg which takes a register as parameter and prints its value. (This is a simplified version of $display).

As an example, a verilog program like this:

module my_module;
reg [3:0] r1;
initial begin
r1 = 4'ha;
#100 $print_reg(r1);
#100 r1 = 4'h3;
#100 $print_reg(r1);
#100 $finish;

Should produce the values 10 and 3 at times 100 and 300.

The following are the steps for writing a PLI routine.

Step 1 of 4: Including the header files

The file veriuser.c containing the main PLIC program must have

#include <veriuser.h>
#include <vxl_veriuser.h>

in Verilog XL and

#include <vcsuser.h>

in VCS.

As always in C, a header file within corner brackets (i.e. '<' and'>') means during the compilation the file should be either in the /usr/include directory or in a path include_path_name. In the later case, however, the program must be compiled with -Iinclude_path_name option. The include files can also be specified as shown below.

#include "include_path_name/veriuser.h"
#include "include_path_name/vxl_veriuser.h"

A typical example of include_path_name may look like /usr/caetools/verilog/.../include
The header file(s) contains the most basic data-structures of the Verilog-PLI that the program will use.

Step 2 of 4: Function prototype and Variable declaration

This part of the program contains all local variables and the functions that it invokes as part of the system call. In the present case, as explained in the next step, it will be as shown below.

int my_calltf(), my_checktf();

However, if the functions are in separate files, they sould be declared as external functions.

extern int my_calltf(), my_checktf();

A typical PLI code, like any other C program, may need few other housekeeping variables.

Previous | Next Share/Save/Bookmark

Verification Management
Join Verification Management Group

Shop Amazon - Contract Cell Phones & Service Plans

Book of the Month