方法1:
dpi_func.c
#include <stdio.h>
int add_int(){
printf("C::display!!!!\n");
}
pkg_0.sv
module test;
import "DPI-C" context function void add_int();
initial begin
add_int();
end
endmodule
编译命令:
vcs +DPI dpi_func.c -full64 -cpp g++ -LDFLAGS -Wl,--no-as-needed -debug_pp \
-sverilog \
-assert en +define+UVM_OBJECT_MUST_HAVE_CONSTRUCTOR \
-f filelist.lst \
-R \
-o test_stim
方法二:直接加载.so
同样是上面的文件,只不过修改对应的编译命令。
将要调用的.c文件编译成.so文件
gcc -fPIC -shared -o libdpi_func.so dpi_func.c
编译:
vcs -full64 -debug_access+all \ -sverilog \ -assert en +define+UVM_OBJECT_MUST_HAVE_CONSTRUCTOR \ -f filelist.lst \ -o test_stim
仿真:
./test_stim -sv_lib libdpi_func
-sv_lib能够自动去找。
vcs -sverilog -full64 -f filelist.lst /home/qingxu12/UVM/dpi_demo/libdpi_func.so
直接将.so加载仿真命令里面。
vcs -sverilog -CFLAGS -DVCS -LDFLAGS "-Wl,-rpath,/home/qingxu12/UVM/dpi_demo -L/home/qingxu12/UVM/dpi_demo -ldpi_func" -full64 -debug_access -LDFLAGS " " -xprop=xp_config_file -timescale=1ns/1ps -f filelist.lst
加上-LDFLAGS对应的VCS的选项。