OpenCores
URL https://opencores.org/ocsvn/uart2bus_testbench/uart2bus_testbench/trunk

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [seq/] [uvm_sequence_item.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//----------------------------------------------------------------------
2
//   Copyright 2007-2011 Mentor Graphics Corporation
3
//   Copyright 2007-2010 Cadence Design Systems, Inc.
4
//   Copyright 2010 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
typedef class uvm_sequence_base;
23
typedef class uvm_sequencer_base;
24
 
25
 
26
//------------------------------------------------------------------------------
27
//
28
// CLASS: uvm_sequence_item
29
//
30
// The base class for user-defined sequence items and also the base class for
31
// the uvm_sequence class. The uvm_sequence_item class provides the basic
32
// functionality for objects, both sequence items and sequences, to operate in
33
// the sequence mechanism.
34
//
35
//------------------------------------------------------------------------------
36
 
37
class uvm_sequence_item extends uvm_transaction;
38
 
39
  local      int                m_sequence_id = -1;
40
  protected  bit                m_use_sequence_info;
41
  protected  int                m_depth = -1;
42
  protected  uvm_sequencer_base m_sequencer;
43
  protected  uvm_sequence_base  m_parent_sequence;
44
  static     bit issued1,issued2;
45
  bit        print_sequence_info;
46
 
47
 
48
  // Function: new
49
  //
50
  // The constructor method for uvm_sequence_item.
51
 
52
  function new (string name = "uvm_sequence_item");
53
    super.new(name);
54
  endfunction
55
 
56
  function string get_type_name();
57
    return "uvm_sequence_item";
58
  endfunction
59
 
60
  // Macro for factory creation
61
  `uvm_object_registry(uvm_sequence_item, "uvm_sequence_item")
62
 
63
 
64
  // Function- set_sequence_id
65
 
66
  function void set_sequence_id(int id);
67
    m_sequence_id = id;
68
  endfunction
69
 
70
 
71
  // Function: get_sequence_id
72
  //
73
  // private
74
  //
75
  // Get_sequence_id is an internal method that is not intended for user code.
76
  // The sequence_id is not a simple integer.  The get_transaction_id is meant
77
  // for users to identify specific transactions.
78
  //
79
  // These methods allow access to the sequence_item sequence and transaction
80
  // IDs. get_transaction_id and set_transaction_id are methods on the
81
  // uvm_transaction base_class. These IDs are used to identify sequences to
82
  // the sequencer, to route responses back to the sequence that issued a
83
  // request, and to uniquely identify transactions.
84
  //
85
  // The sequence_id is assigned automatically by a sequencer when a sequence
86
  // initiates communication through any sequencer calls (i.e. `uvm_do_*,
87
  // wait_for_grant).  A sequence_id will remain unique for this sequence
88
  // until it ends or it is killed.  However, a single sequence may have
89
  // multiple valid sequence ids at any point in time.  Should a sequence
90
  // start again after it has ended, it will be given a new unique sequence_id.
91
  //
92
  // The transaction_id is assigned automatically by the sequence each time a
93
  // transaction is sent to the sequencer with the transaction_id in its
94
  // default (-1) value.  If the user sets the transaction_id to any non-default
95
  // value, that value will be maintained.
96
  //
97
  // Responses are routed back to this sequences based on sequence_id. The
98
  // sequence may use the transaction_id to correlate responses with their
99
  // requests.
100
 
101
  function int get_sequence_id();
102
    return (m_sequence_id);
103
  endfunction
104
 
105
 
106
  // Function: set_item_context
107
  //
108
  // Set the sequence and sequencer execution context for a sequence item
109
 
110
  function void set_item_context(uvm_sequence_base  parent_seq,
111
                                 uvm_sequencer_base sequencer = null);
112
     set_use_sequence_info(1);
113
     if (parent_seq != null) set_parent_sequence(parent_seq);
114
     if (sequencer == null && m_parent_sequence != null) sequencer = m_parent_sequence.get_sequencer();
115
     set_sequencer(sequencer);
116
     if (m_parent_sequence != null) set_depth(m_parent_sequence.get_depth() + 1);
117
     reseed();
118
  endfunction
119
 
120
 
121
  // Function: set_use_sequence_info
122
  //
123
 
124
  function void set_use_sequence_info(bit value);
125
    m_use_sequence_info = value;
126
  endfunction
127
 
128
 
129
  // Function: get_use_sequence_info
130
  //
131
  // These methods are used to set and get the status of the use_sequence_info
132
  // bit. Use_sequence_info controls whether the sequence information
133
  // (sequencer, parent_sequence, sequence_id, etc.) is printed, copied, or
134
  // recorded. When use_sequence_info is the default value of 0, then the
135
  // sequence information is not used. When use_sequence_info is set to 1,
136
  // the sequence information will be used in printing and copying.
137
 
138
  function bit get_use_sequence_info();
139
    return (m_use_sequence_info);
140
  endfunction
141
 
142
 
143
  // Function: set_id_info
144
  //
145
  // Copies the sequence_id and transaction_id from the referenced item into
146
  // the calling item.  This routine should always be used by drivers to
147
  // initialize responses for future compatibility.
148
 
149
  function void set_id_info(uvm_sequence_item item);
150
    if (item == null) begin
151
      uvm_report_fatal(get_full_name(), "set_id_info called with null parameter", UVM_NONE);
152
    end
153
    this.set_transaction_id(item.get_transaction_id());
154
    this.set_sequence_id(item.get_sequence_id());
155
  endfunction
156
 
157
 
158
  // Function: set_sequencer
159
  //
160
  // Sets the default sequencer for the sequence to sequencer.  It will take
161
  // effect immediately, so it should not be called while the sequence is
162
  // actively communicating with the sequencer.
163
 
164
  virtual function void set_sequencer(uvm_sequencer_base sequencer);
165
    m_sequencer = sequencer;
166
    m_set_p_sequencer();
167
  endfunction
168
 
169
 
170
  // Function: get_sequencer
171
  //
172
  // Returns a reference to the default sequencer used by this sequence.
173
 
174
  function uvm_sequencer_base get_sequencer();
175
    return m_sequencer;
176
  endfunction
177
 
178
 
179
  // Function: set_parent_sequence
180
  //
181
  // Sets the parent sequence of this sequence_item.  This is used to identify
182
  // the source sequence of a sequence_item.
183
 
184
  function void set_parent_sequence(uvm_sequence_base parent);
185
    m_parent_sequence = parent;
186
  endfunction
187
 
188
 
189
  // Function: get_parent_sequence
190
  //
191
  // Returns a reference to the parent sequence of any sequence on which this
192
  // method was called. If this is a parent sequence, the method returns ~null~.
193
 
194
  function uvm_sequence_base get_parent_sequence();
195
    return (m_parent_sequence);
196
  endfunction
197
 
198
 
199
  // Function: set_depth
200
  //
201
  // The depth of any sequence is calculated automatically.  However, the user
202
  // may use  set_depth to specify the depth of a particular sequence. This
203
  // method will override the automatically calculated depth, even if it is
204
  // incorrect.
205
 
206
  function void set_depth(int value);
207
    m_depth = value;
208
  endfunction
209
 
210
 
211
  // Function: get_depth
212
  //
213
  // Returns the depth of a sequence from its parent.  A  parent sequence will
214
  // have a depth of 1, its child will have a depth  of 2, and its grandchild
215
  // will have a depth of 3.
216
 
217
  function int get_depth();
218
 
219
    // If depth has been set or calculated, then use that
220
    if (m_depth != -1) begin
221
      return (m_depth);
222
    end
223
 
224
    // Calculate the depth, store it, and return the value
225
    if (m_parent_sequence == null) begin
226
      m_depth = 1;
227
    end else begin
228
      m_depth = m_parent_sequence.get_depth() + 1;
229
    end
230
 
231
    return (m_depth);
232
  endfunction
233
 
234
 
235
  // Function: is_item
236
  //
237
  // This function may be called on any sequence_item or sequence. It will
238
  // return 1 for items and 0 for sequences (which derive from this class).
239
 
240
  virtual function bit is_item();
241
    return(1);
242
  endfunction
243
 
244
 
245
  // Function- get_full_name
246
  //
247
  // Internal method; overrides must follow same naming convention
248
 
249
  function string get_full_name();
250
    if(m_parent_sequence != null)
251
      get_full_name = {m_parent_sequence.get_full_name(), "."};
252
    else if(m_sequencer!=null)
253
      get_full_name = {m_sequencer.get_full_name(), "."};
254
    if(get_name() != "")
255
      get_full_name = {get_full_name, get_name()};
256
    else begin
257
      get_full_name = {get_full_name, "_item"};
258
    end
259
  endfunction
260
 
261
 
262
  // Function: get_root_sequence_name
263
  //
264
  // Provides the name of the root sequence (the top-most parent sequence).
265
 
266
  function string get_root_sequence_name();
267
    uvm_sequence_base root_seq;
268
    root_seq = get_root_sequence();
269
    if (root_seq == null)
270
      return "";
271
    else
272
      return root_seq.get_name();
273
  endfunction
274
 
275
 
276
  // Function- m_set_p_sequencer
277
  //
278
  // Internal method
279
 
280
  virtual function void m_set_p_sequencer();
281
    return;
282
  endfunction
283
 
284
 
285
  // Function: get_root_sequence
286
  //
287
  // Provides a reference to the root sequence (the top-most parent sequence).
288
 
289
  function uvm_sequence_base get_root_sequence();
290
    uvm_sequence_item root_seq_base;
291
    uvm_sequence_base root_seq;
292
    root_seq_base = this;
293
    while(1) begin
294
      if(root_seq_base.get_parent_sequence()!=null) begin
295
        root_seq_base = root_seq_base.get_parent_sequence();
296
        $cast(root_seq, root_seq_base);
297
      end
298
      else
299
        return root_seq;
300
    end
301
  endfunction
302
 
303
 
304
  // Function: get_sequence_path
305
  //
306
  // Provides a string of names of each sequence in the full hierarchical
307
  // path. A "." is used as the separator between each sequence.
308
 
309
  function string get_sequence_path();
310
    uvm_sequence_item this_item;
311
    string seq_path;
312
    this_item = this;
313
    seq_path = this.get_name();
314
    while(1) begin
315
      if(this_item.get_parent_sequence()!=null) begin
316
        this_item = this_item.get_parent_sequence();
317
        seq_path = {this_item.get_name(), ".", seq_path};
318
      end
319
      else
320
        return seq_path;
321
    end
322
  endfunction
323
 
324
 
325
  //---------------------------
326
  // Group: Reporting Interface
327
  //---------------------------
328
  //
329
  // Sequence items and sequences will use the sequencer which they are
330
  // associated with for reporting messages. If no sequencer has been set
331
  // for the item/sequence using  or indirectly via
332
  //  or ),
333
  // then the global reporter will be used.
334
 
335
  virtual function uvm_report_object uvm_get_report_object();
336
    if(m_sequencer == null) begin
337
      uvm_coreservice_t cs = uvm_coreservice_t::get();
338
       return cs.get_root();
339
    end else
340
      return m_sequencer;
341
  endfunction
342
 
343
  function int uvm_report_enabled(int verbosity,
344
                                  uvm_severity severity=UVM_INFO, string id="");
345
    uvm_report_object l_report_object = uvm_get_report_object();
346
    if (l_report_object.get_report_verbosity_level(severity, id) < verbosity)
347
      return 0;
348
    return 1;
349
  endfunction
350
 
351
  // Function: uvm_report
352
  virtual function void uvm_report( uvm_severity severity,
353
                                    string id,
354
                                    string message,
355
                                    int verbosity = (severity == uvm_severity'(UVM_ERROR)) ? UVM_LOW :
356
                                                    (severity == uvm_severity'(UVM_FATAL)) ? UVM_NONE : UVM_MEDIUM,
357
                                    string filename = "",
358
                                    int line = 0,
359
                                    string context_name = "",
360
                                    bit report_enabled_checked = 0);
361
    uvm_report_message l_report_message;
362
    if (report_enabled_checked == 0) begin
363
      if (!uvm_report_enabled(verbosity, severity, id))
364
        return;
365
    end
366
    l_report_message = uvm_report_message::new_report_message();
367
    l_report_message.set_report_message(severity, id, message,
368
                                        verbosity, filename, line, context_name);
369
    uvm_process_report_message(l_report_message);
370
 
371
  endfunction
372
 
373
  // Function: uvm_report_info
374
 
375
  virtual function void uvm_report_info( string id,
376
                                         string message,
377
                                         int verbosity = UVM_MEDIUM,
378
                                         string filename = "",
379
                                         int line = 0,
380
                                         string context_name = "",
381
                                         bit report_enabled_checked = 0);
382
 
383
    this.uvm_report(UVM_INFO, id, message, verbosity, filename, line,
384
                    context_name, report_enabled_checked);
385
  endfunction
386
 
387
  // Function: uvm_report_warning
388
 
389
  virtual function void uvm_report_warning( string id,
390
                                            string message,
391
                                            int verbosity = UVM_MEDIUM,
392
                                            string filename = "",
393
                                            int line = 0,
394
                                            string context_name = "",
395
                                            bit report_enabled_checked = 0);
396
 
397
    this.uvm_report(UVM_WARNING, id, message, verbosity, filename, line,
398
                    context_name, report_enabled_checked);
399
  endfunction
400
 
401
  // Function: uvm_report_error
402
 
403
  virtual function void uvm_report_error( string id,
404
                                          string message,
405
                                          int verbosity = UVM_LOW,
406
                                          string filename = "",
407
                                          int line = 0,
408
                                          string context_name = "",
409
                                          bit report_enabled_checked = 0);
410
 
411
    this.uvm_report(UVM_ERROR, id, message, verbosity, filename, line,
412
                    context_name, report_enabled_checked);
413
  endfunction
414
 
415
  // Function: uvm_report_fatal
416
  //
417
  // These are the primary reporting methods in the UVM. uvm_sequence_item
418
  // derived types delegate these functions to their associated sequencer
419
  // if they have one, or to the global reporter. See 
420
  // for details on the messaging functions.
421
 
422
  virtual function void uvm_report_fatal( string id,
423
                                          string message,
424
                                          int verbosity = UVM_NONE,
425
                                          string filename = "",
426
                                          int line = 0,
427
                                          string context_name = "",
428
                                          bit report_enabled_checked = 0);
429
 
430
    this.uvm_report(UVM_FATAL, id, message, verbosity, filename, line,
431
                    context_name, report_enabled_checked);
432
  endfunction
433
 
434
  virtual function void uvm_process_report_message (uvm_report_message report_message);
435
    uvm_report_object l_report_object = uvm_get_report_object();
436
    report_message.set_report_object(l_report_object);
437
    if (report_message.get_context() == "")
438
      report_message.set_context(get_sequence_path());
439
    l_report_object.m_rh.process_report_message(report_message);
440
  endfunction
441
 
442
 
443
  // Function- do_print
444
  //
445
  // Internal method
446
 
447
  function void do_print (uvm_printer printer);
448
    string temp_str0, temp_str1;
449
    int depth = get_depth();
450
    super.do_print(printer);
451
    if(print_sequence_info || m_use_sequence_info) begin
452
      printer.print_field_int("depth", depth, $bits(depth), UVM_DEC, ".", "int");
453
      if(m_parent_sequence != null) begin
454
        temp_str0 = m_parent_sequence.get_name();
455
        temp_str1 = m_parent_sequence.get_full_name();
456
      end
457
      printer.print_string("parent sequence (name)", temp_str0);
458
      printer.print_string("parent sequence (full name)", temp_str1);
459
      temp_str1 = "";
460
      if(m_sequencer != null) begin
461
        temp_str1 = m_sequencer.get_full_name();
462
      end
463
      printer.print_string("sequencer", temp_str1);
464
    end
465
  endfunction
466
 
467
  /*
468
  virtual task pre_do(bit is_item);
469
    return;
470
  endtask
471
 
472
  virtual task body();
473
    return;
474
  endtask
475
 
476
  virtual function void mid_do(uvm_sequence_item this_item);
477
    return;
478
  endfunction
479
 
480
  virtual function void post_do(uvm_sequence_item this_item);
481
    return;
482
  endfunction
483
 
484
  virtual task wait_for_grant(int item_priority = -1, bit  lock_request = 0);
485
    return;
486
  endtask
487
 
488
  virtual function void send_request(uvm_sequence_item request, bit rerandomize = 0);
489
    return;
490
  endfunction
491
 
492
  virtual task wait_for_item_done(int transaction_id = -1);
493
    return;
494
  endtask
495
  */
496
 
497
endclass

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.