SystemVerilog DPI Tutorial

[SystemVerilog Layer]

Next: Imported functions

Since its version 3.1 onward, SystemVerilog has introduced one of the most powerful foreign language interfaces since VPI. Named DPI, it allows you to inter-mingle C and Verilog with unprecedented ease and elan. This tutorial demystifies the black magic of SystemVerilog DPI for you and teaches you how to take advantage of its various features in your simulation environment.

What is DPI?

Direct Programming Interface or DPI is an interface between SystemVerilog and C that allows inter-language function calls. This means a SystemVerilog task or function can call a C function. And conversely, a C language function can call a SystemVerilog task or function. A C function call from the SystemVerilog side will look identical to any other SystemVerilog task or function call. Similarly, a SystemVerilog task or function call from the C side is no different from any other C function call (see Figure 1). And best of all, you can do all these without any knowledge or overhead of PLI or VPI.

SystemVerilog

	 ...
	 if (p==1'b1) 
	    t = hello_sv();
         ...
	 
C

	 void hello_sv() { 
	    printf("Hello from C\n");
	 } 
	 
Figure 1. A simple DPI example

Theoretically, DPI is not specifically meant for interfacing C and SystemVerilog only. It leaves the option open to extend the interface to include any foreign language and SystemVerilog. However, for now, DPI only describes the syntax and semantics of the interface for SystemVerilog and C.

Little bit of history

While Verilog PLI has been immensely popular and successful, by late 90s it was becoming apparent that a more generalized and lucid interface with less overhead was required. By that time mixed language simulators, primarily combining VHDL and Verilog, were common places and there was no reason why the same concept could not have been extended to other foreign language interfaces. In its proprietary Superlog language Co-design Automation, an EDA start-up at that time, successfully applied this principle to marry Superlog and C using, what it called, its CBlend technology. Many other EDA vendors also came up with similar technologies. One recurrent theme echoed in all of these conceptually similar technologies was the need to standardize a direct, straight-forward and simple foreign language interface.

It was left to Accellera to do the standardization job. With the help of an assorted group of EDA industry leaders, EDA start-ups and user companies putting their heads together, Accellera published its SystemVerilog 3.1 standard in April '03 that included DPI. Further enhancements were made to the DPI in the next version of the standard 3.1A.

PLI is not going away

DPI, by no means, is a replacement for PLI (or VPI). Rather, their roles are complementary. There are primarily two reasons why PLI and VPI will continue to exist, and flourish, in the future.

  • PLI and VPI's time-tested methodologies ensure protection of the simulator database. PLI and VPI will continue to provide a secure mechanism to access design data while preserving integrity of the simulator database.
  • For many, PLI is and will remain the interface of choice for years to come. There are many applications out there written using PLI and VPI. These legacy applications will be maintained, new add-ons to them will be created and altogether new application will emerge - all using PLI and VPI.

Perhaps the best vote of confidence on PLI's utility can be seen in Accellera's decision to include full VPI support for the entire SystemVerilog language. The same VPI methodology that you know and love will now be applicable to the entire object set of SystemVerilog.

Next: Imported functions

Share/Save/Bookmark



Verification Management
Join Verification Management Group


Book of the Month


From Our Press