Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Create an account
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
wafer.jpg

Verilog PLI Tutorial - part 1

E-mail Print PDF

Introduction Verilog PLI (Programming Language Interface) is a mechanism to invoke C or C++ functions from Verilog code. The function invoked in Verilog code is called a system call. An example of a built-in system call is $display, $stop, $random. PLI allows the user to create custom system calls, something that Verilog syntax does not allow us to do. Some of these are:- 

  • Power analysis.

  • Code coverage tools.

  • Modifying the Verilog simulation data structure - more accurate delays.

  • Custom output displays.

  • Co-simulation.

  • Design debug utilities.

  • Simulation analysis.

  • C-model interface to accelerate simulation.

  • Testbench modeling.

To achieve these applications of PLI, C code should have access to the internal data structure of Verilog simulator. To facilitate this Verilog PLI provides something called acc routines or simply access routines.

There is a second set of routines, which are called tf routines, or simply task and function routines. The tf and acc are PLI 1.0 routines and are very vast and very old. The next set of routines, which was introduced with the latest release of Verilog 2001 is called vpi routines. These are small and crystal clear PLI routines and thus the new version PLI 2.0.

You can get Verilog 2001 LRM or PLI 1.0 IEEE document for details of each and every function provided. Verilog IEEE LRMs are written in such a way that anyone with hardware background can understand. If you are unable to get hold of the above IEEE docs, then you can buy the PLI books listed in books section.

How it Works

  • Write the functions in C/C++ code.

  • Compile them to generate shared libs (*.DLL in Windows and *.so in UNIX). Simulator like VCS allows static linking.

  • Use these Functions in Verilog code (Mostly Verilog Testbench).

  • Based on simulator, pass the C/C++ function details to simulator during compile process of Verilog Code (This is called linking, and you need to refer to the simulator user guide to understand how this is done).

  • Once linked just run the simulator like any other Verilog simulation.

../images/verilog/pli_flow.gif

During execution of the Verilog code by the simulator, whenever the simulator encounters user defined system tasks (the ones which start with $), the execution control is passed to the PLI routine (C/C++ function).

Example - Hello World

We will define a function hello, which when called will print "Hello Deepak". This example does not use any of the PLI standard functions (ACC, TF and VPI). For exact linking details, please refer to simulator manuals. Each simulator implements its own way for linking C/C++ functions to simulator.

C Code

1 #include  

 2 

 3 void hello () {

 4   printf ("\nHello Deepak\n");

 5 }

Verilog Code

1 module hello_pli ();

 2    

 3 initial begin

 4   $hello;

 5   #10 $finish;

 6 end

 7     

 8 endmodule

Running the Simulation

Once linking is done, simulation is run as a normal simulation as we saw earlier, with slight modification to the command line options: we need to tell the simulator that we are using PLI (Modelsim needs to know which shared objects to load in the command line).

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

Last Updated ( Tuesday, 29 March 2022 01:02 )  
Chat Zalo