In 2003, IEEE 1800 SV LRM 3.1a proposed a direct programming language interface DPI (Direct Programming Interface). SystemVerilog DPI (Direct Programming Interface) is an interface that connects SystemVerilog with external languages; DPI can connect C more concisely. /C++ or other non-verilog programming languages, as long as you use import declaration and use to import a C subroutine, you can call the C subroutine just like calling a subroutine in SystemVerilog;
DPI consists of two layers: SystemVerilog layer and external language layer, both layers are isolated from each other, which programming language is actually used as a foreign language is transparent, and has nothing to do with the SystemVerilog side of this interface; theoretically, the external language can be C, C++ , SystemC and other languages. But now, SystemVerilog only defines an external language layer for C language, which means that currently DPI only supports C;
Consider the following simple example:
module test;
import "DPI-C" pure function void from_c();//导入外部c
initial begin
$display("Entering in sv initial block");
#20;
from_c();
#5;
$display("Exiting from sv initial block");
end
endmodule
External C:
#include