I would like to communicate c with verilog. I find the Verilog PLI can solve my problem. I read this website to learn http://www.asic-world.com/verilog/pli1.html#How_it_Works . But I still can't work even a printf function. I use ncverilog for verilog compiler. What I done is blow. I can't have a successful compile for this. It says that it can't find the function. Can anyone tell me how to solve my problem. thanks =)
C code: hello.c
#include<stdio.h>
void hello(){
printf("HELLO");
}
make library:
gcc hello.c -fPIC -shared -o hello.so
verilog code: test.v
module test();
initial begin
$hello;
#10 $finish;
end
endmodule
verilog command:
ncverilog test.v +access+r -v hello.so
VPI (PLI 2.0)
hello_vpi.c :
Commands:
PLI 1.0 requires all the C methods use in verilog to be defined in
s_tfcell veriusertfs[]
. Ncverilog requires an additional bootstrap method that returns a typep_tf_cell
, this method defines a statics_tfcell veriusertfs[]
. Here is an example:veriuser_nc.c :
Commands:
VCS requires a tab file instead of an bootstrap method. This is lightly covered here: http://www.asic-world.com/verilog/pli2.html#Linking_With_Simulator
Another approach is to use SystemVerilog DPI which does not have a wrapper/translation layer in the same sense as PLI/VPI.
Add
#include "svdpi.h"
to the head of hello.c. I'm just changing the shared objects name to identify the library type (not required).gcc hello.c -fPIC -shared -o hello_dpi.so
verilog code: test.sv
verilog command:
Documentation on DPI is in the IEEE std 1800-2012 § 35. Direct programming interface. PLI/VPI is covered in § 36 but does not cover simulator specif requirements. For more description and tutorials about DPI, checkout http://en.wikipedia.org/wiki/SystemVerilog_DPI and http://www.doulos.com/knowhow/sysverilog/tutorial/dpi/