Suppose I have a 4 port device. Each port in the device has a register object. I want to write a functional coverage model to make sure that I test the registers in each port. I write the following code:
covergroup cg;
myreg_port_0: coverpoint top_reg_obj.port[0].myreg;
myreg_port_1: coverpoint top_reg_obj.port[1].myreg;
myreg_port_2: coverpoint top_reg_obj.port[2].myreg;
myreg_port_3: coverpoint top_reg_obj.port[3].myreg;
endgroup
However, this is not reusable. The next chip planned is an 8-port device. I have to manually modify this coverage model each time the number of ports change. I would like to write the coverpoints using a for-loop to iterate over all the ports.
What is the best way to do this? It doesn't seem possible to use "for" or "foreach" inside a covergroup.
Thanks in advance.