Suppose I have a packed struct:
typedef struct packed {
logic a;
logic [7:0] b;
bit [7:0] c;
logic [7:0] [31:0] d;
} my_struct;
And I want to pass it into a C function:
import "DPI" context function int my_dpi_function (input my_struct data);
How do I read values on C side?:
int my_dpi_function (void* data)
{
... ?
return 0;
}
The type you need is defined in the
svdpi.hheader:So, you need something like:
svLogicVecValis itself a struct. It has two fields -avalandbval(or sometimes, eg in Cadence,aandb). Fromsvdpi.h:The
avalandbvalfields are encoded thus (the so-called "canonical representation"):So, you can access the
avalandbvalfields in your C. It turns out that for vectors wider than 32-bits, the most-significant 32-bit word is at the highest pointer address.https://www.edaplayground.com/x/2k33
SV
C++