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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [tlm1/] [uvm_tlm_fifos.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
typedef class uvm_tlm_event;
24
 
25
//------------------------------------------------------------------------------
26
//
27
// Title: TLM FIFO Classes
28
//
29
// This section defines TLM-based FIFO classes.
30
//
31
//------------------------------------------------------------------------------
32
 
33
//------------------------------------------------------------------------------
34
//
35
// Class: uvm_tlm_fifo#(T)
36
//
37
// This class provides storage of transactions between two independently running
38
// processes. Transactions are put into the FIFO via the ~put_export~.
39
// transactions are fetched from the FIFO in the order they arrived via the
40
// ~get_peek_export~. The ~put_export~ and ~get_peek_export~ are inherited from
41
// the  super class, and the interface methods provided by
42
// these exports are defined by the  class.
43
//
44
//------------------------------------------------------------------------------
45
 
46
class uvm_tlm_fifo #(type T=int) extends uvm_tlm_fifo_base #(T);
47
 
48
  const static string type_name = "uvm_tlm_fifo #(T)";
49
 
50
  local mailbox #( T ) m;
51
  local int m_size;
52
  protected int m_pending_blocked_gets;
53
 
54
 
55
  // Function: new
56
  //
57
  // The ~name~ and ~parent~ are the normal uvm_component constructor arguments.
58
  // The ~parent~ should be ~null~ if the  is going to be used in a
59
  // statically elaborated construct (e.g., a module). The ~size~ indicates the
60
  // maximum size of the FIFO; a value of zero indicates no upper bound.
61
 
62
  function new(string name, uvm_component parent = null, int size = 1);
63
    super.new(name, parent);
64
    m = new( size );
65
    m_size = size;
66
  endfunction
67
 
68
  virtual function string get_type_name();
69
    return type_name;
70
  endfunction
71
 
72
 
73
  // Function: size
74
  //
75
  // Returns the capacity of the FIFO-- that is, the number of entries
76
  // the FIFO is capable of holding. A return value of 0 indicates the
77
  // FIFO capacity has no limit.
78
 
79
  virtual function int size();
80
    return m_size;
81
  endfunction
82
 
83
 
84
  // Function: used
85
  //
86
  // Returns the number of entries put into the FIFO.
87
 
88
  virtual function int used();
89
    return m.num();
90
  endfunction
91
 
92
 
93
  // Function: is_empty
94
  //
95
  // Returns 1 when there are no entries in the FIFO, 0 otherwise.
96
 
97
  virtual function bit is_empty();
98
    return (m.num() == 0);
99
  endfunction
100
 
101
 
102
  // Function: is_full
103
  //
104
  // Returns 1 when the number of entries in the FIFO is equal to its ,
105
  // 0 otherwise.
106
 
107
  virtual function bit is_full();
108
    return (m_size != 0) && (m.num() == m_size);
109
  endfunction
110
 
111
 
112
 
113
  virtual task put( input T t );
114
    m.put( t );
115
    put_ap.write( t );
116
  endtask
117
 
118
  virtual task get( output T t );
119
    m_pending_blocked_gets++;
120
    m.get( t );
121
    m_pending_blocked_gets--;
122
    get_ap.write( t );
123
  endtask
124
 
125
  virtual task peek( output T t );
126
    m.peek( t );
127
  endtask
128
 
129
  virtual function bit try_get( output T t );
130
    if( !m.try_get( t ) ) begin
131
      return 0;
132
    end
133
 
134
    get_ap.write( t );
135
    return 1;
136
  endfunction
137
 
138
  virtual function bit try_peek( output T t );
139
    if( !m.try_peek( t ) ) begin
140
      return 0;
141
    end
142
    return 1;
143
  endfunction
144
 
145
  virtual function bit try_put( input T t );
146
    if( !m.try_put( t ) ) begin
147
      return 0;
148
    end
149
 
150
    put_ap.write( t );
151
    return 1;
152
  endfunction
153
 
154
  virtual function bit can_put();
155
    return m_size == 0 || m.num() < m_size;
156
  endfunction
157
 
158
  virtual function bit can_get();
159
    return m.num() > 0 && m_pending_blocked_gets == 0;
160
  endfunction
161
 
162
  virtual function bit can_peek();
163
    return m.num() > 0;
164
  endfunction
165
 
166
 
167
  // Function: flush
168
  //
169
  // Removes all entries from the FIFO, after which  returns 0
170
  // and  returns 1.
171
 
172
  virtual function void flush();
173
    T t;
174
    bit r;
175
 
176
    r = 1;
177
    while( r ) r = try_get( t ) ;
178
 
179
    if( m.num() > 0 && m_pending_blocked_gets != 0 ) begin
180
      uvm_report_error("flush failed" ,
181
                       "there are blocked gets preventing the flush", UVM_NONE);
182
    end
183
 
184
  endfunction
185
 
186
endclass
187
 
188
 
189
//------------------------------------------------------------------------------
190
//
191
// Class: uvm_tlm_analysis_fifo#(T)
192
//
193
// An analysis_fifo is a  with an unbounded size and a write interface.
194
// It can be used any place a  is used. Typical usage is
195
// as a buffer between a  in an initiator component
196
// and TLM1 target component.
197
//
198
//------------------------------------------------------------------------------
199
 
200
class uvm_tlm_analysis_fifo #(type T = int) extends uvm_tlm_fifo #(T);
201
 
202
  // Port: analysis_export #(T)
203
  //
204
  // The analysis_export provides the write method to all connected analysis
205
  // ports and parent exports:
206
  //
207
  //|  function void write (T t)
208
  //
209
  // Access via ports bound to this export is the normal mechanism for writing
210
  // to an analysis FIFO.
211
  // See write method of  for more information.
212
 
213
  uvm_analysis_imp #(T, uvm_tlm_analysis_fifo #(T)) analysis_export;
214
 
215
 
216
  // Function: new
217
  //
218
  // This is the standard uvm_component constructor. ~name~ is the local name
219
  // of this component. The ~parent~ should be left unspecified when this
220
  // component is instantiated in statically elaborated constructs and must be
221
  // specified when this component is a child of another UVM component.
222
 
223
  function new(string name ,  uvm_component parent = null);
224
    super.new(name, parent, 0); // analysis fifo must be unbounded
225
    analysis_export = new("analysis_export", this);
226
  endfunction
227
 
228
  const static string type_name = "uvm_tlm_analysis_fifo #(T)";
229
 
230
  virtual function string get_type_name();
231
    return type_name;
232
  endfunction
233
 
234
  function void write(input T t);
235
    void'(this.try_put(t)); // unbounded => must succeed
236
  endfunction
237
 
238
endclass

powered by: WebSVN 2.1.0

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