Hi,
Inside a verification driver I want to randomize the value of the address, opcode and opcode_size when req and grant are low (no valid access)
Here is my code:
typedef enum logic [5:0] {LOAD ='b000001, STORE ='b000010, INVAL ='b111000, PURGE ='b001000, .... } opcode_t;
...
while ((req == 0) || (grant == 0))
begin
@(posedge clock)
vif.addr <= $urandom_range(32'hffffffff, 0);
vif.opcode <= $urandom_range(16, 0);
vif.opcode_size <= $urandom_range(16, 0);
end
However I am struggling to pick a random value for opcode
Here is what I have tried so far:
-
vif.opcode <= $urandom_range(1,0) ? opcode.last : opcode.first;
Compile OK … but restricted to two values of opcode -
vif.opcode <= opcode[ $urandom_range(opcode.num - 1,0) ];
An enum variable ‘vif.opcode’ may only be assigned the same enum typed variable or one of its values. Value ‘vif.opcode[$urandom_range(opcode.num()-1,0)]’ requires an explicit cast. -
vif.opcode <= opcode[ 1 ];
An enum variable ‘vif.opcode’ may only be assigned the same enum typed variable or one of its values. Value ‘opcode[1]’ requires an explicit cast. -
vif.opcode <= opcode.randomize();
** Fatal: (SIGSEGV) Bad handle or reference. -
vif.opcode <= $cast( opcode, 1);
An enum variable ‘vif.opcode’ may only be assigned the same enum typed variable or one of its values. Value ‘$cast(,1)’ requires an explicit cast. -
vif.opcode <= vif.opcode’( $urandom_range(opcode.num() - 1, 0) );
Error: Width cast must be constant.
- What am I doing wrong ?
- How can I randomize opcode I am stuck ! Any ideas ?
Thank you