1 |
16 |
HanySalah |
//------------------------------------------------------------------------------
|
2 |
|
|
// Copyright 2007-2011 Mentor Graphics Corporation
|
3 |
|
|
// Copyright 2007-2011 Cadence Design Systems, Inc.
|
4 |
|
|
// Copyright 2010-2011 Synopsys, Inc.
|
5 |
|
|
// All Rights Reserved Worldwide
|
6 |
|
|
//
|
7 |
|
|
// Licensed under the Apache License, Version 2.0 (the
|
8 |
|
|
// "License"); you may not use this file except in
|
9 |
|
|
// compliance with the License. You may obtain a copy of
|
10 |
|
|
// the License at
|
11 |
|
|
//
|
12 |
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
13 |
|
|
//
|
14 |
|
|
// Unless required by applicable law or agreed to in
|
15 |
|
|
// writing, software distributed under the License is
|
16 |
|
|
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
17 |
|
|
// CONDITIONS OF ANY KIND, either express or implied. See
|
18 |
|
|
// the License for the specific language governing
|
19 |
|
|
// permissions and limitations under the License.
|
20 |
|
|
//------------------------------------------------------------------------------
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
//------------------------------------------------------------------------------
|
24 |
|
|
//
|
25 |
|
|
// CLASS: uvm_sequencer_param_base #(REQ,RSP)
|
26 |
|
|
//
|
27 |
|
|
// Extends with an API depending on specific
|
28 |
|
|
// request (REQ) and response (RSP) types.
|
29 |
|
|
//------------------------------------------------------------------------------
|
30 |
|
|
|
31 |
|
|
class uvm_sequencer_param_base #(type REQ = uvm_sequence_item,
|
32 |
|
|
type RSP = REQ) extends uvm_sequencer_base;
|
33 |
|
|
|
34 |
|
|
typedef uvm_sequencer_param_base #( REQ , RSP) this_type;
|
35 |
|
|
typedef REQ req_type;
|
36 |
|
|
typedef RSP rsp_type;
|
37 |
|
|
|
38 |
|
|
REQ m_last_req_buffer[$];
|
39 |
|
|
RSP m_last_rsp_buffer[$];
|
40 |
|
|
|
41 |
|
|
protected int m_num_last_reqs = 1;
|
42 |
|
|
protected int num_last_items = m_num_last_reqs;
|
43 |
|
|
protected int m_num_last_rsps = 1;
|
44 |
|
|
protected int m_num_reqs_sent;
|
45 |
|
|
protected int m_num_rsps_received;
|
46 |
|
|
uvm_sequencer_analysis_fifo #(RSP) sqr_rsp_analysis_fifo;
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
// Function: new
|
50 |
|
|
//
|
51 |
|
|
// Creates and initializes an instance of this class using the normal
|
52 |
|
|
// constructor arguments for uvm_component: name is the name of the instance,
|
53 |
|
|
// and parent is the handle to the hierarchical parent, if any.
|
54 |
|
|
//
|
55 |
|
|
extern function new (string name, uvm_component parent);
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
// Function: send_request
|
59 |
|
|
//
|
60 |
|
|
// The send_request function may only be called after a wait_for_grant call.
|
61 |
|
|
// This call will send the request item, t, to the sequencer pointed to by
|
62 |
|
|
// sequence_ptr. The sequencer will forward it to the driver. If rerandomize
|
63 |
|
|
// is set, the item will be randomized before being sent to the driver.
|
64 |
|
|
//
|
65 |
|
|
extern virtual function void send_request(uvm_sequence_base sequence_ptr,
|
66 |
|
|
uvm_sequence_item t,
|
67 |
|
|
bit rerandomize = 0);
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
// Function: get_current_item
|
71 |
|
|
//
|
72 |
|
|
// Returns the request_item currently being executed by the sequencer. If the
|
73 |
|
|
// sequencer is not currently executing an item, this method will return ~null~.
|
74 |
|
|
//
|
75 |
|
|
// The sequencer is executing an item from the time that get_next_item or peek
|
76 |
|
|
// is called until the time that get or item_done is called.
|
77 |
|
|
//
|
78 |
|
|
// Note that a driver that only calls get() will never show a current item,
|
79 |
|
|
// since the item is completed at the same time as it is requested.
|
80 |
|
|
//
|
81 |
|
|
function REQ get_current_item();
|
82 |
|
|
REQ t;
|
83 |
|
|
if (m_req_fifo.try_peek(t) == 0)
|
84 |
|
|
return null;
|
85 |
|
|
return t;
|
86 |
|
|
endfunction
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
//----------------
|
90 |
|
|
// Group: Requests
|
91 |
|
|
//----------------
|
92 |
|
|
|
93 |
|
|
// Function: get_num_reqs_sent
|
94 |
|
|
//
|
95 |
|
|
// Returns the number of requests that have been sent by this sequencer.
|
96 |
|
|
//
|
97 |
|
|
extern function int get_num_reqs_sent();
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
// Function: set_num_last_reqs
|
101 |
|
|
//
|
102 |
|
|
// Sets the size of the last_requests buffer. Note that the maximum buffer
|
103 |
|
|
// size is 1024. If max is greater than 1024, a warning is issued, and the
|
104 |
|
|
// buffer is set to 1024. The default value is 1.
|
105 |
|
|
//
|
106 |
|
|
extern function void set_num_last_reqs(int unsigned max);
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
// Function: get_num_last_reqs
|
110 |
|
|
//
|
111 |
|
|
// Returns the size of the last requests buffer, as set by set_num_last_reqs.
|
112 |
|
|
|
113 |
|
|
extern function int unsigned get_num_last_reqs();
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
// Function: last_req
|
117 |
|
|
//
|
118 |
|
|
// Returns the last request item by default. If n is not 0, then it will get
|
119 |
|
|
// the n�th before last request item. If n is greater than the last request
|
120 |
|
|
// buffer size, the function will return ~null~.
|
121 |
|
|
//
|
122 |
|
|
function REQ last_req(int unsigned n = 0);
|
123 |
|
|
if(n > m_num_last_reqs) begin
|
124 |
|
|
uvm_report_warning("HSTOB",
|
125 |
|
|
$sformatf("Invalid last access (%0d), the max history is %0d", n,
|
126 |
|
|
m_num_last_reqs));
|
127 |
|
|
return null;
|
128 |
|
|
end
|
129 |
|
|
if(n == m_last_req_buffer.size())
|
130 |
|
|
return null;
|
131 |
|
|
|
132 |
|
|
return m_last_req_buffer[n];
|
133 |
|
|
endfunction
|
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
//-----------------
|
138 |
|
|
// Group: Responses
|
139 |
|
|
//-----------------
|
140 |
|
|
|
141 |
|
|
// Port: rsp_export
|
142 |
|
|
//
|
143 |
|
|
// Drivers or monitors can connect to this port to send responses
|
144 |
|
|
// to the sequencer. Alternatively, a driver can send responses
|
145 |
|
|
// via its seq_item_port.
|
146 |
|
|
//
|
147 |
|
|
//| seq_item_port.item_done(response)
|
148 |
|
|
//| seq_item_port.put(response)
|
149 |
|
|
//| rsp_port.write(response) <--- via this export
|
150 |
|
|
//
|
151 |
|
|
// The rsp_port in the driver and/or monitor must be connected to the
|
152 |
|
|
// rsp_export in this sequencer in order to send responses through the
|
153 |
|
|
// response analysis port.
|
154 |
|
|
|
155 |
|
|
uvm_analysis_export #(RSP) rsp_export;
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
// Function: get_num_rsps_received
|
159 |
|
|
//
|
160 |
|
|
// Returns the number of responses received thus far by this sequencer.
|
161 |
|
|
|
162 |
|
|
extern function int get_num_rsps_received();
|
163 |
|
|
|
164 |
|
|
|
165 |
|
|
// Function: set_num_last_rsps
|
166 |
|
|
//
|
167 |
|
|
// Sets the size of the last_responses buffer. The maximum buffer size is
|
168 |
|
|
// 1024. If max is greater than 1024, a warning is issued, and the buffer is
|
169 |
|
|
// set to 1024. The default value is 1.
|
170 |
|
|
//
|
171 |
|
|
extern function void set_num_last_rsps(int unsigned max);
|
172 |
|
|
|
173 |
|
|
|
174 |
|
|
// Function: get_num_last_rsps
|
175 |
|
|
//
|
176 |
|
|
// Returns the max size of the last responses buffer, as set by
|
177 |
|
|
// set_num_last_rsps.
|
178 |
|
|
//
|
179 |
|
|
extern function int unsigned get_num_last_rsps();
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
// Function: last_rsp
|
183 |
|
|
//
|
184 |
|
|
// Returns the last response item by default. If n is not 0, then it will
|
185 |
|
|
// get the nth-before-last response item. If n is greater than the last
|
186 |
|
|
// response buffer size, the function will return ~null~.
|
187 |
|
|
//
|
188 |
|
|
function RSP last_rsp(int unsigned n = 0);
|
189 |
|
|
if(n > m_num_last_rsps) begin
|
190 |
|
|
uvm_report_warning("HSTOB",
|
191 |
|
|
$sformatf("Invalid last access (%0d), the max history is %0d", n,
|
192 |
|
|
m_num_last_rsps));
|
193 |
|
|
return null;
|
194 |
|
|
end
|
195 |
|
|
if(n == m_last_rsp_buffer.size())
|
196 |
|
|
return null;
|
197 |
|
|
|
198 |
|
|
return m_last_rsp_buffer[n];
|
199 |
|
|
endfunction
|
200 |
|
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
// Internal methods and variables; do not use directly, not part of standard
|
204 |
|
|
|
205 |
|
|
/* local */ extern function void m_last_rsp_push_front(RSP item);
|
206 |
|
|
/* local */ extern function void put_response (RSP t);
|
207 |
|
|
/* local */ extern virtual function void build_phase(uvm_phase phase);
|
208 |
|
|
/* local */ extern virtual function void connect_phase(uvm_phase phase);
|
209 |
|
|
/* local */ extern virtual function void do_print (uvm_printer printer);
|
210 |
|
|
/* local */ extern virtual function void analysis_write(uvm_sequence_item t);
|
211 |
|
|
/* local */ extern function void m_last_req_push_front(REQ item);
|
212 |
|
|
|
213 |
|
|
/* local */ uvm_tlm_fifo #(REQ) m_req_fifo;
|
214 |
|
|
|
215 |
|
|
endclass
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
//------------------------------------------------------------------------------
|
219 |
|
|
// IMPLEMENTATION
|
220 |
|
|
//------------------------------------------------------------------------------
|
221 |
|
|
|
222 |
|
|
// new
|
223 |
|
|
// ---
|
224 |
|
|
|
225 |
|
|
function uvm_sequencer_param_base::new (string name, uvm_component parent);
|
226 |
|
|
super.new(name, parent);
|
227 |
|
|
|
228 |
|
|
rsp_export = new("rsp_export", this);
|
229 |
|
|
sqr_rsp_analysis_fifo = new("sqr_rsp_analysis_fifo", this);
|
230 |
|
|
sqr_rsp_analysis_fifo.print_enabled = 0;
|
231 |
|
|
m_req_fifo = new("req_fifo", this);
|
232 |
|
|
m_req_fifo.print_enabled = 0;
|
233 |
|
|
endfunction
|
234 |
|
|
|
235 |
|
|
|
236 |
|
|
// do_print
|
237 |
|
|
// --------
|
238 |
|
|
|
239 |
|
|
function void uvm_sequencer_param_base::do_print (uvm_printer printer);
|
240 |
|
|
super.do_print(printer);
|
241 |
|
|
printer.print_field_int("num_last_reqs", m_num_last_reqs, $bits(m_num_last_reqs), UVM_DEC);
|
242 |
|
|
printer.print_field_int("num_last_rsps", m_num_last_rsps, $bits(m_num_last_rsps), UVM_DEC);
|
243 |
|
|
endfunction
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
// connect_phase
|
247 |
|
|
// -------------
|
248 |
|
|
|
249 |
|
|
function void uvm_sequencer_param_base::connect_phase(uvm_phase phase);
|
250 |
|
|
super.connect_phase(phase);
|
251 |
|
|
rsp_export.connect(sqr_rsp_analysis_fifo.analysis_export);
|
252 |
|
|
endfunction
|
253 |
|
|
|
254 |
|
|
|
255 |
|
|
// build_phase
|
256 |
|
|
// -----------
|
257 |
|
|
|
258 |
|
|
function void uvm_sequencer_param_base::build_phase(uvm_phase phase);
|
259 |
|
|
super.build_phase(phase);
|
260 |
|
|
sqr_rsp_analysis_fifo.sequencer_ptr = this;
|
261 |
|
|
endfunction
|
262 |
|
|
|
263 |
|
|
|
264 |
|
|
// send_request
|
265 |
|
|
// ------------
|
266 |
|
|
|
267 |
|
|
function void uvm_sequencer_param_base::send_request(uvm_sequence_base sequence_ptr,
|
268 |
|
|
uvm_sequence_item t,
|
269 |
|
|
bit rerandomize = 0);
|
270 |
|
|
REQ param_t;
|
271 |
|
|
|
272 |
|
|
if (sequence_ptr == null) begin
|
273 |
|
|
uvm_report_fatal("SNDREQ", "Send request sequence_ptr is null", UVM_NONE);
|
274 |
|
|
end
|
275 |
|
|
|
276 |
|
|
if (sequence_ptr.m_wait_for_grant_semaphore < 1) begin
|
277 |
|
|
uvm_report_fatal("SNDREQ", "Send request called without wait_for_grant", UVM_NONE);
|
278 |
|
|
end
|
279 |
|
|
sequence_ptr.m_wait_for_grant_semaphore--;
|
280 |
|
|
|
281 |
|
|
if ($cast(param_t, t)) begin
|
282 |
|
|
if (rerandomize == 1) begin
|
283 |
|
|
if (!param_t.randomize()) begin
|
284 |
|
|
uvm_report_warning("SQRSNDREQ", "Failed to rerandomize sequence item in send_request");
|
285 |
|
|
end
|
286 |
|
|
end
|
287 |
|
|
if (param_t.get_transaction_id() == -1) begin
|
288 |
|
|
param_t.set_transaction_id(sequence_ptr.m_next_transaction_id++);
|
289 |
|
|
end
|
290 |
|
|
m_last_req_push_front(param_t);
|
291 |
|
|
end else begin
|
292 |
|
|
uvm_report_fatal(get_name(),$sformatf("send_request failed to cast sequence item"), UVM_NONE);
|
293 |
|
|
end
|
294 |
|
|
|
295 |
|
|
param_t.set_sequence_id(sequence_ptr.m_get_sqr_sequence_id(m_sequencer_id, 1));
|
296 |
|
|
t.set_sequencer(this);
|
297 |
|
|
if (m_req_fifo.try_put(param_t) != 1) begin
|
298 |
|
|
uvm_report_fatal(get_full_name(), "Concurrent calls to get_next_item() not supported. Consider using a semaphore to ensure that concurrent processes take turns in the driver", UVM_NONE);
|
299 |
|
|
end
|
300 |
|
|
|
301 |
|
|
m_num_reqs_sent++;
|
302 |
|
|
// Grant any locks as soon as possible
|
303 |
|
|
grant_queued_locks();
|
304 |
|
|
endfunction
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
// put_response
|
308 |
|
|
// ------------
|
309 |
|
|
|
310 |
|
|
function void uvm_sequencer_param_base::put_response (RSP t);
|
311 |
|
|
uvm_sequence_base sequence_ptr;
|
312 |
|
|
|
313 |
|
|
if (t == null) begin
|
314 |
|
|
uvm_report_fatal("SQRPUT", "Driver put a null response", UVM_NONE);
|
315 |
|
|
end
|
316 |
|
|
|
317 |
|
|
m_last_rsp_push_front(t);
|
318 |
|
|
m_num_rsps_received++;
|
319 |
|
|
|
320 |
|
|
// Check that set_id_info was called
|
321 |
|
|
if (t.get_sequence_id() == -1) begin
|
322 |
|
|
`ifndef CDNS_NO_SQR_CHK_SEQ_ID
|
323 |
|
|
uvm_report_fatal("SQRPUT", "Driver put a response with null sequence_id", UVM_NONE);
|
324 |
|
|
`endif
|
325 |
|
|
return;
|
326 |
|
|
end
|
327 |
|
|
|
328 |
|
|
sequence_ptr = m_find_sequence(t.get_sequence_id());
|
329 |
|
|
|
330 |
|
|
if (sequence_ptr != null) begin
|
331 |
|
|
// If the response_handler is enabled for this sequence, then call the response handler
|
332 |
|
|
if (sequence_ptr.get_use_response_handler() == 1) begin
|
333 |
|
|
sequence_ptr.response_handler(t);
|
334 |
|
|
return;
|
335 |
|
|
end
|
336 |
|
|
|
337 |
|
|
sequence_ptr.put_response(t);
|
338 |
|
|
end
|
339 |
|
|
else begin
|
340 |
|
|
uvm_report_info("Sequencer",
|
341 |
|
|
$sformatf("Dropping response for sequence %0d, sequence not found. Probable cause: sequence exited or has been killed",
|
342 |
|
|
t.get_sequence_id()));
|
343 |
|
|
end
|
344 |
|
|
endfunction
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
// analysis_write
|
348 |
|
|
// --------------
|
349 |
|
|
|
350 |
|
|
function void uvm_sequencer_param_base::analysis_write(uvm_sequence_item t);
|
351 |
|
|
RSP response;
|
352 |
|
|
|
353 |
|
|
if (!$cast(response, t)) begin
|
354 |
|
|
uvm_report_fatal("ANALWRT", "Failure to cast analysis port write item", UVM_NONE);
|
355 |
|
|
end
|
356 |
|
|
put_response(response);
|
357 |
|
|
endfunction
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
// get_num_reqs_sent
|
361 |
|
|
// -----------------
|
362 |
|
|
|
363 |
|
|
function int uvm_sequencer_param_base::get_num_reqs_sent();
|
364 |
|
|
return m_num_reqs_sent;
|
365 |
|
|
endfunction
|
366 |
|
|
|
367 |
|
|
|
368 |
|
|
// get_num_rsps_received
|
369 |
|
|
// ---------------------
|
370 |
|
|
|
371 |
|
|
function int uvm_sequencer_param_base::get_num_rsps_received();
|
372 |
|
|
return m_num_rsps_received;
|
373 |
|
|
endfunction
|
374 |
|
|
|
375 |
|
|
|
376 |
|
|
// set_num_last_reqs
|
377 |
|
|
// -----------------
|
378 |
|
|
|
379 |
|
|
function void uvm_sequencer_param_base::set_num_last_reqs(int unsigned max);
|
380 |
|
|
if(max > 1024) begin
|
381 |
|
|
uvm_report_warning("HSTOB",
|
382 |
|
|
$sformatf("Invalid last size; 1024 is the maximum and will be used"));
|
383 |
|
|
max = 1024;
|
384 |
|
|
end
|
385 |
|
|
|
386 |
|
|
//shrink the buffer if necessary
|
387 |
|
|
while((m_last_req_buffer.size() != 0) && (m_last_req_buffer.size() > max))
|
388 |
|
|
void'(m_last_req_buffer.pop_back());
|
389 |
|
|
|
390 |
|
|
m_num_last_reqs = max;
|
391 |
|
|
num_last_items = max;
|
392 |
|
|
|
393 |
|
|
endfunction
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
// get_num_last_reqs
|
397 |
|
|
// -----------------
|
398 |
|
|
|
399 |
|
|
function int unsigned uvm_sequencer_param_base::get_num_last_reqs();
|
400 |
|
|
return m_num_last_reqs;
|
401 |
|
|
endfunction
|
402 |
|
|
|
403 |
|
|
|
404 |
|
|
// m_last_req_push_front
|
405 |
|
|
// ---------------------
|
406 |
|
|
|
407 |
|
|
function void uvm_sequencer_param_base::m_last_req_push_front(REQ item);
|
408 |
|
|
if(!m_num_last_reqs)
|
409 |
|
|
return;
|
410 |
|
|
|
411 |
|
|
if(m_last_req_buffer.size() == m_num_last_reqs)
|
412 |
|
|
void'(m_last_req_buffer.pop_back());
|
413 |
|
|
|
414 |
|
|
this.m_last_req_buffer.push_front(item);
|
415 |
|
|
endfunction
|
416 |
|
|
|
417 |
|
|
|
418 |
|
|
// set_num_last_rsps
|
419 |
|
|
// -----------------
|
420 |
|
|
|
421 |
|
|
function void uvm_sequencer_param_base::set_num_last_rsps(int unsigned max);
|
422 |
|
|
if(max > 1024) begin
|
423 |
|
|
uvm_report_warning("HSTOB",
|
424 |
|
|
$sformatf("Invalid last size; 1024 is the maximum and will be used"));
|
425 |
|
|
max = 1024;
|
426 |
|
|
end
|
427 |
|
|
|
428 |
|
|
//shrink the buffer
|
429 |
|
|
while((m_last_rsp_buffer.size() != 0) && (m_last_rsp_buffer.size() > max)) begin
|
430 |
|
|
void'(m_last_rsp_buffer.pop_back());
|
431 |
|
|
end
|
432 |
|
|
|
433 |
|
|
m_num_last_rsps = max;
|
434 |
|
|
|
435 |
|
|
endfunction
|
436 |
|
|
|
437 |
|
|
|
438 |
|
|
// get_num_last_rsps
|
439 |
|
|
// -----------------
|
440 |
|
|
|
441 |
|
|
function int unsigned uvm_sequencer_param_base::get_num_last_rsps();
|
442 |
|
|
return m_num_last_rsps;
|
443 |
|
|
endfunction
|
444 |
|
|
|
445 |
|
|
|
446 |
|
|
// m_last_rsp_push_front
|
447 |
|
|
// ---------------------
|
448 |
|
|
|
449 |
|
|
function void uvm_sequencer_param_base::m_last_rsp_push_front(RSP item);
|
450 |
|
|
if(!m_num_last_rsps)
|
451 |
|
|
return;
|
452 |
|
|
|
453 |
|
|
if(m_last_rsp_buffer.size() == m_num_last_rsps)
|
454 |
|
|
void'(m_last_rsp_buffer.pop_back());
|
455 |
|
|
|
456 |
|
|
this.m_last_rsp_buffer.push_front(item);
|
457 |
|
|
endfunction
|
458 |
|
|
|
459 |
|
|
|