I have 2 heterogenous cores which utilise the same tb environment. Hence I have created 2 instances of coverage class. However I need to create & sample covergroup based on the core. How can I do so?
I have tried this, however getting error that sample() function can only be called on covergroup instances created.
class my_agent extends uvm_agent;
cov_collector[NUM_CORES];
function void build phase(uvm_phase phase);
super.build_phase(phase);
for(int i=0;i<NUM_CORES; i++)
begin
cov_collector=my_cov_collector::type_id::create($psprintf("cov_collector[%0d]",i),this);
cov_collector.core=i;
end
endfunction
class my_cov_collector extends uvm_monitor;
int core;
covergroup core0;
endgroup
covergroup core1;
endgroup
function new();
super.new();
if(core==0) begin core0=new(); end
if(core==1) begin core1=new(); end
endfunction
task sample();
if(core==0) begin core0.sample(); end
if(core==1) begin core1.sample(); end
endtask
It seems to me that issue is core variable is being assigned value in build phase. However new function is invoked before that & it considers default value of core as 0 & hence only creates core0 covergroups in both instances.
Could anyone suggest a solution?
The issue you're facing is related to the fact that the new() function is being called before the core variable is assigned a value in the build_phase. To address this, you should initialize the core variable in the new() function itself.
Here's a modified version of your code:
In this the core variable is initialized with its default value in the new() function. Later, during the build_phase, you update the core0 and core1 covergroups based on the value of the core variable. This should resolve the issue you were facing.