In reply to Jay Maradia:
Your question is not clear what you mean by “field”. Did you mean to say your sequence_item has a field that could take on the list of possible states: START, DATA, …, IDLE? And you need to send these items serially to your driver? Or did you need to create a dynamic array of fields, with the first element having the START value, then you send the array to the driver? Some code that showed what your sequence_item looks like would help.
It’s possible to have constraints that look at the previous value to constrain the new value, but it might be simpler to simple coerce the values directly.
Since constraints do not support don’t-care values, you have to use a bit mask to specify which bits are random and which bits need a specific value. For example suppose you had 16’h?A?B, then you need a constraint
constraint C { (random_variable & 16'h0F0F) == 16'h0A0B; }
The bits are masked out with 0 become don’t cares.
Here is what I came up with based on the information you gave
module top;
class A;
rand bit [65:0] field;
typedef enum bit [65:0] {START=66'h1234, DATA=66'h4567, TERM=66'h0,SOS=66'hABCD, ECB=66'hBEEF, IDLE=66'hDEAD} command_t;
typedef enum bit [65:0] {TERM0, TERM1, TERM2, TERM3, TERM4, TERM5, TERM6, TERM7} term_t;
rand command_t command;
rand term_t term;
const bit [65:0] pattern_mask[term_t] = '{
TERM0: {2'h3, 8'hFF, { 7{1'b0}}, 7'h3F, {42{1'b0}}},
TERM1: {2'h3, 8'hFF, { 8{1'b0}}, {6{1'b0}}, 7'h3F, {35{1'b0}}},
TERM2: {2'h3, 8'hFF, {16{1'b0}}, {5{1'b0}}, 7'h3F, {28{1'b0}}},
TERM3: {2'h3, 8'hFF, {24{1'b0}}, {4{1'b0}}, 7'h3F, {21{1'b0}}},
TERM4: {2'h3, 8'hFF, {32{1'b0}}, {3{1'b0}}, 7'h3F, {14{1'b0}}},
TERM5: {2'h3, 8'hFF, {40{1'b0}}, {2{1'b0}}, 7'h3F, {7{1'b0}}},
TERM6: {2'h3, 8'hFF, {48{1'b0}}, {1{1'b0}}, 7'h3F},
TERM7: {2'h3, 8'hFF, {56{1'b0}}} };
const bit [65:0] pattern_data[term_t] = '{
TERM0: {2'h2, 8'he1, { 7{1'b0}}, 7'b0, {42{1'b0}}},
TERM1: {2'h2, 8'h99, { 8{1'b0}}, {6{1'b0}}, 7'b0, {35{1'b0}}},
TERM2: {2'h2, 8'h55, {16{1'b0}}, {5{1'b0}}, 7'b0, {28{1'b0}}},
TERM3: {2'h2, 8'h2d, {24{1'b0}}, {4{1'b0}}, 7'b0, {21{1'b0}}},
TERM4: {2'h2, 8'h33, {32{1'b0}}, {3{1'b0}}, 7'b0, {14{1'b0}}},
TERM5: {2'h2, 8'h4b, {40{1'b0}}, {2{1'b0}}, 7'b0, {7{1'b0}}},
TERM6: {2'h2, 8'h87, {48{1'b0}}, {1{1'b0}}, 7'b0},
TERM7: {2'h2, 8'hFF, {56{1'b0}}} };
constraint c {
command != TERM -> field == command;
command == TERM -> (field & pattern_mask[term]) == pattern_data[term];
solve command, term before field; } // improve distribution
endclass
A a = new;
initial repeat (50) begin
assert (a.randomize);
$displayh(a.field,, a.command.name,,a.term.name);
end
endmodule