In DPI-C, How to map data type to reg or wire

170 Views Asked by At

I am writing a CRC16 function in C to use in System Verilog.

Requirement as below:

Output of CRC16 has 16 bits Input of CRC16 has bigger than 72 bits The difficulty is that I don't know whether DPI-C can support map data type with reg/wire in System Verilog to C or not ? how many maximum length of reg/wire can support to use DPI-C.

Can anybody help me ?

2

There are 2 best solutions below

1
dave_59 On

Stay with compatible types across the language boundaries. For output use shortint For input, use an array of byte in SystemVerilog which maps to array of char in C.

1
Serge On

Dpi support has provision for any bit width, converting packed arrays into c-arrays. The question is: what are you going to do with 72-bit data at c side?

But, svBitVecVal for two-state bits and svLogicVecVal for four-stat logics could be used at 'c' side to retrieve values. Look at H.7.6/7 of lrm for more info.

Here is an example from lrm H.10.2 for 4-state data (logic):

SystemVerilog:

typedef struct {int x; int y;} pair;
import "DPI-C" function void f1(input int i1, pair i2, output logic [63:0] o3);

C:

void f1(const int i1, const pair *i2, svLogicVecVal* o3)
{
  int tab[8];
  printf("%d\n", i1);
  o3[0].aval = i2->x;
  o3[0].bval = 0;
  o3[1].aval = i2->y;
  o3[1].b = 0;
  ...
}