How can I copy data from C/C++ array to the entire SV array using SV-DPI?

854 Views Asked by At

I would like my array of data from SystemVerilog have the entire copy of data from the array on the C/C++ side:

C/C++ code:

void myCfunc(svOpenArrayHandle results) {
    int randomsize;
    ...
    uint32_t myArray[randomsize];
    ...
    svPutBitArrElemVecVal(results, myArray, 1); // copies only the first element
    //svPutBitArrElemVecVal(results, myArray, 1, 2, 3); // still only copies the first element for some reason
    // svCopyArr(results, myArray); // this isn't a DPI function, but I would like do to something like this.
    // Copy the whole array, not just the an element
}

SV code:

module tb_top;
    int results[100];
    import "DPI-C" function myCfunc(output int results[]);
    ...
    initial begin
        myCfunc(results);
    end
endmodule : tb_top

My issue is that I don't know the exact size of the source array each time. Also, even if it was a fixed size every time, I would imagine having a long list of index arguments would be excessive for a large array. The other SV-DPI handler functions either don't seem to apply to my case or I must be misunderstanding how they are to be used.

1

There are 1 best solutions below

0
Serge On

You construct is called 'open array'. Standard defines a fiew functions which could be used to determine array parameters.

/*
* Open array querying functions
* These functions are modeled upon the SystemVerilog array
* querying functions and use the same semantics.
*
* If the dimension is 0, then the query refers to the
* packed part of an array (which is one-dimensional).
* Dimensions > 0 refer to the unpacked part of an array.
*/
/* h= handle to open array, d=dimension */
XXTERN int svLeft(const svOpenArrayHandle h, int d);
XXTERN int svRight(const svOpenArrayHandle h, int d);
XXTERN int svLow(const svOpenArrayHandle h, int d);
XXTERN int svHigh(const svOpenArrayHandle h, int d);
XXTERN int svIncrement(const svOpenArrayHandle h, int d);
XXTERN int svSize(const svOpenArrayHandle h, int d);
XXTERN int svDimensions(const svOpenArrayHandle h);

As an alternative method you can pass array size as a separate parameter to your function.