In reply to dave_59:
The original problem is simple:
unlike dpi import which support open array for variable amount of data, what is the generic way of sending variable amount of data from C to SV, if the C function is called by irrelevant caller, like VPI callback.
It seems I’m using the 2nd way you described:
-
send the C pointer to the data and size of the data to SV via a DPI export:
void callback()
{
…
send_data_to_sv(data_ptr, size);
…
} -
send_data_to_sv allocated dynamic array using the size and call DPI import for final copy:
export "DPI-C" function send_data_to_SV(chandle ptr, int size);
import "DPI-C" function void copy_data(chandle ptr, inout int array[]);
function void send_data_to_sv(chandle ptr, int size);
int array[] = new[size];
copy_data(ptr, array);
endfunction
- in C side, define copy_data
void copy_data(void* data_ptr, svOpenArrayHandle h)
{
memcpy(svOpenArrayHandle(h), dsta_ptr, svSizeOfArray(h);
}
You can see in above solution there are two DPI calls. Would the performance be better if we get rid of the import? Instead, we copy data directly in the callback function and call a simple dpi export to get SV notified.