0

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 ?

toolic
  • 57,801
  • 17
  • 75
  • 117

2 Answers2

1

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.

dave_59
  • 39,096
  • 3
  • 24
  • 63
  • Hi Dave, Serge, Thank you very much for your guide. Now, It works for me. I try with both svLogicVecVal* and array as input. Because the C function of CRC16 use "for loop" each byte so using array is better. – Trong Tran Feb 14 '23 at 01:59
0

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;
  ...
}
Serge
  • 11,616
  • 3
  • 18
  • 28
  • Hi Serge, Thank you very much for your solution. I have tried with svLogicVecVal*. C function and system verilog fucntion can compile without any error. But the C function of CRC16 use "for loop" each byte so using array is better. For other function, I think using svLogicVecVal* is a good choice. – Trong Tran Feb 14 '23 at 02:09