Analysis Components & Techniques(从predictor_matlab.svh开始)

上一篇 / 下一篇  2018-12-28 15:08:17

   predictor_matlab.svh

       一旦我们编译并将matlab_dpi.so添加到Questa vsim命令行,我们就可以启动/停止MATLAB引擎并使用MATLAB引擎作为记分板预测器。扩展了原始预测器,我们将build(),write()和report_phase()函数替换目的为了控制MATLAB。要使用上面的MATLAB函数ml_adder,我们只需将命令字符串“X = ml_adder(in0,in1)”发送到MATLAB。MATLAB将调用ml_adder函数,结果放在MATLAB输出缓冲区中,我们读回来解析响应。预测器然后将预测的事务发送到记分板预测的analysis port。

       //----------------------------------------------------------------------
       //           Mentor Graphics Corporation
       //----------------------------------------------------------------------
       // Project : my_project
       // Unit : predictor_matlab
       // File : predictor_matlab.svh
       //----------------------------------------------------------------------
       // Created by : cgales
       // Creation Date : 2012/01/04
       //----------------------------------------------------------------------
       // Title:
       //
       // Summary:
       //
       // Description:
       //
       //----------------------------------------------------------------------

       //----------------------------------------------------------------------
       // predictor_matlab
       //----------------------------------------------------------------------

       class predictor_matlab extends predictor;
            // factory registration macro
            `uvm_component_utils(predictor_matlab)

       。。。

            //--------------------------------------------------------------------
            // build_phase
            //--------------------------------------------------------------------
            function void build_phase(uvm_phase phase);
                 // During the build phase, start MATLAB and add
                 // MATLAB dir to enable access to MATLAB functions
                 if (!start_matlab("matlab -nosplash")) begin
                     `uvm_fatal(get_name(), "Unable to start MATLAB");
                 end

                 void'(send_matlab_cmd("addpath ./MATLAB;"));

                 m_output_ap = new("m_output_ap", this);
            endfunction : build_phase

            //--------------------------------------------------------------------
            // write
            //--------------------------------------------------------------------
            function void write(T t);
                 in_tran m_out_item;
                 string msg, cmd, cmd_rsp;

                 m_out_item = in_tran::type_id::create("m_out_item");

                 //t is the input sequence item (transaction). Process t and then
                 // write the new processed output to the m_output_ap.
                 m_out_item.do_copy(t);

                 $sformat(msg, "INPUT: %s",t.convert2string());
                 `uvm_info(get_name(),msg, UVM_HIGH);

                 $sformat(cmd, "X = ml_adder(%0d,%0d);", t.input0, t.input1);
                 `uvm_info(get_name(), cmd, UVM_HIGH);

                 // Call our MATLAB function with our transaction inputs
                 void'(send_matlab_cmd(cmd));

                 // Readback the MATLAB buffer with our output
                 cmd_rsp = get_matlab_buffer();

                 `uvm_info(get_name(), $sformatf("MATLAB Buffer is %s", cmd_rsp), UVM_HIGH);

                 if (!$sscanf(cmd_rsp, ">> %d", m_out_item.output0)) begin
                     `uvm_warning(get_name(), "Error parsing MATLAB response");
                 end

                 m_output_ap.write(m_out_item);
            endfunction : write

            function void report_phase(uvm_phase phase);
                // All done - shut down MATLAB
                stop_matlab();
            endfunction

       endclass : predictor_matlab

       (在上在线下载源代码示例)。


TAG:

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2019-01-12  
  12345
6789101112
13141516171819
20212223242526
2728293031  

数据统计

  • 访问量: 19247
  • 日志数: 75
  • 建立时间: 2018-09-03
  • 更新时间: 2018-12-29

RSS订阅

Open Toolbar
魔域私服 魔域私服 魔域私服 魔域私服 魔域私服

<small id='m0x0z'></small><noframes id='1726r'>

  • <tfoot id='mmlvi'></tfoot>

      <legend id='kmhwv'><style id='071zv'><dir id='fu3zz'><q id='v9jb2'></q></dir></style></legend>
      <i id='rvsit'><tr id='4khb3'><dt id='4ps3i'><q id='fj644'><span id='m21m7'><b id='7hssf'><form id='2bz20'><ins id='9e9mf'></ins><ul id='jg3x0'></ul><sub id='d5rzg'></sub></form><legend id='s16m2'></legend><bdo id='uf6de'><pre id='7kaa9'><center id='64fml'></center></pre></bdo></b><th id='9y0g0'></th></span></q></dt></tr></i><div id='y26a4'><tfoot id='naeve'></tfoot><dl id='jmz8r'><fieldset id='dylj1'></fieldset></dl></div>

          <bdo id='vd6ek'></bdo><ul id='cel2j'></ul>

          1. <li id='1d8vx'><abbr id='s8jfy'></abbr></li>