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-02-13  
     12
3456789
10111213141516
17181920212223
2425262728  

數據統計

  • 訪問量: 22481
  • 日志數: 75
  • 建立時間: 2018-09-03
  • 更新時間: 2018-12-29

RSS訂閱

Open Toolbar
幸运飞艇 魔域私服 魔域私服 传世私服 魔域私服 热血江湖私服 魔域私服 魔域私服 传世私服 天龙八部私服