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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [base/] [uvm_globals.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2007-2011 Mentor Graphics Corporation
4
//   Copyright 2007-2011 Cadence Design Systems, Inc.
5
//   Copyright 2010-2011 Synopsys, Inc.
6
//   Copyright 2013-2014 NVIDIA Corporation
7
//   All Rights Reserved Worldwide
8
//
9
//   Licensed under the Apache License, Version 2.0 (the
10
//   "License"); you may not use this file except in
11
//   compliance with the License.  You may obtain a copy of
12
//   the License at
13
//
14
//       http://www.apache.org/licenses/LICENSE-2.0
15
//
16
//   Unless required by applicable law or agreed to in
17
//   writing, software distributed under the License is
18
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
19
//   CONDITIONS OF ANY KIND, either express or implied.  See
20
//   the License for the specific language governing
21
//   permissions and limitations under the License.
22
//------------------------------------------------------------------------------
23
 
24
 
25
// Title: Globals
26
 
27
//------------------------------------------------------------------------------
28
//
29
// Group: Simulation Control
30
//
31
//------------------------------------------------------------------------------
32
 
33
// Task: run_test
34
//
35
// Convenience function for uvm_top.run_test(). See  for more
36
// information.
37
 
38
task run_test (string test_name="");
39
  uvm_root top;
40
  uvm_coreservice_t cs;
41
  cs = uvm_coreservice_t::get();
42
  top = cs.get_root();
43
  top.run_test(test_name);
44
endtask
45
 
46
 
47
`ifndef UVM_NO_DEPRECATED
48
// Variable- uvm_test_done - DEPRECATED
49
//
50
// An instance of the  class, this object is
51
// used by components to coordinate when to end the currently running
52
// task-based phase. When all participating components have dropped their
53
// raised objections, an implicit call to  is issued
54
// to end the run phase (or any other task-based phase).
55
 
56
const uvm_test_done_objection uvm_test_done = uvm_test_done_objection::get();
57
 
58
 
59
// Method- global_stop_request  - DEPRECATED
60
//
61
// Convenience function for uvm_test_done.stop_request(). See
62
//  for more information.
63
 
64
function void global_stop_request();
65
  uvm_test_done_objection tdo;
66
  tdo = uvm_test_done_objection::get();
67
  tdo.stop_request();
68
endfunction
69
 
70
 
71
// Method- set_global_timeout  - DEPRECATED
72
//
73
// Convenience function for uvm_top.set_timeout(). See
74
//  for more information.  The overridable bit
75
// controls whether subsequent settings will be honored.
76
 
77
 
78
function void set_global_timeout(time timeout, bit overridable = 1);
79
  uvm_root top;
80
  uvm_coreservice_t cs;
81
  cs = uvm_coreservice_t::get();
82
  top = cs.get_root();
83
  top.set_timeout(timeout,overridable);
84
endfunction
85
 
86
 
87
// Function- set_global_stop_timeout - DEPRECATED
88
//
89
// Convenience function for uvm_test_done.stop_timeout = timeout.
90
// See  for more information.
91
 
92
function void set_global_stop_timeout(time timeout);
93
  uvm_test_done_objection tdo;
94
  tdo = uvm_test_done_objection::get();
95
  tdo.stop_timeout = timeout;
96
endfunction
97
`endif
98
 
99
 
100
//----------------------------------------------------------------------------
101
//
102
// Group: Reporting
103
//
104
//----------------------------------------------------------------------------
105
 
106
 
107
// Function: uvm_get_report_object
108
//
109
// Returns the nearest uvm_report_object when called.
110
// For the global version, it returns uvm_root.
111
//
112
function uvm_report_object uvm_get_report_object();
113
  uvm_root top;
114
  uvm_coreservice_t cs;
115
  cs = uvm_coreservice_t::get();
116
  top = cs.get_root();
117
  return top;
118
endfunction
119
 
120
 
121
// Function: uvm_report_enabled
122
//
123
// Returns 1 if the configured verbosity in ~uvm_top~ for this
124
// severity/id is greater than or equal to ~verbosity~ else returns 0.
125
//
126
// See also .
127
//
128
// Static methods of an extension of uvm_report_object, e.g. uvm_component-based
129
// objects, cannot call ~uvm_report_enabled~ because the call will resolve to
130
// the , which is non-static.
131
// Static methods cannot call non-static methods of the same class.
132
 
133
function int uvm_report_enabled (int verbosity,
134
                                 uvm_severity severity=UVM_INFO, string id="");
135
  uvm_root top;
136
  uvm_coreservice_t cs;
137
  cs = uvm_coreservice_t::get();
138
  top = cs.get_root();
139
  return top.uvm_report_enabled(verbosity,severity,id);
140
endfunction
141
 
142
// Function: uvm_report
143
 
144
function void uvm_report( uvm_severity severity,
145
                          string id,
146
                          string message,
147
                          int verbosity = (severity == uvm_severity'(UVM_ERROR)) ? UVM_LOW :
148
                                          (severity == uvm_severity'(UVM_FATAL)) ? UVM_NONE : UVM_MEDIUM,
149
                          string filename = "",
150
                          int line = 0,
151
                          string context_name = "",
152
                          bit report_enabled_checked = 0);
153
  uvm_root top;
154
  uvm_coreservice_t cs;
155
  cs = uvm_coreservice_t::get();
156
  top = cs.get_root();
157
  top.uvm_report(severity, id, message, verbosity, filename, line, context_name, report_enabled_checked);
158
endfunction
159
 
160
// Undocumented DPI available version of uvm_report
161
export "DPI-C" function m__uvm_report_dpi;
162
function void m__uvm_report_dpi(int severity,
163
                                string id,
164
                                string message,
165
                                int    verbosity,
166
                                string filename,
167
                                int    line);
168
   uvm_report(uvm_severity'(severity), id, message, verbosity, filename, line);
169
endfunction : m__uvm_report_dpi
170
 
171
// Function: uvm_report_info
172
 
173
function void uvm_report_info(string id,
174
                              string message,
175
                              int verbosity = UVM_MEDIUM,
176
                              string filename = "",
177
                              int line = 0,
178
                              string context_name = "",
179
                              bit report_enabled_checked = 0);
180
  uvm_root top;
181
  uvm_coreservice_t cs;
182
  cs = uvm_coreservice_t::get();
183
  top = cs.get_root();
184
  top.uvm_report_info(id, message, verbosity, filename, line, context_name,
185
    report_enabled_checked);
186
endfunction
187
 
188
 
189
// Function: uvm_report_warning
190
 
191
function void uvm_report_warning(string id,
192
                                 string message,
193
                                 int verbosity = UVM_MEDIUM,
194
                                 string filename = "",
195
                                 int line = 0,
196
                                 string context_name = "",
197
                                 bit report_enabled_checked = 0);
198
  uvm_root top;
199
  uvm_coreservice_t cs;
200
  cs = uvm_coreservice_t::get();
201
  top = cs.get_root();
202
  top.uvm_report_warning(id, message, verbosity, filename, line, context_name,
203
    report_enabled_checked);
204
endfunction
205
 
206
 
207
// Function: uvm_report_error
208
 
209
function void uvm_report_error(string id,
210
                               string message,
211
                               int verbosity = UVM_LOW,
212
                               string filename = "",
213
                               int line = 0,
214
                               string context_name = "",
215
                               bit report_enabled_checked = 0);
216
  uvm_root top;
217
  uvm_coreservice_t cs;
218
  cs = uvm_coreservice_t::get();
219
  top = cs.get_root();
220
  top.uvm_report_error(id, message, verbosity, filename, line, context_name,
221
    report_enabled_checked);
222
endfunction
223
 
224
 
225
// Function: uvm_report_fatal
226
//
227
// These methods, defined in package scope, are convenience functions that
228
// delegate to the corresponding component methods in ~uvm_top~. They can be
229
// used in module-based code to use the same reporting mechanism as class-based
230
// components. See  for details on the reporting mechanism.
231
//
232
// *Note:* Verbosity is ignored for warnings, errors, and fatals to ensure users
233
// do not inadvertently filter them out. It remains in the methods for backward
234
// compatibility.
235
 
236
function void uvm_report_fatal(string id,
237
                               string message,
238
                               int verbosity = UVM_NONE,
239
                               string filename = "",
240
                               int line = 0,
241
                               string context_name = "",
242
                               bit report_enabled_checked = 0);
243
  uvm_root top;
244
  uvm_coreservice_t cs;
245
  cs = uvm_coreservice_t::get();
246
  top = cs.get_root();
247
  top.uvm_report_fatal(id, message, verbosity, filename, line, context_name,
248
    report_enabled_checked);
249
endfunction
250
 
251
 
252
// Function: uvm_process_report_message
253
//
254
// This method, defined in package scope, is a convenience function that
255
// delegate to the corresponding component method in ~uvm_top~. It can be
256
// used in module-based code to use the same reporting mechanism as class-based
257
// components. See  for details on the reporting mechanism.
258
 
259
function void uvm_process_report_message(uvm_report_message report_message);
260
  uvm_root top;
261
  uvm_coreservice_t cs;
262
  process p;
263
  p = process::self();
264
  cs = uvm_coreservice_t::get();
265
  top = cs.get_root();
266
  top.uvm_process_report_message(report_message);
267
endfunction
268
 
269
 
270
// TODO merge with uvm_enum_wrapper#(uvm_severity)
271
function bit uvm_string_to_severity (string sev_str, output uvm_severity sev);
272
  case (sev_str)
273
    "UVM_INFO": sev = UVM_INFO;
274
    "UVM_WARNING": sev = UVM_WARNING;
275
    "UVM_ERROR": sev = UVM_ERROR;
276
    "UVM_FATAL": sev = UVM_FATAL;
277
    default: return 0;
278
  endcase
279
  return 1;
280
endfunction
281
 
282
 
283
function automatic bit uvm_string_to_action (string action_str, output uvm_action action);
284
  string actions[$];
285
  uvm_split_string(action_str,"|",actions);
286
  uvm_string_to_action = 1;
287
  action = 0;
288
  foreach(actions[i]) begin
289
    case (actions[i])
290
      "UVM_NO_ACTION": action |= UVM_NO_ACTION;
291
      "UVM_DISPLAY":   action |= UVM_DISPLAY;
292
      "UVM_LOG":       action |= UVM_LOG;
293
      "UVM_COUNT":     action |= UVM_COUNT;
294
      "UVM_EXIT":      action |= UVM_EXIT;
295
      "UVM_CALL_HOOK": action |= UVM_CALL_HOOK;
296
      "UVM_STOP":      action |= UVM_STOP;
297
      "UVM_RM_RECORD": action |= UVM_RM_RECORD;
298
      default: uvm_string_to_action = 0;
299
    endcase
300
  end
301
endfunction
302
 
303
 
304
`ifndef UVM_NO_DEPRECATED
305
//------------------------------------------------------------------------------
306
//
307
// Group- Configuration
308
//
309
//------------------------------------------------------------------------------
310
 
311
// Function- set_config_int
312
//
313
// This is the global version of set_config_int in . This
314
// function places the configuration setting for an integral field in a
315
// global override table, which has highest precedence over any
316
// component-level setting.  See  for
317
// details on setting configuration.
318
 
319
function void  set_config_int  (string inst_name,
320
                                string field_name,
321
                                uvm_bitstream_t value);
322
  uvm_root top;
323
  uvm_coreservice_t cs;
324
  if (!uvm_component::m_config_deprecated_warned) begin
325
     `uvm_warning("UVM/CFG/SET/DPR", "get/set_config_* API has been deprecated. Use uvm_config_db instead.")
326
     uvm_component::m_config_deprecated_warned = 1;
327
  end
328
  cs = uvm_coreservice_t::get();
329
  top = cs.get_root();
330
  top.set_config_int(inst_name, field_name, value);
331
endfunction
332
 
333
 
334
// Function- set_config_object
335
//
336
// This is the global version of set_config_object in . This
337
// function places the configuration setting for an object field in a
338
// global override table, which has highest precedence over any
339
// component-level setting.  See  for
340
// details on setting configuration.
341
 
342
function void set_config_object (string inst_name,
343
                                 string field_name,
344
                                 uvm_object value,
345
                                 bit clone=1);
346
  uvm_root top;
347
  uvm_coreservice_t cs;
348
  if (!uvm_component::m_config_deprecated_warned) begin
349
     `uvm_warning("UVM/CFG/SET/DPR", "get/set_config_* API has been deprecated. Use uvm_config_db instead.")
350
     uvm_component::m_config_deprecated_warned = 1;
351
  end
352
  cs = uvm_coreservice_t::get();
353
  top = cs.get_root();
354
  top.set_config_object(inst_name, field_name, value, clone);
355
endfunction
356
 
357
 
358
// Function- set_config_string
359
//
360
// This is the global version of set_config_string in . This
361
// function places the configuration setting for an string field in a
362
// global override table, which has highest precedence over any
363
// component-level setting.  See  for
364
// details on setting configuration.
365
 
366
function void set_config_string (string inst_name,
367
                                 string field_name,
368
                                 string value);
369
  uvm_root top;
370
  uvm_coreservice_t cs;
371
  if (!uvm_component::m_config_deprecated_warned) begin
372
     `uvm_warning("UVM/CFG/SET/DPR", "get/set_config_* API has been deprecated. Use uvm_config_db instead.")
373
     uvm_component::m_config_deprecated_warned = 1;
374
  end
375
  cs = uvm_coreservice_t::get();
376
  top = cs.get_root();
377
  top.set_config_string(inst_name, field_name, value);
378
endfunction
379
`endif
380
 
381
 
382
//----------------------------------------------------------------------------
383
//
384
// Group: Miscellaneous
385
//
386
//----------------------------------------------------------------------------
387
 
388
 
389
// Function: uvm_is_match
390
//
391
// Returns 1 if the two strings match, 0 otherwise.
392
//
393
// The first string, ~expr~, is a string that may contain '*' and '?'
394
// characters. A * matches zero or more characters, and ? matches any single
395
// character. The 2nd argument, ~str~, is the string begin matched against.
396
// It must not contain any wildcards.
397
//
398
//----------------------------------------------------------------------------
399
 
400
function bit uvm_is_match (string expr, string str);
401
  string s;
402
  s = uvm_glob_to_re(expr);
403
  return (uvm_re_match(s, str) == 0);
404
endfunction
405
 
406
 
407
parameter UVM_LINE_WIDTH = `UVM_LINE_WIDTH;
408
parameter UVM_NUM_LINES = `UVM_NUM_LINES;
409
parameter UVM_SMALL_STRING = UVM_LINE_WIDTH*8-1;
410
parameter UVM_LARGE_STRING = UVM_LINE_WIDTH*UVM_NUM_LINES*8-1;
411
 
412
 
413
//----------------------------------------------------------------------------
414
//
415
// Function: uvm_string_to_bits
416
//
417
// Converts an input string to its bit-vector equivalent. Max bit-vector
418
// length is approximately 14000 characters.
419
//----------------------------------------------------------------------------
420
 
421
function logic[UVM_LARGE_STRING:0] uvm_string_to_bits(string str);
422
  $swrite(uvm_string_to_bits, "%0s", str);
423
endfunction
424
 
425
 
426
//----------------------------------------------------------------------------
427
//
428
// Function: uvm_bits_to_string
429
//
430
// Converts an input bit-vector to its string equivalent. Max bit-vector
431
// length is approximately 14000 characters.
432
//----------------------------------------------------------------------------
433
 
434
function string uvm_bits_to_string(logic [UVM_LARGE_STRING:0] str);
435
  $swrite(uvm_bits_to_string, "%0s", str);
436
endfunction
437
 
438
 
439
//----------------------------------------------------------------------------
440
//
441
// Task: uvm_wait_for_nba_region
442
//
443
// Callers of this task will not return until the NBA region, thus allowing
444
// other processes any number of delta cycles (#0) to settle out before
445
// continuing. See  for example usage.
446
//
447
//----------------------------------------------------------------------------
448
 
449
task uvm_wait_for_nba_region;
450
 
451
  string s;
452
 
453
  int nba;
454
  int next_nba;
455
 
456
  //If `included directly in a program block, can't use a non-blocking assign,
457
  //but it isn't needed since program blocks are in a separate region.
458
`ifndef UVM_NO_WAIT_FOR_NBA
459
  next_nba++;
460
  nba <= next_nba;
461
  @(nba);
462
`else
463
  repeat(`UVM_POUND_ZERO_COUNT) #0;
464
`endif
465
 
466
 
467
endtask
468
 
469
 
470
//----------------------------------------------------------------------------
471
//
472
// Function: uvm_split_string
473
//
474
// Returns a queue of strings, ~values~, that is the result of the ~str~ split
475
// based on the ~sep~.  For example:
476
//
477
//| uvm_split_string("1,on,false", ",", splits);
478
//
479
// Results in the 'splits' queue containing the three elements: 1, on and
480
// false.
481
//----------------------------------------------------------------------------
482
 
483
function automatic void uvm_split_string (string str, byte sep, ref string values[$]);
484
  int s = 0, e = 0;
485
  values.delete();
486
  while(e < str.len()) begin
487
    for(s=e; e
488
      if(str[e] == sep) break;
489
    if(s != e)
490
      values.push_back(str.substr(s,e-1));
491
    e++;
492
  end
493
endfunction
494
 
495
// Class: uvm_enum_wrapper#(T)
496
//
497
// The ~uvm_enum_wrapper#(T)~ class is a utility mechanism provided
498
// as a convenience to the end user.  It provides a 
499
// method which is the logical inverse of the System Verilog ~name~
500
// method which is built into all enumerations.
501
 
502
class uvm_enum_wrapper#(type T=uvm_active_passive_enum);
503
 
504
    protected static T map[string];
505
 
506
    // Function: from_name
507
    // Attempts to convert a string ~name~ to an enumerated value.
508
    //
509
    // If the conversion is successful, the method will return
510
    // 1, otherwise 0.
511
    //
512
    // Note that the ~name~ passed in to the method must exactly
513
    // match the value which would be produced by ~enum::name~, and
514
    // is case sensitive.
515
    //
516
    // For example:
517
    //| typedef uvm_enum_wrapper#(uvm_radix_enum) radix_wrapper;
518
    //| uvm_radix_enum r_v;
519
    //|
520
    //| // The following would return '0', as "foo" isn't a value
521
    //| // in uvm_radix_enum:
522
    //| radix_wrapper::from_name("foo", r_v);
523
    //|
524
    //| // The following would return '0', as "uvm_bin" isn't a value
525
    //| // in uvm_radix_enum (although the upper case "UVM_BIN" is):
526
    //| radix_wrapper::from_name("uvm_bin", r_v);
527
    //|
528
    //| // The following would return '1', and r_v would be set to
529
    //| // the value of UVM_BIN
530
    //| radix_wrapper::from_name("UVM_BIN", r_v);
531
    //
532
    static function bit from_name(string name, ref T value);
533
        if (map.size() == 0)
534
          m_init_map();
535
 
536
        if (map.exists(name)) begin
537
            value = map[name];
538
            return 1;
539
        end
540
        else begin
541
            return 0;
542
        end
543
    endfunction : from_name
544
 
545
    // Function- m_init_map
546
    // Initializes the name map, only needs to be performed once
547
    protected static function void m_init_map();
548
        T e = e.first();
549
        do
550
          begin
551
            map[e.name()] = e;
552
            e = e.next();
553
          end
554
        while (e != e.first());
555
    endfunction : m_init_map
556
 
557
    // Function- new
558
    // Prevents accidental instantiations
559
    protected function new();
560
    endfunction : new
561
 
562
endclass : uvm_enum_wrapper
563
 
564
 

powered by: WebSVN 2.1.0

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