hi,
I’m new in systemverilog vpi. I try to get value of argument pasing as chandle (void *). I dont know what i’m doing wrong. Minimum require sorce code is below. Please can you give me some advice?. I’m using modelsim to simulate. I have an other question: Is pli death and i should only use dpi?
vsim -version
“Model Technology ModelSim SE-64 vsim 10.6a Simulator 2017.03 Mar 16 2017”
I think 2017.03 is xilinxe library.
import "DPI-C" function chandle malloc(int size); //only for test purpose
import "DPI-C" function void free(chandle ptr); //only for test purpose
import "DPI-C" function int printf(string s, chandle add); //only for test purpose
module testbench();
int ret;
chandle addr;
initial begin
addr = malloc(10);
printf("addr %p\n", addr);
ret = $hello(addr);
free(addr);
end
endmodule
//test.c
[c]
static int hello(PLI_BYTE8 * user_data){
vpiHandle this, args, arg;
struct t_vpi_value val, ret;
void * data;
//get pointer to caller of this function
this = vpi_handle(vpiSysTfCall, NULL);
args = vpi_iterate(vpiArgument, this); //get pointer to arguments
while(arg = vpi_scan(args)){
if(type == 622){ //vpiChandlerVar
val.format = vpiSuppressVal; // vpiObjTypeVal; // vpiSuppressVal;
vpi_get_value(arg, &val);
data = val.value.misc;
printf(“addr is %p\n” , data);
}
}
return 0;
}
void Registerhello( void )
{
s_vpi_systf_data systf_data;
vpiHandle systf_handle;
systf_data.type = vpiSysFunc; //vpiSysTask;
systf_data.sysfunctype = vpiIntFunc; // 0;
systf_data.tfname = “$hello”;
systf_data.calltf = hello;
systf_data.compiletf = 0;
systf_data.sizetf = 0;
systf_data.user_data = 0;
systf_handle = vpi_register_systf( &systf_data );
vpi_free_object( systf_handle );
}
void (*vlog_startup_routines)() = {
Registerhello,
0
};
[/c]
//output
addr 0x29534d0
addr is (nil)
//compilation procedure
vlib work
vlog -sv12compat test.sv
gcc -std=c11 -g0 -O3 -fPIC -I/usr/local/fpga/Modeltech/include test.c -o test.o -c
ld -shared test.o -o test.so
vsim -c testbench -pli test.so
run -all
quit -f