transaction模块
🧨

transaction模块

Created
Jul 31, 2024 03:32 PM
Tags
`ifndef TRANSACTION `define TRANSACTION class transaction; rand bit[7:0] A; rand bit[7:0] B; rand operation_t op; bit[15:0] result; constraint opcode_c {op dist {no_op := 1, add_op:= 5, and_op:=5, xor_op:=5,mul_op:=5,div_op:=5, rst_op:=1};} constraint oprand_c { A dist {8'h00:=1, [8'h01 : 8'hFE]:=1, 8'hFF:=1}; B dist {8'h00:=1, [8'h01 : 8'hFE]:=1, 8'hFF:=1};} function bit compare(transaction tr); bit same; if(tr == null)begin same = 0; $display("%0t -> transaction : ERROR -> tr is null",$time); end else if((this.A == tr.A) && (this.B == tr.B) && (this.op == tr.op) && (this.result == tr.result)) same = 1; else same = 0; return same; endfunction function string convert2string_in(); string s; s = $sformatf("A: %2h B: %2h op: %s", A, B, op.name()); return s; endfunction function string convert2string(); string s; s = $sformatf("A: %2h B: %2h op: %s = %4h", A, B, op.name(), result); return s; endfunction function transaction clone(); clone = new(); clone.A = this.A; clone.B = this.B; clone.op = this.op; clone.result = this.result; return clone; endfunction endclass `endif
负责产生操作数(A、B)和操作类型(op),然后发送给DUT。
sv一共发送多少个会根据generator来决定,在实际的项目中,generator使用repeat重复了400次,会发送400个事务。