I have the following files:
C file with functions:
// funcs.c
#include <stdio.h>
void something() {
printf("something\n");
sayHello();
}
System verilog file:
// hello_world.v
module kuku;
export "DPI-C" function sayHello;
import "DPI-C" function void something();
initial something();
function int sayHello ();
$display("hello world");
sayHello = 1;
endfunction
endmodule
How can I compile it and make this work so when I call something()
from SV, it will call the C function, and when I call sayHello()
from C, it will call the SV function?
Answering myself:
When SV code is compiled using VCS, it is first translated into C code.
When
exporting
a function out of SV, it generates a C header filevc_hdrs.h
that should be included by the C file.So a change I made in the C file is to add the line:
Then, I just added the C functions file to the VCS compilation command:
It works!
The output I get is:
.