算法工程通常会用Matlab来建模,Digital designer会将Matlab model 作为golden model 进行设计和验证。 面临的问题时VCS不用能直接调用.m文件。 这就需要先将.m文件生成System Verilog的DPI或转成Cpp文件,之后就可以在SystemVerilog 中直接调用了
(1) Matlab 生成DPI
下面是两个matlab function,分别在两个独立文件中
function y = fun(x)
y = x * 2;
end
function sample=fun_tb
% Testbench should not require input, however you can give an output.
% Define a test vector
tVecIn = [1,2,3,4,5];
% Exercise fun.m and plot results to make sure function is working correctly
tVecOut = arrayfun(@(in) fun(in),tVecIn);
plot(tVecIn,tVecOut);
grid on;
% Get my sample input to use it with function dpigen.
sample = tVecIn(1);
end
生成DPI的命令
dpigen fun -args {int8(0)} -testbench fun_tb
若不需要生成test_bench,则用命令
dpigen fun -args{int8(0)}
在run_tb_vcs.sh中可看到生成的DPI库
(2)用coder 将.m 转成Cpp或C 有VCS 统一编译
coder