Creating protocol transfers

Hi, Debjit

Here is an example below. You can see how parity is generated in the post_randomize function. Your concerns on HADDR in your situation is the same, I think.

// Parity Type Control knob
typedef enum bit {GOOD_PARITY, BAD_PARITY} parity_e;

class uart_frame extends uvm_sequence_item; //lab1_note1
// UART Frame
rand bit start_bit;
rand bit [7:0] payload;
bit parity;
rand bit [1:0] stop_bits;
rand bit [3:0] error_bits;

// Control Knobs
rand parity_e parity_type;
rand int transmit_delay;

// Default constraints //lab1_note2
constraint default_txmit_delay {transmit_delay >= 0; transmit_delay < 20;}
constraint default_start_bit { start_bit == 1’b0;}
constraint default_stop_bits { stop_bits == 2’b11;}
constraint default_parity_type { parity_type==GOOD_PARITY;}
constraint default_error_bits { error_bits == 4’b0000;}

// This method calculates the parity
function bit calc_parity(int unsigned num_of_data_bits=8,
bit[1:0] ParityMode=0);
bit temp_parity;

if (num_of_data_bits == 6)
  temp_parity = ^payload[5:0];  
else if (num_of_data_bits == 7)
  temp_parity = ^payload[6:0];  
else
  temp_parity = ^payload;  

case(ParityMode[0])
  0: temp_parity = ~temp_parity;
  1: temp_parity = temp_parity;
endcase
case(ParityMode[1])
  0: temp_parity = temp_parity;
  1: temp_parity = ~ParityMode[0];
endcase
if (parity_type == BAD_PARITY)
  calc_parity = ~temp_parity;
else 
  calc_parity = temp_parity;

endfunction

// Parity is calculated in the post_randomize() method //lab1_note5
function void post_randomize();
parity = calc_parity();
endfunction : post_randomize


Regards,
Yao he