I’m looking for a way to extend the idea of parameterized interface.
I have agent+drive+monitor+seq with a virtual interface for data packets, where the virtual interface gets a parameter of data width that sets its fields (the driver instances the virtual interface inside it)
I would like to use those modules for 2 places in my environment in which there are different data width (the whole agent+driver(+vif) + monitor )
how can i send the virtual interface a parameter which is actually a variable ?
Here is my thought, please check if it will work to meet your needs?
Method 1:
Declare a local “data_width” variable in driver and monitor etc. components where the virtual interface instance declaration locates. Use uvm_config_db::get to get “data_width” value in these components and use uvm_config_db::set “data_width” value at environment level.
For example:
class my_driver extends uvm_driver #(my_seq_item);
protected int data_width = 32;
protected virtual my_interface #(data_width) my_vif;
//enable "data_width" variable field automation
`uvm_component_utils_begin(my_driver)
`uvm_field_int(data_width, UVM_ALL_ON)
`uvm_component_utils_end
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db#(int)::get(this, “”,"data_width",data_width))
`uvm_fatal("NODATAWIDTH", {"data_width must be set for: ", get_full_name(),".data_width"});
endfunction : build_phase
//...
endclass
class my_env extends uvm_env;
my_agent agent[2];
virtual function void build_phase(uvm_phase phase);
super.build_phase(phase);
uvm_config_db#(int)::set(this,".agent[0].*","data_width", 16);
uvm_config_db#(int)::set(this,".agent[1].*","data_width", 32);
// create agent[0], agent[1]...
endfunction : build_phase
//...
endclass
Method 2:
Implement the driver, monitor, agent etc. with “data_width” as parameter and take it as as virtual interface’s parameter as well. Then you can assign the specific data_width value when agent is instanced in the environment.
About method 1 - i doesn’t work, since as much as i know you can not create an interface with a non-constant value (the data_width) is a variable and not a constant and you get compilation error.
I guess i will use method 2.
Do you if there is any other way to make method 1 work ?
Hi,
how can i send the virtual interface a parameter which is actually a variable ?
Thanks !
A virtual interface can only be parameterized and a parameter cannot be a variable.
I do not understand why you want to use a variable.
If you want to use the same interface in your UVM environment in 2 different places with different data_with then you cane do this like this: