Consider the example below
// File: rgb_coverage.sv
// Purpose: simple Experimental Example to show how to build more comptex
// coverage involving typedefs, arrays and emums.
// By: Thomas D. Tessier, t2design Inc.
typedef enum (TEXA, TEXB, TEXC, TEXD, TEXE, TEXF, TEXNONE} texture_enum_t;
typedef enum (ON, OFF, BLINK) feature_enum_t;
typedef enum (ENABLE, DISABLE} enable_enum_t;
typedef enum (FRONT, BACK) stage_enum_t;
typedef enum (RED, BLUE, GREEN) color_enum_t;
typedef bit [2:0] color_t;
typedef bit [4:0] width_t;
typedef bit [4:0] height_t;
typedef bit [3:0] depth_t;
const stage_enum_t stage_loops [stage_enum_t] = '(FRONT: FRONT, BACK: BACK};
const color_enum_t color_loops[color_enum_t] = '(RED: RED, BLUE: BLUE, GREEN: GREEN};
class pixel_t;
rand color_t pixel_color(stage_enum_t][color_enum_t];
rand width_t pixel_x[stage_enum_t];
rand height_t pixel_y[stage_enum_t];
rand depth_t pixel_z[stage_enum_t];
rand texture_enum_t pixel_texture[stage_enum_t];
rand feature_enum_t pixel_feature[stage_enum_t];
rand enable_enum_t pixel_visibility[stage_enum_t];
function new(string name="pixel_t");
foreach (stage_loops [stage]) begin
pixel_x[stage] = 0;
pixel y[stage] = 0;
pixel_z[stage] = 0;
pixel_texture[stage] = TEXNONE;
pixel_feature[stage] = OFF;
pixel_visibility[stage] = DISABLE;
foreach (color_loops[color]) begin
pixel_color[stage][color] = 0;
end
end // foreach (stage_loops [stage])
endfunction // new
endclass // pixel_t
covergroup cg_pixel(string name) with function sample(pixel_t item, stage_enum_t stage, color_enum_t color):
option.per_instance = 1;
option.name = name;
ср_с: coverpoint item.pixel__color[stage][color];
cp_x:coverpoint item.pixel_x[stage] ;
ср_у: coverpoint item.pixel_y[stage];
cp_z: coverpoint item.pixel_z[stage];
cp_t:coverpoint item.pixel_texture[stage];
cp_f: coverpoint item.pixel_feature|stage];
cp_v: coverpoint item. pixel _visibility[stage];
// Simple cross with simple logical ignore_bin
cx_tfv: cross cp_t, cp_f, cp_v {
ignore_bins not_visible = cx_tfv with (cp_v = DISABLE || cp_t = TEXNONE || cp_f == OFF);
}
endgroup // cg pixel
class pixel_coverage_wrapper;
// how to get around arrays of embedded covergroups
cg_pixel mycg_pixel[state_enum_t][color_enum_t];
function new();
foreach (stage_loops[stage]) foreach (color_loops[color]) begin
mycg_pixel[stage][color] = new($sformatf("mycg_pixel[%p][%p]_inside_wrapper", stage, color));
end
endfunction // new
function void sample(pixel_t pixel);
foreach (stage_loops[stage]) foreach (color_loops[color]) begin
mycg_pixel[stage][color].sample(pixel, stage, color);
end
endfunction // sample
endclass // pixel_coverage_wrapper
class pixel_coverage_t;
pixel_coverage_wrapper pcw;
function new();
pcw = new();
endfunction // new
function void write(pixel_t pixel);
pcw.sample(pixel);
endfunction // write
endclass // pixel_coverage_t
module top;
pixel_coverage_t the_coverage = new();
pixel_t the_pixel;
initial begin
the_pixel = new();
for (int i = 0; i < 10; i++) begin
assert (the_pixel.randoize ());
the_coverage.write(the_pixel);
end
end
endmodule // top
// end of file
Lets say I want to answer the question: Did I hit these key colors: Black (0,0,0), White (7,7,7), Red (7,0,0), Lime (0,7,0) and Blue (0,0,7). We might also want to cross these colors with Blinking as well.
Now I know we could change the “pixel_t” class to organize the data differently, I cannot do that for the problem I am trying to solve. I just have to build coverage for this data object. Now this is a small example my actual design contains 100K space of which I am looking for like 2000 datapoints. I am trying to figure out how to write functions or macros to help me program up the coverage bins and model.
Thanks in advance for considering.
TomT…