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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [comps/] [uvm_random_stimulus.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-2010 Cadence Design Systems, Inc.
5
//   Copyright 2010 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
//------------------------------------------------------------------------------
24
// CLASS: uvm_random_stimulus #(T)
25
//
26
// A general purpose unidirectional random stimulus class.
27
//
28
// The uvm_random_stimulus class generates streams of T transactions. These streams
29
// may be generated by the randomize method of T, or the randomize method of
30
// one of its subclasses.  The stream may go indefinitely, until terminated
31
// by a call to stop_stimulus_generation, or we may specify the maximum number
32
// of transactions to be generated.
33
//
34
// By using inheritance, we can add directed initialization or tidy up after
35
// random stimulus generation. Simply extend the class and define the run task,
36
// calling super.run() when you want to begin the random stimulus phase of
37
// simulation.
38
//
39
// While very useful in its own right, this component can also be used as a
40
// template for defining other stimulus generators, or it can be extended to
41
// add additional stimulus generation methods and to simplify test writing.
42
//
43
//------------------------------------------------------------------------------
44
 
45
class uvm_random_stimulus #(type T=uvm_transaction) extends uvm_component;
46
 
47
  const static string type_name = "uvm_random_stimulus #(T)";
48
 
49
  typedef uvm_random_stimulus #(T) this_type;
50
  `uvm_component_param_utils(this_type)
51
 
52
  // Port: blocking_put_port
53
  //
54
  // The blocking_put_port is used to send the generated stimulus to the rest
55
  // of the testbench.
56
 
57
  uvm_blocking_put_port #(T) blocking_put_port;
58
 
59
 
60
  // Function: new
61
  //
62
  // Creates a new instance of a specialization of this class.
63
  // Also, displays the random state obtained from a get_randstate call.
64
  // In subsequent simulations, set_randstate can be called with the same
65
  // value to reproduce the same sequence of transactions.
66
 
67
  function new(string name, uvm_component parent);
68
 
69
    super.new(name, parent);
70
 
71
    blocking_put_port=new("blocking_put_port", this);
72
 
73
    uvm_report_info("uvm_stimulus", {"rand state is ", get_randstate()});
74
 
75
  endfunction
76
 
77
 
78
  local bit m_stop;
79
 
80
 
81
  // Function: generate_stimulus
82
  //
83
  // Generate up to max_count transactions of type T.
84
  // If t is not specified, a default instance of T is allocated and used.
85
  // If t is specified, that transaction is used when randomizing. It must
86
  // be a subclass of T.
87
  //
88
  // max_count is the maximum number of transactions to be
89
  // generated. A value of zero indicates no maximum - in
90
  // this case, generate_stimulus will go on indefinitely
91
  // unless stopped by some other process
92
  //
93
  // The transactions are cloned before they are sent out
94
  // over the blocking_put_port
95
 
96
  virtual task generate_stimulus(T t=null, int max_count=0);
97
 
98
    T temp;
99
 
100
    if (t == null)
101
      t = new;
102
 
103
    for (int i=0; (max_count == 0 || i < max_count) && !m_stop; i++) begin
104
 
105
       if (! t.randomize() )
106
          uvm_report_warning ("RANDFL", "Randomization failed in generate_stimulus");
107
 
108
       $cast(temp, t.clone());
109
       uvm_report_info("stimulus generation", temp.convert2string());
110
       blocking_put_port.put(temp);
111
    end
112
  endtask
113
 
114
 
115
  // Function: stop_stimulus_generation
116
  //
117
  // Stops the generation of stimulus.
118
  // If a subclass of this method has forked additional
119
  // processes, those processes will also need to be
120
  // stopped in an overridden version of this method
121
 
122
  virtual function void stop_stimulus_generation;
123
    m_stop = 1;
124
  endfunction
125
 
126
 
127
  virtual function string get_type_name();
128
    return type_name;
129
  endfunction
130
 
131
endclass : uvm_random_stimulus

powered by: WebSVN 2.1.0

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