ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

uvm callback and reg backdoor access callback

2022-08-31 01:02:01  阅读:229  来源: 互联网

标签:backdoor driver access callback user reg uvm


uvm callback and reg backdoor access callback

using uvm_callback class

Linux上写的,没有中文输入法,也不翻译了,留个档。
there are 4 main steps to using uvm_callback class to implement callback function.

  • extend callback class from uvm_callback class, and defined user callback class.
  • add register message(marcos) to the class who call the callback class method.
  • place the callback hook in the place you want to call.
  • In the test envrionment, create the callback class and add the callback information to the UVM.

here's the details.

extend user callback class from uvm_callback

class driver_callback extends uvm_callback;
	`uvm_object_utils(driver_callback)
	function new (string name = "driver_callback");
		super.new(name);
	endfunction
	virtual task user_drive_pre_cb;
	endtask
	virtual task user_drive_post_cb;
	endtask
endclass

class user_driver_callback extends driver_callback;
	`uvm_object_utils(user_driver_callback)
	function new (string name = "user_driver_callback");
		super.new(name);
	endfunction
	task user_drive_pre_cb;
		`uvm_info("callback", "here is the pre_cb called", UVM_LOW)
	endtask
	task user_drive_post_cb;
		`uvm_info("callback", "here is the post_cb called", UVM_LOW)
	endtask
endclass

place the callback hook in the place you want to call

    class user_driver extends uvm_driver #(uvm_sequence_item);
        ...
        `uvm_components_utils(user_driver)
        `uvm_register_cb(user_driver, driver_callback)
    endclass

add the callback marcos to the place you want to call

    class user_driver extends uvm_driver #(uvm_sequence_item);
        ...
        `uvm_components_utils(user_driver)
        `uvm_register_cb(user_driver, driver_callback)

        task run_phase(uvm_phase);
            `uvm_do_callbacks(user_driver, driver_callback, user_drive_pre_cb);
            do_run_phase_task();
            `uvm_do_callbacks(user_driver, driver_callback, user_drive_post_cb);
        endtask
    endclass

create callback class in test environment, and add to uvm environment

    class base_test extends uvm_test;
        user_driver_callback user_cb;
        ...

        function build_phase (uvm_phase phase);
            user_cb = user_driver_callback::create("user_cb");

            uvm_callbacks#(user_driver, driver_callback)::add(env.mst_agent.driver, user_cb);
        endfunction
    endclass

when have more than 1 callback class

when there are more than 1 callback class extends from driver_callback, the call marcos could call the callback methods multi times, the callback method execute order depends on the which object is using uvm_callbacks#(driver,driver_callback)::add add to envrionment first.

uvm register model backdoor access callback

background

I have a verification project which need to collect coverage of register value, so I create frontdoor_access uvm_event and backdoor_access uvm_event to sample data(actually, it could using the reg coverage of uvm register model, here is talking about another method). The front door event is easy to triggered, only triggering in the monitor getting the item on uvm_analysis_port. The backdoor_access event is hard to triggered, because such write()/read()/update()/mirror() methods, all of them could use backdoor path, so it is not possible to use pre_write()/pre_read() to trigger the backdoor_access event.

and here is the solution of using uvm_reg_cbs

about uvm_reg_cbs

uvm_reg_cbs derives from uvm_callback, so the major opeartion is same like part1, the first half of the article. here is the virtual method of uvm_callback.

  • pre_write()
  • post_write()
  • pre_read()
  • post_read()
  • post_predict()
  • encode()
  • decode()

we will use post_predict() to triggered the backdoor_access event.
why we use the post_predict()
post_predict will be called after a successful UVM_PREDICT_READ or UVM_PREDICT_WRITE prediction. And when we update the register model mirrored value by update()/read()/write(), it will call predict() method automatically, so we can use post_predict() to trigger backdoor_access event.

here's the details.

trig_reg_bd_access_cbs define

    class trig_reg_bd_access_cbs extends uvm_reg_cbs;
        `uvm_object_utils(trig_reg_bd_access_cbs)

        uvm_event bd_access_e;

        function new(string name = "trigger_reg_field_cbs");
            super.new(name);
        endfunction: new

        function void post_predict(input uvm_reg_field  fld,
                                    input uvm_reg_data_t previous,
                                    inout uvm_reg_data_t value,
                                    input uvm_predict_e  kind,
                                    input uvm_path_e     path,
                                    input uvm_reg_map    map);
        
        bd_access_e = uvm_event_pool::get_global("backdoor_access_event");
        bd_access_e.trigger(fld);
        endfunction
    endclass

instantiate callback class

    class test_base extends uvm_test;
        ...
        register_model rgm;
        trig_reg_bd_access_cbs reg_cbs;
        uvm_reg_field all_fields[$];

        function build_phase(uvm_phase);
            reg_cbs = trig_reg_bd_access_cbs::type_id::create("reg_cbs");
            rgm.get_fields(all_fields);
            foreach(all_fields[i])
                uvm_reg_filed_cb::add(all_fields, reg_cbs);
        endfunction
    endclass

get triggered data

the backdoor access can be successfully triggered, then you can set uvm_event to get the triggered data.

    class cov_model extends uvm_component;
    uvm_event bd_access_e;
    uvm_reg_field r;
    uvm_object tmp;

    task run_phase();
        forever begin
            bd_access_e = uvm_event_pool::get_global("backdoor_access_event");
            bd_access_e.wait_trigger(tmp);
            void'($cast(r, tmp));
            ...
        end
    endtask
    endclass

标签:backdoor,driver,access,callback,user,reg,uvm
来源: https://www.cnblogs.com/pu1se/p/16641498.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有