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

Subversion Repositories uart2bus_testbench

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 HanySalah
//
2
//------------------------------------------------------------------------------
3
//   Copyright 2007-2010 Mentor Graphics Corporation
4
//   Copyright 2007-2011 Cadence Design Systems, Inc.
5
//   Copyright 2010 Synopsys, Inc.
6
//   Copyright 2014 NVIDIA Corportation
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
//
26
// CLASS: uvm_event_base
27
//
28
// The uvm_event_base class is an abstract wrapper class around the SystemVerilog event
29
// construct.  It provides some additional services such as setting callbacks
30
// and maintaining the number of waiters.
31
//
32
//------------------------------------------------------------------------------
33
 
34
virtual class uvm_event_base extends uvm_object;
35
        const static string type_name = "uvm_event_base";
36
        protected event      m_event;
37
        protected int        num_waiters;
38
        protected bit        on;
39
        protected time       trigger_time=0;
40
        protected uvm_event_callback  callbacks[$];
41
 
42
        // Function: new
43
        //
44
        // Creates a new event object.
45
 
46
        function new (string name="");
47
                super.new(name);
48
        endfunction
49
 
50
        //---------//
51
        // waiting //
52
        //---------//
53
 
54
        // Task: wait_on
55
        //
56
        // Waits for the event to be activated for the first time.
57
        //
58
        // If the event has already been triggered, this task returns immediately.
59
        // If ~delta~ is set, the caller will be forced to wait a single delta #0
60
        // before returning. This prevents the caller from returning before
61
        // previously waiting processes have had a chance to resume.
62
        //
63
        // Once an event has been triggered, it will be remain "on" until the event
64
        // is .
65
 
66
        virtual task wait_on (bit delta = 0);
67
                if (on) begin
68
                        if (delta)
69
                                #0;
70
                        return;
71
                end
72
                num_waiters++;
73
                @on;
74
        endtask
75
 
76
 
77
        // Task: wait_off
78
        //
79
        // If the event has already triggered and is "on", this task waits for the
80
        // event to be turned "off" via a call to .
81
        //
82
        // If the event has not already been triggered, this task returns immediately.
83
        // If ~delta~ is set, the caller will be forced to wait a single delta #0
84
        // before returning. This prevents the caller from returning before
85
        // previously waiting processes have had a chance to resume.
86
 
87
        virtual task wait_off (bit delta = 0);
88
                if (!on) begin
89
                        if (delta)
90
                                #0;
91
                        return;
92
                end
93
                num_waiters++;
94
                @on;
95
        endtask
96
 
97
 
98
        // Task: wait_trigger
99
        //
100
        // Waits for the event to be triggered.
101
        //
102
        // If one process calls wait_trigger in the same delta as another process
103
        // calls , a race condition occurs. If the call to wait occurs
104
        // before the trigger, this method will return in this delta. If the wait
105
        // occurs after the trigger, this method will not return until the next
106
        // trigger, which may never occur and thus cause deadlock.
107
 
108
        virtual task wait_trigger ();
109
                num_waiters++;
110
                @m_event;
111
        endtask
112
 
113
 
114
        // Task: wait_ptrigger
115
        //
116
        // Waits for a persistent trigger of the event. Unlike , this
117
        // views the trigger as persistent within a given time-slice and thus avoids
118
        // certain race conditions. If this method is called after the trigger but
119
        // within the same time-slice, the caller returns immediately.
120
 
121
        virtual task wait_ptrigger ();
122
                if (m_event.triggered)
123
                        return;
124
                num_waiters++;
125
                @m_event;
126
        endtask
127
 
128
 
129
        // Function: get_trigger_time
130
        //
131
        // Gets the time that this event was last triggered. If the event has not been
132
        // triggered, or the event has been reset, then the trigger time will be 0.
133
 
134
        virtual function time get_trigger_time ();
135
                return trigger_time;
136
        endfunction
137
 
138
 
139
        //-------//
140
        // state //
141
        //-------//
142
 
143
        // Function: is_on
144
        //
145
        // Indicates whether the event has been triggered since it was last reset.
146
        //
147
        // A return of 1 indicates that the event has triggered.
148
 
149
        virtual function bit is_on ();
150
                return (on == 1);
151
        endfunction
152
 
153
 
154
        // Function: is_off
155
        //
156
        // Indicates whether the event has been triggered or been reset.
157
        //
158
        // A return of 1 indicates that the event has not been triggered.
159
 
160
        virtual function bit is_off ();
161
                return (on == 0);
162
        endfunction
163
 
164
 
165
        // Function: reset
166
        //
167
        // Resets the event to its off state. If ~wakeup~ is set, then all processes
168
        // currently waiting for the event are activated before the reset.
169
        //
170
        // No callbacks are called during a reset.
171
 
172
        virtual function void reset (bit wakeup = 0);
173
                event e;
174
                if (wakeup)
175
                        ->m_event;
176
                m_event = e;
177
                num_waiters = 0;
178
                on = 0;
179
                trigger_time = 0;
180
        endfunction
181
 
182
 
183
 
184
        //--------------//
185
        // waiters list //
186
        //--------------//
187
 
188
        // Function: cancel
189
        //
190
        // Decrements the number of waiters on the event.
191
        //
192
        // This is used if a process that is waiting on an event is disabled or
193
        // activated by some other means.
194
 
195
        virtual function void cancel ();
196
                if (num_waiters > 0)
197
                        num_waiters--;
198
        endfunction
199
 
200
 
201
        // Function: get_num_waiters
202
        //
203
        // Returns the number of processes waiting on the event.
204
 
205
        virtual function int get_num_waiters ();
206
                return num_waiters;
207
        endfunction
208
 
209
 
210
        virtual function string get_type_name();
211
                return type_name;
212
        endfunction
213
 
214
 
215
        virtual function void do_print (uvm_printer printer);
216
                printer.print_field_int("num_waiters", num_waiters, $bits(num_waiters), UVM_DEC, ".", "int");
217
                printer.print_field_int("on", on, $bits(on), UVM_BIN, ".", "bit");
218
                printer.print_time("trigger_time", trigger_time);
219
                printer.m_scope.down("callbacks");
220
                foreach(callbacks[e]) begin
221
                        printer.print_object($sformatf("[%0d]",e), callbacks[e], "[");
222
                end
223
                printer.m_scope.up();
224
        endfunction
225
 
226
 
227
        virtual function void do_copy (uvm_object rhs);
228
                uvm_event_base e;
229
                super.do_copy(rhs);
230
                if(!$cast(e, rhs) || (e==null)) return;
231
 
232
                m_event = e.m_event;
233
                num_waiters = e.num_waiters;
234
                on = e.on;
235
                trigger_time = e.trigger_time;
236
                callbacks.delete();
237
                callbacks = e.callbacks;
238
 
239
        endfunction
240
 
241
endclass
242
 
243
 
244
//------------------------------------------------------------------------------
245
//
246
// CLASS: uvm_event#(T)
247
//
248
// The uvm_event class is an extension of the abstract uvm_event_base class.
249
//
250
// The optional parameter ~T~ allows the user to define a data type which
251
// can be passed during an event trigger.
252
//------------------------------------------------------------------------------
253
 
254
class uvm_event#(type T=uvm_object) extends uvm_event_base;
255
 
256
        const static string type_name = "uvm_event";
257
 
258
        local T trigger_data;
259
 
260
        // Function: new
261
        //
262
        // Creates a new event object.
263
 
264
        function new (string name="");
265
                super.new(name);
266
        endfunction
267
 
268
 
269
        // Task: wait_trigger_data
270
        //
271
        // This method calls  followed by .
272
 
273
        virtual task wait_trigger_data (output T data);
274
                wait_trigger();
275
                data = get_trigger_data();
276
        endtask
277
 
278
 
279
        // Task: wait_ptrigger_data
280
        //
281
        // This method calls  followed by .
282
 
283
        virtual task wait_ptrigger_data (output T data);
284
                wait_ptrigger();
285
                data = get_trigger_data();
286
        endtask
287
 
288
 
289
        //------------//
290
        // triggering //
291
        //------------//
292
 
293
        // Function: trigger
294
        //
295
        // Triggers the event, resuming all waiting processes.
296
        //
297
        // An optional ~data~ argument can be supplied with the enable to provide
298
        // trigger-specific information.
299
 
300
        virtual function void trigger (T data=null);
301
                int skip;
302
                skip=0;
303
                if (callbacks.size()) begin
304
                        for (int i=0;i
305
                                uvm_event_callback#(T) tmp=callbacks[i];
306
                                skip = skip + tmp.pre_trigger(this,data);
307
                        end
308
                end
309
                if (skip==0) begin
310
                        ->m_event;
311
                        if (callbacks.size()) begin
312
                                for (int i=0;i
313
                                        uvm_event_callback#(T) tmp=callbacks[i];
314
                                        tmp.post_trigger(this,data);
315
                                end
316
                        end
317
                        num_waiters = 0;
318
                        on = 1;
319
                        trigger_time = $realtime;
320
                        trigger_data = data;
321
                end
322
        endfunction
323
 
324
 
325
        // Function: get_trigger_data
326
        //
327
        // Gets the data, if any, provided by the last call to .
328
 
329
        virtual function T get_trigger_data ();
330
                return trigger_data;
331
        endfunction
332
 
333
        virtual function string get_type_name();
334
                return type_name;
335
        endfunction
336
 
337
                //-----------//
338
        // callbacks //
339
        //-----------//
340
 
341
        // Function: add_callback
342
        //
343
        // Registers a callback object, ~cb~, with this event. The callback object
344
        // may include pre_trigger and post_trigger functionality. If ~append~ is set
345
        // to 1, the default, ~cb~ is added to the back of the callback list. Otherwise,
346
        // ~cb~ is placed at the front of the callback list.
347
 
348
        virtual function void add_callback (uvm_event_callback#(T) cb, bit append=1);
349
                for (int i=0;i
350
                        if (cb == callbacks[i]) begin
351
                                uvm_report_warning("CBRGED","add_callback: Callback already registered. Ignoring.", UVM_NONE);
352
                                return;
353
                        end
354
                end
355
                if (append)
356
                        callbacks.push_back(cb);
357
                else
358
                        callbacks.push_front(cb);
359
        endfunction
360
 
361
 
362
        // Function: delete_callback
363
        //
364
        // Unregisters the given callback, ~cb~, from this event.
365
 
366
        virtual function void delete_callback (uvm_event_callback#(T) cb);
367
                for (int i=0;i
368
                        if (cb == callbacks[i]) begin
369
                                callbacks.delete(i);
370
                                return;
371
                        end
372
                end
373
                uvm_report_warning("CBNTFD", "delete_callback: Callback not found. Ignoring delete request.", UVM_NONE);
374
        endfunction
375
 
376
        virtual function void do_print (uvm_printer printer);
377
                super.do_print(printer);
378
                printer.print_object("trigger_data", trigger_data);
379
        endfunction
380
 
381
        virtual function void do_copy (uvm_object rhs);
382
                uvm_event#(T) e;
383
                super.do_copy(rhs);
384
                if(!$cast(e, rhs) || (e==null)) return;
385
                trigger_data = e.trigger_data;
386
        endfunction // do_copy
387
 
388
        virtual function uvm_object create(string name="");
389
                uvm_event#(T) v;
390
                v=new(name);
391
                return v;
392
        endfunction
393
 
394
endclass

powered by: WebSVN 2.1.0

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