itsmyturn Posted June 6, 2012 Report Share Posted June 6, 2012 My code for the driver's connect phase is shown below. I'm creating a simple VIF container object and setting it as a DB object. When I try to retrive it from the driver, I do get the object, but it seems to be of a different type, and my simulation fails at the casting step in the driver. Can someone help me with this. This is my first attempt with UVM. So, it might be a very simple mistake. Any help in this regard is appreciated. I have an initial block in my TB that does something like initial begin typedef myvif_container #(virtual myInterface) myvif_container_t; myvif_container_t myvif_container_h; myvif_container_h = myvif_container_t::type_id::create("myvif_container_h"); set_config_object("*.*driver", "myvif_container", myvif_container_h); .... end function void connect(); uvm_object tmp; typedef myvif_container #(virtual myInterface) myvif_container_t; myvif_container_t myvif_container_h; if (!(get_config_object("myvif_container", tmp))) begin `uvm_fatal(get_type_name(), "VIF container not found") end if (tmp == null) begin `uvm_fatal(get_type_name(), "VIF container is null"); end if (!($cast(myvif_container_h, tmp))) begin `uvm_info(get_type_name(), $psprintf ("container type is %s", tmp.get_type_name()), UVM_NONE); `uvm_fatal(get_type_name(), "Interface container different type") end endfunction : connect class myvif_container #(type VIF=int) extends uvm_object; `uvm_object_param_utils (myvif_container #(VIF)) VIF m_vif_h; function new (string name="vif_container"); super.new(name); endfunction : new endclass : myvif_container Quote Link to comment Share on other sites More sharing options...
dave_59 Posted June 6, 2012 Report Share Posted June 6, 2012 There is no need for a vif container in UVM. You can use the uvm_config_db directly. uvm_config_db #(virtual myinterface)::set(null, "uvm_test_top", "my_vif", myifinstance); See http://verificationacademy.com/uvm-ovm/Config/VirtInterfaceConfigDb more complete examples. Quote Link to comment Share on other sites More sharing options...
itsmyturn Posted June 7, 2012 Author Report Share Posted June 7, 2012 Dave, thank you so much for the prompt reply. It did the trick. I hate to say that I spent a couple of hours fighting with that casting issue. I still don't understand why that didn't work. Can you think of a reason why that casting didn't work? Thanks Quote Link to comment Share on other sites More sharing options...
amitrana Posted June 7, 2012 Report Share Posted June 7, 2012 HI , Casting can be done from a child to parent class. Forexample, class A; endclass class B extends A; endclass module top; A a; B b; initial begin b=new(); void'($cast(a,); endmodule But in your case you are doing reverse from parent to child ,that's an error. end Quote Link to comment Share on other sites More sharing options...
pjigar Posted June 7, 2012 Report Share Posted June 7, 2012 To further safeguard you with typos in the get(), you can also create a typedef for uvm_config_db parametrized with a specific interface type. e.g. In uvm_pkg: typedef uvm_config_db #(virtual myinterface) myinterface_config_db; In module testbench: myinterface_config_db::set(null, "*.tb.uvc.agent.*", "vif", my_if_inst); And in the driver: myinterface_config_db::get(this, "", "vif", myifinstance); -Jigar Quote Link to comment Share on other sites More sharing options...
itsmyturn Posted June 7, 2012 Author Report Share Posted June 7, 2012 Looks like I landed in the right place. Thank you all for the replies. They're quite helpful. Quote Link to comment Share on other sites More sharing options...
uwes Posted June 12, 2012 Report Share Posted June 12, 2012 HI , Casting can be done from a child to parent class. hi, you dont need to cast from child to parent at all since a derived is always a base. you can directly assign a derived class handle to a base class handle. the reverse is not always true therefore you need to check at runtime. HI ,But in your case you are doing reverse from parent to child ,that's an error. not necessarily, have a look at the attached code module test193; virtual class car; endclass class mercedes extends car; endclass class renault extends car; endclass car c; mercedes m; renault r; initial begin m=new(); // this is not needed since a "mercedes" is always a "car" void'($cast(c,m)); // do the previous the simple way c=m; // the reverse needs a cast since a "car" is not necessarily a "mercedes" r = new(); c=r; assert($cast(m,c)); //this should fail c=m; assert($cast(m,c)); // this should pass end endmodule Quote Link to comment Share on other sites More sharing options...
itsmyturn Posted June 12, 2012 Author Report Share Posted June 12, 2012 hi, you dont need to cast from child to parent at all since a derived is always a base. you can directly assign a derived class handle to a base class handle. the reverse is not always true therefore you need to check at runtime. not necessarily, have a look at the attached code module test193; virtual class car; endclass class mercedes extends car; endclass class renault extends car; endclass car c; mercedes m; renault r; initial begin m=new(); // this is not needed since a "mercedes" is always a "car" void'($cast(c,m)); // do the previous the simple way c=m; // the reverse needs a cast since a "car" is not necessarily a "mercedes" r = new(); c=r; assert($cast(m,c)); //this should fail c=m; assert($cast(m,c)); // this should pass end endmodule Even I doubted whether amitrana's comments were correct, as I saw uvm_object type objects being casted to VIF container objects everywhere in the UVM manuals/books. But, I wasn't quite sure if I was in a place to comment. Anyway, thanks for the detailed explanation. I didn't know that a derived guy can be assigned to base class handle directly. Thanks again. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.