| |
为了将我们的ml_adder函数用作DUT,我们创建了一个MATLAB包装器函数,我们可以将其连接到HDL模块。EDA Simulator Link工具箱提供位向量和内部MATLAB数据类型之间的转换功能。
MATLAB源代码如下所示:
function [iport,tnext] = hdl_adder(oport, tnow, portinfo)
% Demonstration for MATLAB Connectivity
% This function uses the HDL Simulator Link methodology to get HDL port values
% into and out of this function
%
tnext = [];
iport = struct();
% Convert the input ports to integers
input0 = mvl2dec(oport.input0);
input1 = mvl2dec(oport.input1);
% This is a call to a simple MATLAB function found in ml_adder.m
output0 = ml_adder(input0,input1);
% Convert and assign the output port to a 9 bit vector
iport.output0 = dec2mvl(output0,9);
% [EOF] hdl_adder.m
modelsim_matlab.m
在Questa和MATLAB Simulator之间创建连接有两个步骤。 首先,启动MATLAB并告诉它创建一个EDA Simulator Link后台程序来监听与Questa的通信。 我们可以使用MATLAB函数来完成这项工作。
MATLAB源代码如下所示:
% This is a MATLAB startup function to create an HDL Simulator Link
% It requires the FLI library to be loaded on the vsim command line
hdldaemon('socket', 5001, 'time', 'int64');
% This adds the MATLAB directory containing the MATLAB functions
addpath ./MATLAB;
第二步是使用添加的FLI命令启动Questa以加载MATLAB EDA Simulator Link功能。 MATLAB提供了所使用的FLI模块,因此我们将“matlabclient $(MATLAB)/ toolbox / edalink / extensions / modelsim / linux64 / liblf hdlc_tmwgcc.so”添加到Questa命令行。
一旦Questa运行,我们提供FLI命令将testbench DUT模块(在本例中为shell模块)连接到MATLAB hdl_adder函数。 这是使用命令'matlabcp / testbench / dut -rising / testbench / dut / valid -mfunc hdl_adder -socket 5001'完成的。 在此示例中,脚本文件(scripts / matlab.do)用于简化此操作。
在此示例中,testbench(sv / testbench.sv)使用+ define + MATLAB编译。 这将使用空模块替换现有的DUT Verilog模块以连接到MATLAB。
您可以使用'make simulate_matlab_dut'运行此示例以查看结果。 运行时,您将看到MATLAB控制台启动,HDL后台程序开始侦听连接。 延迟(为了给MATLAB启动预留时间),Questa将启动并建立DUT到MATLAB的连接。 运行时,您将看到Questa环境正常运行以及在MATLAB控制台中查看MATLAB函数计算。 如果需要对MATLAB函数进行调试,MATLAB控制台的输出也会保存在matlab.log文件中。