ee_king的个人空间 https://blog.eetop.cn/1494617 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

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

已有 1176 次阅读| 2018-12-28 15:08 |系统分类:芯片设计

   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

       (在http://verificationacademy.com/uvm-ovm上在线下载源代码示例)。


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 2

    粉丝
  • 0

    好友
  • 0

    获赞
  • 6

    评论
  • 访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-20 17:31 , Processed in 0.029046 second(s), 18 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部