Dear All,
I’m trying to make an callback function in UVM.
I was made a simple callback which is a function will be called by data width set once such as “apb_cb.set_data_width(2);”
and I expected that “MY_CALLBACK_TEST1 !!” message will print. But nothing do anything.
How do I print my callback function message which is “MY_CALLBACK_TEST1 !!”?
types.sv
typedef class apb_when_callback_will_be_called;
typedef class apb_base_callback;
typedef uvm_callbacks#(apb_when_callback_will_be_called ,apb_base_callback) my_cb_pool;
apb_basic_test.sv
class apb_basic_test extends uvm_test;
int packets;
`uvm_component_utils_begin(apb_basic_test)
`uvm_field_int(packets,UVM_ALL_ON)
`uvm_component_utils_end
apb_master_environment apb_environment;//evironment handle
apb_sequence seq;//sequence handle
apb_when_callback_will_be_called apb_cb;
apb_cb_test1 cb_test1;
function new(string name="apb_basic_test", uvm_component parent);
super.new(name,parent);
`uvm_info(get_type_name(),"the objection test object has been built",UVM_LOW);
endfunction
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db#(int)::get(this,"","number_of_packets",packets))
`uvm_info(get_type_name(),"the geting of packets variable failed",UVM_LOW)
apb_environment = apb_master_environment::type_id::create("apb_environment",this);
seq = apb_sequence::type_id::create("seq", this);
cb_test1 = apb_cb_test1::type_id::create("cb_test1",this);
apb_cb = apb_when_callback_will_be_called::type_id::create("apb_cb", this);
my_cb_pool::add(apb_cb, cb_test1);
endfunction
virtual function void connect_phase(uvm_phase phase);
seq.packets = packets;
`uvm_info(get_type_name(),"the connect phase of the basic_test completed", UVM_LOW)
endfunction
virtual task run_phase(uvm_phase phase);
super.run_phase(phase);
phase.raise_objection(this);//raise objection
// im changing here..........
// vsequence.start(null);
seq.start(apb_environment.apb_agent.sequencer);
apb_cb.set_data_width(2);
phase.drop_objection(this);//drop objection
endtask
endclass
apb_cb_test1.sv
class apb_cb_test1 extends apb_base_callback;
`uvm_object_utils(apb_cb_test1)
function new(string name ="");
super.new(name);
endfunction
virtual function void my_apb_base_width_changed(int old_width, int new_width);
`uvm_info(get_type_name(), "MY_CALLBACK_TEST1 !!",UVM_LOW)
endfunction
endclass
apb_base_callback.sv
class apb_base_callback extends uvm_callback;
`uvm_object_utils(apb_base_callback)
// No Need to Virtual
function new (string name ="");
super.new(name);
endfunction
virtual function void my_apb_base_width_changed(int old_width, int new_width);
endfunction
endclass
callback_will_be_called.sv
class apb_when_callback_will_be_called extends uvm_component;
`uvm_component_utils(apb_when_callback_will_be_called)
int width;
`uvm_register_cb(apb_when_callback_will_be_called, apb_base_callback)
function new(string name = "", uvm_component parent);
super.new(name, parent);
endfunction
function void set_data_width(int width);
`uvm_do_callbacks(apb_when_callback_will_be_called,apb_base_callback,
my_apb_base_width_changed( this.width, width) );
this.width = width;
endfunction
endclass