How to pass the enum data type as argument in embedded covergroup(Here i want take the enum data type as a multiple type)?Explain with some example.
// Purpose: Pass enum as a argument in embedded covergroup
module top;
typedef enum bit [1:0] {zero, one, two, three} one_four;
class xyz;
bit m_z;
int m_y;
bit m_x;
covergroup cov1 (ref one_four e) @m_z; // embedded covergroup
coverpoint m_x;
coverpoint m_y;
coverpoint e;
endgroup
function new(ref one_four e_new);
cov1 = new(e_new);
endfunction
endclass
initial
begin
xyz xyz_c;
one_four e_change;
xyz_c = new(e_change);
// Stimulus
e_change = three;
xyz_c.m_x = 1'b1;
xyz_c.m_y = 15;
xyz_c.m_z = 1'b1;
e_change = one;
xyz_c.m_z = 1'b0;
end
endmodule // top
Thanks for reply.
But i want to access the enum data type like this but i m getting error…plz guide me.
typedef enum bit [1:0] {zero, one, two, three} one_four;
covergroup cov1 (ref bit m_x,ref int m_y,ref one_four e); // embedded covergroup
coverpoint m_x;
coverpoint m_y;
coverpoint e;
endgroup
class xyz;
int m_y;
bit m_x;
typedef enum bit [1:0] {zero, one, two, three} one_four;
one_four e;
cov1 cov;
function new();
cov = new(m_x,m_y,e);
endfunction
endclass
I am getting following error:
Error-[IRPC] Illegal ref port connection
ex7.sv, 17
$unit, "this.e"
Illegal connection to the ref port 'e' of function/task 'cov1::new',formal
argument should have same type as actual argument.
The problem is that you are defining the enumeration one_four twice, once before the covergroup and again inside the class. This results in two distinct definitions which are not type compatible.
Remove the typedef from within the class.
thanks cgales…its work fine now.
Yet i have another question:
I want to give value(Or I want take value of RTL signal to directly coverpoint of covergroup) to coverpoint of embedded covergroup,So it is possible???For Following code i am geting error
typedef enum {zero, one, two, three} one_four;
covergroup cov1 (ref int m_x,ref int m_y,ref one_four e); // embedded covergroup
coverpoint m_x;
coverpoint m_y;
coverpoint e;
endgroup
class xyz;
int m_y[20];
int m_x[20];
one_four e[20];
cov1 cov[20];
function new();
foreach(cov[i]) begin
cov[i]=new(m_x[i],m_y[i],e[i]);
cov[i].sample();
end
endfunction
task sampling();
begin
cov[0].m_x[0]=2;
cov[0].m_y[0]=5;
cov[0].e[0]=one;
end
endtask
endclass
Warning-[INAV] Index into non-array variable
ex7.sv, 24
"this.cov[0].m_x_cp[0]"
Bit/Part-select specified for non array variable in module '$unit'.
Error-[TCF-IOTO] Illegal operator applied to object
ex7.sv, 24
"this.cov[0].m_x_cp[0]"
The Select operator cannot be applied to an object of this type.
Warning-[INAV] Index into non-array variable
ex7.sv, 25
"this.cov[0].m_y_cp[0]"
Bit/Part-select specified for non array variable in module '$unit'.
Error-[TCF-IOTO] Illegal operator applied to object
ex7.sv, 25
"this.cov[0].m_y_cp[0]"
The Select operator cannot be applied to an object of this type.
Warning-[INAV] Index into non-array variable
ex7.sv, 26
"this.cov[0].e_cp[0]"
Bit/Part-select specified for non array variable in module '$unit'.
Error-[TCF-IOTO] Illegal operator applied to object
ex7.sv, 26
"this.cov[0].e_cp[0]"
The Select operator cannot be applied to an object of this type.
3 warnings
3 errors
CPU time: .042 seconds to compile
In the sampling task, you don’t want to assign the variables in the covergroup instance. You only want to assign values to the variables which are referenced by the covergroup instance.
task sampling();
begin
m_x[0]=2;
m_y[0]=5;
e[0]=one;
end
endtask
Its Working fine…Thanks Cgales
Now In following code i am accesing RTL signal to m_x[0],m_y[0] but its showing warning.
typedef enum {zero, one, two, three} one_four;
covergroup cov1 (ref int m_x,ref int m_y,ref one_four e); // embedded covergroup
coverpoint m_x;
coverpoint m_y;
coverpoint e;
endgroup
typedef class sae_cfg;
class xyz;
sae_cfg cfg;
int m_y[20];
int m_x[20];
one_four e[20];
cov1 cov[20];
function new();
foreach(cov[i]) begin
cov[i]=new(m_x[i],m_y[i],e[i]);
cov[i].sample();
end
endfunction
task sampling(sae_cfg cfg);
begin
m_x[0]=system.dut.block1.cnt[10:0]; //line 1
m_y[0]=system.dut.block1.cnt2[6:0]; //line 2
e[0]=system.dut.block1.state[3:0]; //line 3
m_x[1]=cfg.valid_cnt; //line 4
m_y[1]=cfg.invld_cnt; //line 5
e[1]=cfg.state; //line 6
end
endtask
endclass
Warning-[ENUMASSIGN] Illegal assignment to enum variable //This error at line 3
"this. = system.dut.block1.state[3:0];"
Only expressions of the enum type can be assigned to an enum variable.
The type reg [3:0] is incompatible with the enum 'state'
Expression:
system.dut.block1.state[3:0]
Use the static cast operator to convert the expression to enum type.
Error-[ENUMASSIGNTYPE] Different enum types in assignment //This error a line 6
Different enum types in assignment statement
Cannot assign a value of type 'sae_cfg::mode_e' to a variable of type
'LIB_CHIP_B0.$unit::mode_e'
Source info: this.mode = cfg.mode;
Use the static cast operator to convert the expression to the required enum
type.
Error-[ICTA] Incompatible complex type //This error at line 6
Incompatible complex type assignment
Type of source expression is incompatible with type of target expression.
Mismatching types cannot be used in assignments, initializations and
instantiations. The type of the target is 'enum $unit::mode_e', while the
type of the source is 'enum $unit::sae_cfg::mode_e'.
Source Expression: cfg.mode
You are getting warnings because your code isn’t LRM compliant:
6.19.3 Type checking
Enumerated types are strongly typed; thus, a variable of type enum cannot be directly assigned a value that lies outside the enumeration set unless an explicit cast is used or unless the enum variable is a member of a union. This is a powerful type-checking aid, which prevents users from accidentally assigning nonexistent values to variables of an enumerated type.
Thanks cgales its work for me.
typedef enum {zero, one, two, three} one_four;
covergroup cov1 (ref int m_x,ref int m_y,ref one_four e); // embedded covergroup
coverpoint m_x;
coverpoint m_y;
coverpoint e;
endgroup
typedef class sae_cfg;
class xyz;
sae_cfg cfg;
int m_y[20];
int m_x[20];
one_four e[20];
cov1 cov[20];
function new();
foreach(cov[i]) cov[i]=new(m_x[i],m_y[i],e[i]);
endfunction
task sampling(sae_cfg cfg);
begin
m_x[0]=system.dut.block1.cnt[10:0]; //line 1
m_y[0]=system.dut.block1.cnt2[6:0]; //line 2
e[0]=system.dut.block1.state[3:0]; //line 3
m_x[1]=cfg.valid_cnt; //line 4
m_y[1]=cfg.invld_cnt; //line 5
e[1]=one_four'(cfg.state); //line 6
foreach(cov[i]) cov[i].sample();
end
endtask
endclass
For above code i getting covergroup with “0” score…means sampling is not done…can anyone suggest me where i have to use sample method for sampling the RTL siganl value in my muliple covergroup instance’s coverpoint ???