My objective is to pass an array from C to SV and print the array contents in SV, I have tried the following C program of converting some text file(data_file.txt) (given full source in the link below) to an array and trying to read back the array by using DPI calls in SystemVeilog(SV), in "C" I have passed the array values to my function(mydisplay) which is inside the main func.(please correct me if I am wrong here) also it seems the array values are not read back to the SV environment as I would expect what could be the reason, is there an efficient way to get back the array in SV?
c code:
void mydisplay(svOpenArrayHandle h) {
int *a;
a =(int*)svGetArrayPtr(h);
for( i=0;i<idx;i++) {
io_printf("C: values[%2zu]=0x%02x\n",i,values[i]);
a[i] = values[i];
}
}
sv code:
program automatic top;
int a[32000];
import "DPI-C" function void mydisplay(inout int h[]);
initial begin
mydisplay(a);
foreach(a[i]) $display("SV after DPI: a[%0d]=%0d",i,a[i]);
end
endprogram
source at EDAplayground
After some trials I've finally found the solution and able to pass the processed text data from C to SV by a small tweak, I just imported a function and called the exported function using already available context method in the SV-DPI as per LRM, also only used the user defined function and removed the main from native "C" lang., this way I was able to read back the values in the array values from C to SV, provided below the code samples, updated code at EDAPlayground
C code:
SV code: