-
Notifications
You must be signed in to change notification settings - Fork 1
/
transaction.sv
125 lines (107 loc) · 4.24 KB
/
transaction.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/* MIT License
Copyright (c) 2020 Rishav Kumar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
import uvm_pkg::*;
class transaction extends uvm_sequence_item;
`uvm_object_utils(transaction)
// Inputs to DUT
rand logic [7:0] OPA, OPB;
rand logic cin, mode, ce;
rand logic [3:0] cmd;
constraint cmd_val {
if (mode == 1)
cmd inside { [0:9] };
else
cmd inside { [0:13] };
};
constraint ce_dist { ce dist { 1 := 9, 0 := 1 }; }
// Ouput from DUT
logic [2:0] egl;
logic [8:0] res;
logic cout, err, oflow;
static bit [7:0] trans_ID; // Transaction ID
static bit isRandom; // Control bit
function new(string name = "trans");
super.new(name);
init_val();
endfunction //new()
function void pre_randomize();
trans_ID++;
endfunction
// Helper functions
function void init_val();
OPA = 'z;
OPB = 'z;
cin = 'z;
cmd = 'z;
ce = 'z;
//r_bit = 'z;
mode = 'z;
egl = 'z;
res = 'z;
cout = 'z;
err = 'z;
oflow = 'z;
endfunction
function void do_print(uvm_printer printer);
$display("Transaction ID: %0d", trans_ID);
printer.print_field("OPA", OPA, 8, UVM_UNSIGNED);
printer.print_field("OPB", OPB, 8, UVM_UNSIGNED);
printer.print_field("Mode", mode, 1, UVM_BIN);
printer.print_field("CMD", cmd, 4, UVM_BIN);
printer.print_field("CE", ce, 1, UVM_BIN);
printer.print_field("Result", res, 9, UVM_UNSIGNED);
printer.print_field("cout", cout, 1, UVM_BIN);
printer.print_field("err", err, 1, UVM_BIN);
printer.print_field("oflow", oflow, 1, UVM_BIN);
printer.print_field("EGL", egl, 3, UVM_BIN);
endfunction
function string convert2string();
string s;
s = $sformatf("Packet ID: %0d", trans_ID);
s = $sformatf("%s\nInput: OPA = %b, OPB = %b, cin = %b, cmd = %b, mode = %b, ce = %b, ",
s, OPA, OPB, cin, cmd, mode, ce);
s = $sformatf("%s\nOuput: result = %b, cout = %b, err = %b, oflow = %b, EGL = %b",
s, res, cout, err, oflow, egl);
return s;
endfunction
function bit do_compare(uvm_object rhs, uvm_comparer comparer);
transaction _rhs;
bit cmp;
if(!$cast(_rhs, rhs))
`uvm_fatal(get_type_name(), "object passed is not compatible with Transaction");
cmp = this.egl === _rhs.egl & this.res === _rhs.res & cout === _rhs.cout
& err === _rhs.err & oflow === _rhs.oflow;
return cmp;
endfunction
function void do_copy(uvm_object rhs);
transaction _rhs;
if(!$cast(_rhs, rhs))
`uvm_fatal(get_type_name(), "rhs is not compatible with this class");
OPA = _rhs.OPA;
OPB = _rhs.OPB;
cin = _rhs.cin;
cmd = _rhs.cmd;
ce = _rhs.ce;
mode = _rhs.mode;
egl = _rhs.egl;
res = _rhs.res;
cout = _rhs.cout;
err = _rhs.err;
oflow = _rhs.oflow;
endfunction
endclass //transaction extends uvm_sequence_item