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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [reg/] [uvm_reg_cbs.svh] - Blame information for rev 16

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
// -------------------------------------------------------------
3
//    Copyright 2004-2009 Synopsys, Inc.
4
//    Copyright 2010 Mentor Graphics Corporation
5
//    Copyright 2010 Cadence Design Systems, 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
typedef class uvm_reg;
25
typedef class uvm_mem;
26
typedef class uvm_reg_backdoor;
27
 
28
//------------------------------------------------------------------------------
29
// Title: Register Callbacks
30
//
31
// This section defines the base class used for all register callback
32
// extensions. It also includes pre-defined callback extensions for use on
33
// read-only and write-only registers.
34
//------------------------------------------------------------------------------
35
 
36
 
37
//------------------------------------------------------------------------------
38
// Class: uvm_reg_cbs
39
//
40
// Facade class for field, register, memory and backdoor
41
// access callback methods.
42
//------------------------------------------------------------------------------
43
 
44
virtual class uvm_reg_cbs extends uvm_callback;
45
 
46
   function new(string name = "uvm_reg_cbs");
47
      super.new(name);
48
   endfunction
49
 
50
 
51
   // Task: pre_write
52
   //
53
   // Called before a write operation.
54
   //
55
   // All registered ~pre_write~ callback methods are invoked after the
56
   // invocation of the ~pre_write~ method of associated object (,
57
   // , , or ). If the element being
58
   // written is a , all ~pre_write~ callback methods are invoked
59
   // before the contained .
60
   //
61
   // Backdoor - ,
62
   //             cbs for backdoor.
63
   //
64
   // Register - ,
65
   //             cbs for reg,
66
   //            then foreach field:
67
   //              ,
68
   //               cbs for field
69
   //
70
   // RegField - ,
71
   //             cbs for field
72
   //
73
   // Memory   - ,
74
   //             cbs for mem
75
   //
76
   // The ~rw~ argument holds information about the operation.
77
   //
78
   // - Modifying the ~value~ modifies the actual value written.
79
   //
80
   // - For memories, modifying the ~offset~ modifies the offset
81
   //   used in the operation.
82
   //
83
   // - For non-backdoor operations, modifying the access ~path~ or
84
   //   address ~map~ modifies the actual path or map used in the
85
   //   operation.
86
   //
87
   // If the ~rw.status~ is modified to anything other than ,
88
   // the operation is aborted.
89
   //
90
   // See  for details on ~rw~ information.
91
   //
92
   virtual task pre_write(uvm_reg_item rw); endtask
93
 
94
 
95
   // Task: post_write
96
   //
97
   // Called after a write operation.
98
   //
99
   // All registered ~post_write~ callback methods are invoked before the
100
   // invocation of the ~post_write~ method of the associated object (,
101
   // , , or ). If the element being
102
   // written is a , all ~post_write~ callback methods are invoked
103
   // before the contained .
104
   //
105
   // Summary of callback order:
106
   //
107
   // Backdoor -  cbs for backdoor,
108
   //            
109
   //
110
   // Register -  cbs for reg,
111
   //            ,
112
   //            then foreach field:
113
   //               cbs for field,
114
   //              
115
   //
116
   // RegField -  cbs for field,
117
   //            
118
   //
119
   // Memory   -  cbs for mem,
120
   //            
121
   //
122
   // The ~rw~ argument holds information about the operation.
123
   //
124
   // - Modifying the ~status~ member modifies the returned status.
125
   //
126
   // - Modifying the ~value~ or ~offset~ members has no effect, as
127
   //   the operation has already completed.
128
   //
129
   // See  for details on ~rw~ information.
130
   //
131
   virtual task post_write(uvm_reg_item rw); endtask
132
 
133
 
134
   // Task: pre_read
135
   //
136
   // Callback called before a read operation.
137
   //
138
   // All registered ~pre_read~ callback methods are invoked after the
139
   // invocation of the ~pre_read~ method of associated object (,
140
   // , , or ). If the element being
141
   // read is a , all ~pre_read~ callback methods are invoked before
142
   // the contained .
143
   //
144
   // Backdoor - ,
145
   //             cbs for backdoor
146
   //
147
   // Register - ,
148
   //             cbs for reg,
149
   //            then foreach field:
150
   //              ,
151
   //               cbs for field
152
   //
153
   // RegField - ,
154
   //             cbs for field
155
   //
156
   // Memory   - ,
157
   //             cbs for mem
158
   //
159
   // The ~rw~ argument holds information about the operation.
160
   //
161
   // - The ~value~ member of ~rw~ is not used has no effect if modified.
162
   //
163
   // - For memories, modifying the ~offset~ modifies the offset
164
   //   used in the operation.
165
   //
166
   // - For non-backdoor operations, modifying the access ~path~ or
167
   //   address ~map~ modifies the actual path or map used in the
168
   //   operation.
169
   //
170
   // If the ~rw.status~ is modified to anything other than ,
171
   // the operation is aborted.
172
   //
173
   // See  for details on ~rw~ information.
174
   //
175
   virtual task pre_read(uvm_reg_item rw); endtask
176
 
177
 
178
   // Task: post_read
179
   //
180
   // Callback called after a read operation.
181
   //
182
   // All registered ~post_read~ callback methods are invoked before the
183
   // invocation of the ~post_read~ method of the associated object (,
184
   // , , or ). If the element being read
185
   // is a , all ~post_read~ callback methods are invoked before the
186
   // contained .
187
   //
188
   // Backdoor -  cbs for backdoor,
189
   //            
190
   //
191
   // Register -  cbs for reg,
192
   //            ,
193
   //            then foreach field:
194
   //               cbs for field,
195
   //              
196
   //
197
   // RegField -  cbs for field,
198
   //            
199
   //
200
   // Memory   -  cbs for mem,
201
   //            
202
   //
203
   // The ~rw~ argument holds information about the operation.
204
   //
205
   // - Modifying the readback ~value~ or ~status~ modifies the actual
206
   //   returned value and status.
207
   //
208
   // - Modifying the ~value~ or ~offset~ members has no effect, as
209
   //   the operation has already completed.
210
   //
211
   // See  for details on ~rw~ information.
212
   //
213
   virtual task post_read(uvm_reg_item rw); endtask
214
 
215
 
216
   // Task: post_predict
217
   //
218
   // Called by the  method
219
   // after a successful UVM_PREDICT_READ or UVM_PREDICT_WRITE prediction.
220
   //
221
   // ~previous~ is the previous value in the mirror and
222
   // ~value~ is the latest predicted value. Any change to ~value~ will
223
   // modify the predicted mirror value.
224
   //
225
   virtual function void post_predict(input uvm_reg_field  fld,
226
                                      input uvm_reg_data_t previous,
227
                                      inout uvm_reg_data_t value,
228
                                      input uvm_predict_e  kind,
229
                                      input uvm_path_e     path,
230
                                      input uvm_reg_map    map);
231
   endfunction
232
 
233
 
234
   // Function: encode
235
   //
236
   // Data encoder
237
   //
238
   // The registered callback methods are invoked in order of registration
239
   // after all the ~pre_write~ methods have been called.
240
   // The encoded data is passed through each invocation in sequence.
241
   // This allows the ~pre_write~ methods to deal with clear-text data.
242
   //
243
   // By default, the data is not modified.
244
   //
245
   virtual function void encode(ref uvm_reg_data_t data[]);
246
   endfunction
247
 
248
 
249
   // Function: decode
250
   //
251
   // Data decode
252
   //
253
   // The registered callback methods are invoked in ~reverse order~
254
   // of registration before all the ~post_read~ methods are called.
255
   // The decoded data is passed through each invocation in sequence.
256
   // This allows the ~post_read~ methods to deal with clear-text data.
257
   //
258
   // The reversal of the invocation order is to allow the decoding
259
   // of the data to be performed in the opposite order of the encoding
260
   // with both operations specified in the same callback extension.
261
   //
262
   // By default, the data is not modified.
263
   //
264
   virtual function void decode(ref uvm_reg_data_t data[]);
265
   endfunction
266
 
267
 
268
 
269
endclass
270
 
271
 
272
//------------------
273
// Section: Typedefs
274
//------------------
275
 
276
 
277
// Type: uvm_reg_cb
278
//
279
// Convenience callback type declaration for registers
280
//
281
// Use this declaration to register the register callbacks rather than
282
// the more verbose parameterized class
283
//
284
typedef uvm_callbacks#(uvm_reg, uvm_reg_cbs) uvm_reg_cb;
285
 
286
 
287
// Type: uvm_reg_cb_iter
288
//
289
// Convenience callback iterator type declaration for registers
290
//
291
// Use this declaration to iterate over registered register callbacks
292
// rather than the more verbose parameterized class
293
//
294
typedef uvm_callback_iter#(uvm_reg, uvm_reg_cbs) uvm_reg_cb_iter;
295
 
296
 
297
// Type: uvm_reg_bd_cb
298
//
299
// Convenience callback type declaration for backdoor
300
//
301
// Use this declaration to register register backdoor callbacks rather than
302
// the more verbose parameterized class
303
//
304
typedef uvm_callbacks#(uvm_reg_backdoor, uvm_reg_cbs) uvm_reg_bd_cb;
305
 
306
 
307
// Type: uvm_reg_bd_cb_iter
308
// Convenience callback iterator type declaration for backdoor
309
//
310
// Use this declaration to iterate over registered register backdoor callbacks
311
// rather than the more verbose parameterized class
312
//
313
 
314
typedef uvm_callback_iter#(uvm_reg_backdoor, uvm_reg_cbs) uvm_reg_bd_cb_iter;
315
 
316
 
317
// Type: uvm_mem_cb
318
//
319
// Convenience callback type declaration for memories
320
//
321
// Use this declaration to register memory callbacks rather than
322
// the more verbose parameterized class
323
//
324
typedef uvm_callbacks#(uvm_mem, uvm_reg_cbs) uvm_mem_cb;
325
 
326
 
327
// Type: uvm_mem_cb_iter
328
//
329
// Convenience callback iterator type declaration for memories
330
//
331
// Use this declaration to iterate over registered memory callbacks
332
// rather than the more verbose parameterized class
333
//
334
typedef uvm_callback_iter#(uvm_mem, uvm_reg_cbs) uvm_mem_cb_iter;
335
 
336
 
337
// Type: uvm_reg_field_cb
338
//
339
// Convenience callback type declaration for fields
340
//
341
// Use this declaration to register field callbacks rather than
342
// the more verbose parameterized class
343
//
344
typedef uvm_callbacks#(uvm_reg_field, uvm_reg_cbs) uvm_reg_field_cb;
345
 
346
 
347
// Type: uvm_reg_field_cb_iter
348
//
349
// Convenience callback iterator type declaration for fields
350
//
351
// Use this declaration to iterate over registered field callbacks
352
// rather than the more verbose parameterized class
353
//
354
typedef uvm_callback_iter#(uvm_reg_field, uvm_reg_cbs) uvm_reg_field_cb_iter;
355
 
356
 
357
//-----------------------------
358
// Group: Predefined Extensions
359
//-----------------------------
360
 
361
//------------------------------------------------------------------------------
362
// Class: uvm_reg_read_only_cbs
363
//
364
// Pre-defined register callback method for read-only registers
365
// that will issue an error if a write() operation is attempted.
366
//
367
//------------------------------------------------------------------------------
368
 
369
class uvm_reg_read_only_cbs extends uvm_reg_cbs;
370
 
371
   function new(string name = "uvm_reg_read_only_cbs");
372
      super.new(name);
373
   endfunction
374
 
375
   `uvm_object_utils(uvm_reg_read_only_cbs)
376
 
377
 
378
   // Function: pre_write
379
   //
380
   // Produces an error message and sets status to .
381
   //
382
   virtual task pre_write(uvm_reg_item rw);
383
      string name = rw.element.get_full_name();
384
 
385
      if (rw.status != UVM_IS_OK)
386
         return;
387
 
388
      if (rw.element_kind == UVM_FIELD) begin
389
         uvm_reg_field fld;
390
         uvm_reg rg;
391
         $cast(fld, rw.element);
392
         rg = fld.get_parent();
393
         name = rg.get_full_name();
394
      end
395
 
396
      `uvm_error("UVM/REG/READONLY",
397
                 {name, " is read-only. Cannot call write() method."});
398
 
399
      rw.status = UVM_NOT_OK;
400
   endtask
401
 
402
   local static uvm_reg_read_only_cbs m_me;
403
   local static function uvm_reg_read_only_cbs get();
404
      if (m_me == null) m_me = new;
405
      return m_me;
406
   endfunction
407
 
408
 
409
   // Function: add
410
   //
411
   // Add this callback to the specified register and its contained fields.
412
   //
413
   static function void add(uvm_reg rg);
414
      uvm_reg_field flds[$];
415
 
416
      uvm_reg_cb::add(rg, get());
417
      rg.get_fields(flds);
418
      foreach (flds[i]) begin
419
         uvm_reg_field_cb::add(flds[i], get());
420
      end
421
   endfunction
422
 
423
 
424
   // Function: remove
425
   //
426
   // Remove this callback from the specified register and its contained fields.
427
   //
428
   static function void remove(uvm_reg rg);
429
      uvm_reg_cb_iter cbs = new(rg);
430
      uvm_reg_field flds[$];
431
 
432
      void'(cbs.first());
433
      while (cbs.get_cb() != get()) begin
434
         if (cbs.get_cb() == null)
435
            return;
436
         void'(cbs.next());
437
      end
438
      uvm_reg_cb::delete(rg, get());
439
      rg.get_fields(flds);
440
      foreach (flds[i]) begin
441
         uvm_reg_field_cb::delete(flds[i], get());
442
      end
443
   endfunction
444
endclass
445
 
446
 
447
//------------------------------------------------------------------------------
448
// Class: uvm_reg_write_only_cbs
449
//
450
// Pre-defined register callback method for write-only registers
451
// that will issue an error if a read() operation is attempted.
452
//
453
//------------------------------------------------------------------------------
454
 
455
class uvm_reg_write_only_cbs extends uvm_reg_cbs;
456
 
457
   function new(string name = "uvm_reg_write_only_cbs");
458
      super.new(name);
459
   endfunction
460
 
461
   `uvm_object_utils(uvm_reg_write_only_cbs)
462
 
463
   // Function: pre_read
464
   //
465
   // Produces an error message and sets status to .
466
   //
467
   virtual task pre_read(uvm_reg_item rw);
468
      string name = rw.element.get_full_name();
469
 
470
      if (rw.status != UVM_IS_OK)
471
         return;
472
 
473
      if (rw.element_kind == UVM_FIELD) begin
474
         uvm_reg_field fld;
475
         uvm_reg rg;
476
         $cast(fld, rw.element);
477
         rg = fld.get_parent();
478
         name = rg.get_full_name();
479
      end
480
 
481
      `uvm_error("UVM/REG/WRTEONLY",
482
                 {name, " is write-only. Cannot call read() method."});
483
 
484
      rw.status = UVM_NOT_OK;
485
   endtask
486
 
487
   local static uvm_reg_write_only_cbs m_me;
488
   local static function uvm_reg_write_only_cbs get();
489
      if (m_me == null) m_me = new;
490
      return m_me;
491
   endfunction
492
 
493
 
494
   // Function: add
495
   //
496
   // Add this callback to the specified register and its contained fields.
497
   //
498
   static function void add(uvm_reg rg);
499
      uvm_reg_field flds[$];
500
 
501
      uvm_reg_cb::add(rg, get());
502
      rg.get_fields(flds);
503
      foreach (flds[i]) begin
504
         uvm_reg_field_cb::add(flds[i], get());
505
      end
506
   endfunction
507
 
508
 
509
   // Function: remove
510
   //
511
   // Remove this callback from the specified register and its contained fields.
512
   //
513
   static function void remove(uvm_reg rg);
514
      uvm_reg_cb_iter cbs = new(rg);
515
      uvm_reg_field flds[$];
516
 
517
      void'(cbs.first());
518
      while (cbs.get_cb() != get()) begin
519
         if (cbs.get_cb() == null)
520
            return;
521
         void'(cbs.next());
522
      end
523
      uvm_reg_cb::delete(rg, get());
524
      rg.get_fields(flds);
525
      foreach (flds[i]) begin
526
         uvm_reg_field_cb::delete(flds[i], get());
527
      end
528
   endfunction
529
endclass

powered by: WebSVN 2.1.0

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