Callback function does not work

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

In reply to UVM_LOVE:

Without going into the details. The uvm_callback is an extension of uvM-object.
The test cannot be extended from an uvm_object it is a uvm_component.

In reply to chr_sue:

In reply to UVM_LOVE:
Without going into the details. The uvm_callback is an extension of uvM-object.
The test cannot be extended from an uvm_object it is a uvm_component.

I also confused it.
I agree on your reply, But My reference code was used with uvm_object.

In reply to UVM_LOVE:

uvm_callback is an extension of uvm_object. But you are trying to use it as a component when extenting the callback to a test. The test has to be a component.

In reply to chr_sue:

In reply to UVM_LOVE:
uvm_callback is an extension of uvm_object. But you are trying to use it as a component when extenting the callback to a test. The test has to be a component.

But don’t know why it does not make an error.
There is no any Compile/Elaborate/Simulation Error messages and looks working good.
As you can see the reference code/site what I have linked even it was used in there as per object into component test class.

In reply to UVM_LOVE:

A compile or elaborate error happens only if there are syntax errors. It looks like your test has not been constructed because it is not a component.
I do not see how you are starting your test.

In reply to chr_sue:

In reply to UVM_LOVE:
A compile or elaborate error happens only if there are syntax errors. It looks like your test has not been constructed because it is not a component.
I do not see how you are starting your test.

Sir, I do start with run_test(“apb_basic_test”);
Object was constructed

cb_test1 = apb_cb_test1::type_id::create("cb_test1",this);

in test.

I’m so confused it.

In reply to UVM_LOVE:

You do not have to construct the test you want to run explicitely. It is doen automatically for you. But again this test is not a component. It does not belong to the topology of your testbench, but it should.
Without seeing more/all your code I cannot guide you.