其他分享
首页 > 其他分享> > uvm callback and reg backdoor access callback

uvm callback and reg backdoor access callback

作者:互联网

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.

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.

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