I’m having trouble with an export function. I can’t put the export function in a predictor class, but the import functions seems ok in the class.
Any Ideas?
Thanks in advance,
Dan
import “DPI-C” context function int my_C_function(input int i1, i2);
export “DPI-C” function my_SV_function;
class my_predictor extends ovm_component;
.
virtual function my_SV_function(input byte i1[15:0]);
begin
end
virtual function exe_dut();
begin
ret = my_C_function(t1,t2);
end
The DPI is C-based only - you can only call static functions across the interface, and you cannot pass SV class handles across the interface either. You will have to create a look-up table, perhaps using an associative array, and pass an ID as an extra argument to your C imported function. Then when you call the SV exported function, you can pass the ID back and lookup the handle needed to call your virtual method.
My C model simply makes some calculations and stored the result in const char array, so I need to get the result back into the SystemVerilog OVM predictor class.
Is there a way to return the result in the imported c cfunction?
I also saw a post on this forum that mentioned something about using a global function that gets the handle to the class and then calls the function in the class. Does this sound like the right thing to do?
FYI: I’m new to DPI and just learning. If you could point me to an example, that would be great.
Although its return type is limited, an imported C function can have output arguments with the same types allowed for input arguments. Output arguments are passed by reference on the C side. So you can have
import “DPI-C” context function int my_C_function(input int i1[], i2[], output byte i3[15:0]);
The C prototype will be (using Questa’s -dpiheader generator)
void
my_C_function(
const svOpenArrayHandle i1,i2,
char* i3);
Note that the byte ordering of i3 will be reversed on the C side because arrays always start with [0] and not [15] as you specified in SV.
Idea is to use a module/interface and create a handl-object of this wrapper class. Have a static function declared in that module/interface then export it to C-side.