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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [seq/] [uvm_sequence_builtin.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
//   Copyright 2010 Paradigm-works, Inc.
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
`ifndef UVM_NO_DEPRECATED
25
 
26
//------------------------------------------------------------------------------
27
// Title- Predefined Sequences
28
//
29
// This section defines several sequences that ship with the UVM library.
30
//------------------------------------------------------------------------------
31
 
32
//------------------------------------------------------------------------------
33
//
34
// CLASS- uvm_random_sequence
35
//
36
// This sequence randomly selects and executes a sequence from the sequencer's
37
// sequence library, excluding uvm_random_sequence itself, and
38
// uvm_exhaustive_sequence.
39
//
40
// The uvm_random_sequence class is a built-in sequence that is preloaded into
41
// every sequencer's sequence library with the name "uvm_random_sequence".
42
//
43
// The number of selections and executions is determined by the count property
44
// of the sequencer (or virtual sequencer) on which uvm_random_sequence is
45
// operating. See  for more information.
46
//
47
//------------------------------------------------------------------------------
48
 
49
class uvm_random_sequence extends uvm_sequence #(uvm_sequence_item);
50
 
51
  rand protected int unsigned l_count=-1;
52
  local int unsigned l_exhaustive_seq_kind;
53
  local int unsigned max_kind;
54
  rand local int unsigned l_kind;
55
  protected bit m_success;
56
 
57
// Function- get_count
58
//
59
// Returns the count of the number of sub-sequences which are randomly generated.
60
// By default, count is equal to the value from the sequencer's count variable.
61
// However, if the sequencer's count variable is -1, then a random value between
62
// 0 and sequencer.max_random_count (exclusive) is chosen. The sequencer's
63
// count variable is subsequently reset to the random value that was used. If
64
// get_count() is call before the sequence has started, the return value will
65
// be sequencer.count, which may be -1.
66
 
67
function int unsigned get_count();
68
  if(l_count == -1)
69
    return m_sequencer.count;
70
  return l_count;
71
endfunction
72
 
73
// new
74
// ---
75
 
76
function new(string name="uvm_random_sequence");
77
  super.new(name);
78
endfunction
79
 
80
 
81
// body
82
// ----
83
 
84
task body();
85
  pick_sequence.constraint_mode(0);
86
  if (m_sequencer.count == -1) begin
87
    if (!randomize(l_count) with { l_count > 0 &&
88
                                   l_count < m_sequencer.max_random_count; })
89
      uvm_report_fatal("RANDSEQ", "Randomization for l_count failed in random sequence body", UVM_NONE);
90
    m_sequencer.count = l_count;
91
  end
92
  else
93
    l_count = m_sequencer.count;
94
  max_kind = m_sequencer.sequences.size();
95
  l_exhaustive_seq_kind = m_sequencer.get_seq_kind("uvm_exhaustive_sequence");
96
  repeat (l_count) begin
97
    if (!randomize(l_kind) with { l_kind > l_exhaustive_seq_kind &&
98
      l_kind < max_kind; })
99
      uvm_report_fatal("RANDSEQ", "Randomization for l_kind failed in random sequence body", UVM_NONE);
100
    do_sequence_kind(l_kind);
101
  end
102
  m_sequencer.m_random_count++;
103
  pick_sequence.constraint_mode(1);
104
endtask
105
 
106
 
107
//Implement data functions
108
function void do_copy (uvm_object rhs);
109
  uvm_random_sequence seq;
110
  if(rhs==null) return;
111
  if(!$cast(seq, rhs)) return;
112
  l_count = seq.l_count;
113
endfunction
114
 
115
function bit do_compare (uvm_object rhs, uvm_comparer comparer);
116
  uvm_random_sequence seq;
117
  do_compare = 1;
118
  if(rhs==null) return 0;
119
  if(!$cast(seq, rhs)) return 0;
120
  do_compare &= comparer.compare_field_int("l_count", l_count, seq.l_count,
121
    $bits(l_count));
122
endfunction
123
 
124
function void do_print (uvm_printer printer);
125
  printer.print_field_int("l_count", l_count, $bits(l_count));
126
endfunction
127
 
128
function void do_record (uvm_recorder recorder);
129
  recorder.record_field_int("l_count", l_count, $bits(l_count));
130
endfunction // void
131
 
132
  function uvm_object create (string name="");
133
    uvm_random_sequence i; i=new(name);
134
    return i;
135
  endfunction
136
 
137
  virtual function string get_type_name();
138
     return "uvm_random_sequence";
139
  endfunction
140
 
141
  // Macro for factory creation
142
  `uvm_object_registry(uvm_random_sequence, "uvm_random_sequence")
143
 
144
endclass
145
 
146
 
147
//------------------------------------------------------------------------------
148
//
149
// CLASS- uvm_exhaustive_sequence
150
//
151
// This sequence randomly selects and executes each sequence from the
152
// sequencer's sequence library once, excluding itself and uvm_random_sequence.
153
//
154
// The uvm_exhaustive_sequence class is a built-in sequence that is preloaded
155
// into every sequencer's sequence library with the name
156
// "uvm_exaustive_sequence".
157
//
158
//------------------------------------------------------------------------------
159
 
160
class uvm_exhaustive_sequence extends uvm_sequence #(uvm_sequence_item);
161
 
162
  rand protected int unsigned l_count;
163
  local int unsigned l_exhaustive_seq_kind;
164
  local int unsigned max_kind;
165
  randc local bit[9:0] l_kind;
166
  protected bit m_success;
167
 
168
// new
169
// ---
170
 
171
function new(string name="uvm_exhaustive_sequence");
172
  super.new(name);
173
endfunction
174
 
175
 
176
// body
177
// ----
178
 
179
task body();
180
    int i;
181
 
182
  pick_sequence.constraint_mode(0);
183
    //$display("In exhaustive sequence body, num_sequences: %0d", m_sequencer.num_sequences());
184
 
185
 
186
    //for (i = 0; i < m_sequencer.num_sequences(); i++ ) begin
187
    //  $display("seq: %0d: %s", i, m_sequencer.sequences[i]);
188
    //  $display("get_seq_kind[%s]: %0d", m_sequencer.sequences[i], get_seq_kind(m_sequencer.sequences[i]));
189
    //end
190
 
191
 
192
  l_count = m_sequencer.sequences.size() - 2;
193
  max_kind = m_sequencer.sequences.size();
194
  l_exhaustive_seq_kind = m_sequencer.get_seq_kind("uvm_exhaustive_sequence");
195
  repeat (l_count) begin
196
    if (!randomize(l_kind) with { l_kind > l_exhaustive_seq_kind;
197
      l_kind < max_kind; }) // l_kind is randc
198
      uvm_report_fatal("RANDSEQ", "Randomization for l_kind failed in exhaustive sequence body", UVM_NONE);
199
 
200
    //$display ("Chosen l_kind: %0d", l_kind);
201
    do_sequence_kind(l_kind);
202
  end
203
  m_sequencer.m_exhaustive_count++;
204
  pick_sequence.constraint_mode(1);
205
endtask
206
 
207
 
208
//Implement data functions
209
function void do_copy (uvm_object rhs);
210
  uvm_exhaustive_sequence seq;
211
  if(rhs==null) return;
212
  if(!$cast(seq, rhs)) return;
213
  l_count = seq.l_count;
214
endfunction
215
 
216
function bit do_compare (uvm_object rhs, uvm_comparer comparer);
217
  uvm_exhaustive_sequence seq;
218
  do_compare = 1;
219
  if(rhs==null) return 0;
220
  if(!$cast(seq, rhs)) return 0;
221
  do_compare &= comparer.compare_field_int("l_count", l_count, seq.l_count,
222
    $bits(l_count));
223
endfunction
224
 
225
function void do_print (uvm_printer printer);
226
  printer.print_field_int("l_count", l_count, $bits(l_count));
227
endfunction
228
 
229
function void do_record (uvm_recorder recorder);
230
  recorder.record_field_int("l_count", l_count, $bits(l_count));
231
endfunction // void
232
 
233
function uvm_object create (string name="");
234
  uvm_exhaustive_sequence i; i=new(name);
235
  return i;
236
endfunction
237
 
238
virtual function string get_type_name();
239
   return "uvm_exhaustive_sequence";
240
endfunction
241
 
242
// Macro for factory creation
243
`uvm_object_registry(uvm_exhaustive_sequence, "uvm_exhaustive_sequence")
244
 
245
endclass
246
 
247
 
248
//------------------------------------------------------------------------------
249
//
250
// CLASS- uvm_simple_sequence
251
//
252
// This sequence simply executes a single sequence item.
253
//
254
// The item parameterization of the sequencer on which the uvm_simple_sequence
255
// is executed defines the actual type of the item executed.
256
//
257
// The uvm_simple_sequence class is a built-in sequence that is preloaded into
258
// every sequencer's sequence library with the name "uvm_simple_sequence".
259
//
260
// See  for more information on running sequences.
261
//
262
//------------------------------------------------------------------------------
263
 
264
class uvm_simple_sequence extends uvm_sequence #(uvm_sequence_item);
265
 
266
  protected rand uvm_sequence_item item;
267
 
268
  // new
269
  // ---
270
  function new (string name="uvm_simple_sequence");
271
    super.new(name);
272
    // Initialized to avoid potential warnings if this class instance
273
    // is randomized without calling its body()
274
    item = new;
275
  endfunction
276
 
277
  // body
278
  // ----
279
  task body();
280
    `uvm_do(item)
281
    m_sequencer.m_simple_count++;
282
  endtask
283
 
284
  function uvm_object create (string name="");
285
    uvm_simple_sequence i;
286
    i=new(name);
287
    return i;
288
  endfunction
289
 
290
  virtual function string get_type_name();
291
     return "uvm_simple_sequence";
292
  endfunction
293
 
294
  // Macro for factory creation
295
  `uvm_object_registry(uvm_simple_sequence, "uvm_simple_sequence")
296
 
297
endclass
298
 
299
`endif // UVM_NO_DEPRECATED

powered by: WebSVN 2.1.0

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