I have coded an algorithm using MATLAB R2019 script and i want it to be called in an System verilog file i.e The output generated by the matlab script is actually to be fed into the testbench written using SV. I dont want to use HDL coder tool as the algorithm is quite complex and re-coding it in SV/ C is quite difficult. I use synopsys VCS tool for compilation and elaboration. My question is : 1. Is it possible that a MATLAB script to be called in testbench written in SV ? I've heard about DPI, but not much idea on it, or worked on it. 2. Can the output of the MATLAB script stored in a separate file, let's say for example a text file and i can call that file in my SV test bench.?
To answer your questions in order, it is indeed possible.
You need to do the following:
In SV, import a C function (extern DPI-C) that you will call as required. Say we call this callMatlabFn
In C, define an extern function called callMatlabFn. This will then actually call your matlab fn. Have a look here for calling matlab in C : https://www.mathworks.com/help/matlab/matlab_external/call-matlab-functions-from-c-1.html
Finally, text File I/O in SV is implemented via the following system tasks:
$fopen (file_name) ;
$fclose (file_name) ;
$fdisplay (arguments) ;
$fwrite (arguments) ;
$fstrobe (arguments) ;
$fmonitor (arguments) ;
$readmemb ("file", memory_identifier [,begin_address[,end_address]]) ;
$readmemh ("file", memory_identifier [,begin_address[,end_address]]) ;