-
Notifications
You must be signed in to change notification settings - Fork 0
/
tb_drv_seqr_mon.svh
executable file
·266 lines (212 loc) · 7.34 KB
/
tb_drv_seqr_mon.svh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
//-----------------------------------------------------------------------------------------------------------
// Class for sequencer. derived from base class uvm_sequencer.
// Parameterized to type transaction(sequence) :apb_rw. meaning the sequencer will
// pass the transaction(sequence) apb_rw onto the driver
// If a response is needed, a response sequence can also be parameterized
`include "../src/uvm_macros.svh"
//`include "tb_seq_item.svh"
`include "tb_sequence.svh"
import uvm_pkg::*;
// Memory array for internal storage.
//logic [7:0]memory[0:2047];
//logic [7:0] temp;
//===========================================================================
// Sequencer Class
class NF_sequencer extends uvm_sequencer #(NF_seq_item);
// class registration in uvm_factory
`uvm_object_utils(NF_sequencer)
// Constructor class
function new(string name = "NF_sequencer");
super.new(name);
endfunction : new
endclass : NF_sequencer
//============================================================================
// Driver Class
class NF_driver extends uvm_driver#(NF_seq_item);
logic [7:0]memory[0:2047];
logic [7:0] temp;
// Class registration in uvm_factory
`uvm_component_utils(NF_driver)
// Since the driver interacts with the DUT via the interface, we need to create a
// virtual interface handle in the driver class
virtual flash_bfm vif;
// Constructor Class
function new(string name = "NF_driver", uvm_component parent = null);
super.new(name, parent);
endfunction : new
// Build Phase
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db#(virtual flash_bfm)::get(this, "", "vif",vif))
`uvm_fatal("NO_VIF", {"Virtual Interface must be set for:", get_full_name(), ".vif"});
endfunction : build_phase
// Run Phase
virtual task run_phase(uvm_phase phase);
forever begin
NF_seq_item tr;
@(this.vif.clk);
seq_item_port.get_next_item(tr);
$display("seq_id_cmd: %d", tr.seq_item_BF_nfc_cmd);
@(this.vif.clk);
case (tr.seq_item_BF_nfc_cmd)
3'b011 : reset();
3'b010 : read_cycle(tr.seq_item_RWA);
3'b110 : drive_reset();
3'b001 : drive_write(tr.seq_item_RWA);
3'b100 : erase_cycle(tr.seq_item_RWA);
3'b000 : stable();
endcase // tr.seq_item_BF_nfc_cmd
/* if(tr.seq_item_BF_nfc_cmd != 3'b110) begin
vif.BF_we = 1'b0;
wait(this.vif.nfc_done);
@(posedge vif.clk);
#3;
vif.nfc_cmd = 3'b111;
//read_buffer();
end
if(tr.seq_item_BF_nfc_cmd == 3'b010) begin
$display("inside READ BUFFER LOOP");
read_buffer();
end // if(tr.send_item_BF_nfc_cmd != 3'b010)
vif.BF_sel = 1'b0;
*/
seq_item_port.item_done();
end // forever
endtask : run_phase
virtual task read_buffer();
$display("INSIDE READ BUFFER");
@(posedge vif.clk);
wait(vif.nfc_done);
@(posedge vif.clk);
//#3;
vif.nfc_cmd=3'b111;
vif.BF_ad<= vif.BF_ad+1;
for(int i=0;i<2048;i=i+1)begin
@(posedge vif.clk);
temp<=memory[i];
vif.BF_ad<= vif.BF_ad+1;
end // for(i=0;i<2048;i=i+1)
if(vif.RErr)
$display($time," %m \t \t << ecc error >>");
else
$display($time," %m \t \t << ecc no error >>");
kill_time;
kill_time;
endtask : read_buffer
// Task for reset command
virtual task drive_reset();
vif.system_reset(2);
$display("RESET DONE");
kill_time;
kill_time;
//vif.send(3'b011, 16'h1234);
endtask : drive_reset
// Task for write command
virtual task drive_write(input logic [15:0] address);
$display("ENTERING WRITE, address: %h", address);
vif.send(3'b001, address);
for (int i = 0; i<2048; i++) begin
memory[i] = $random % 256;
vif.write_buffer(1'b1,memory[i],i);
end
@(posedge vif.clk) ;
@(posedge vif.clk) ;
//#3;
vif.BF_we=1'b0;
wait(vif.nfc_done);
@(posedge vif.clk) ;
//#3;
vif.nfc_cmd=3'b111;
vif.BF_sel=1'b0;
if(vif.PErr)
$display($time," %m \t \t << Writing error >>");
else
$display($time," %m \t \t << Writing no error >>");
kill_time;
kill_time;
endtask : drive_write
virtual task read_cycle(input logic [15:0]address);
$display("ENTERING READ CYCLE");
vif.send(3'b010,address);
read_buffer();
endtask
// Task for read command
virtual task reset();
begin
vif.send(3'b011, 16'h1234);
kill_time;
kill_time;
end
endtask : reset
task kill_time;
begin
@(posedge vif.clk);
@(posedge vif.clk);
@(posedge vif.clk);
@(posedge vif.clk);
@(posedge vif.clk);
end
endtask // of kill_time;
task erase_cycle(input logic [15:0]address);
begin
vif.send(3'b100,address);
if(vif.EErr)
$display($time," %m \t \t << erase error >>");
else
$display($time," %m \t \t << erase no error >>");
kill_time;
kill_time;
end
endtask : erase_cycle
task stable();
vif.rst = 1'b1;
vif.BF_sel = 1'b0;
vif.BF_ad = 0;
vif.BF_din = 0;
vif.BF_we = 0;
vif.RWA = 0;
vif.nfc_cmd = 3'b111;
vif.nfc_strt = 1'b0;
//temp = 8'b24;
kill_time;
kill_time;
vif.rst = 1'b0;
endtask : stable
endclass : NF_driver
//============================================================
class NF_monitor extends uvm_monitor;
// virtual interface
virtual flash_bfm vif;
uvm_analysis_port #(NF_seq_item) item_collected_port;
NF_seq_item trans_collected;
`uvm_component_utils(NF_monitor)
// constructor class
function new(string name, uvm_component parent);
super.new(name, parent);
trans_collected = new();
item_collected_port = new("item_collected_port", this);
endfunction : new
function void build_phase(uvm_phase phase);
super.build_phase(phase);
if(!uvm_config_db#(virtual flash_bfm)::get(this, "", "vif", vif))
`uvm_fatal("NOVIF",{"Virtual interface must be set for: ", get_full_name(), ".vif"});
endfunction
// run phase
virtual task run_phase(uvm_phase phase);
forever begin
@(negedge vif.clk);
//$display("-----Inside monitor-----1");
//if(vif.nfc_strt)begin
// $display("-----Inside monitor-----2");
if((vif.nfc_cmd == 3'b001) && (vif.BF_we))begin
// trans_collected.seq_item_BF_nfc_cmd = 3'b001;//vif.nfc_cmd;
trans_collected.seq_item_RWA = vif.RWA;
trans_collected.seq_item_BF_ad = vif.BF_ad;
//$display("vif.nfc_cmd :, RWA: %h", vif.RWA);
trans_collected.seq_item_BF_din = vif.BF_din;
// $display("DATA WRITE::: seq_item_BF_ad : %h , trans_collected.seq_item_BF_din : %h",trans_collected.seq_item_BF_ad, trans_collected.seq_item_BF_din);
end // if(vif.nfc_strt)end
item_collected_port.write(trans_collected);
end // forever
endtask : run_phase
endclass : NF_monitor