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

Subversion Repositories lpffir

[/] [lpffir/] [trunk/] [uvm/] [tools/] [uvm_syoscb/] [src/] [cl_syoscb_queue_std.svh] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 vladimirar
//----------------------------------------------------------------------
2
//   Copyright 2014-2015 SyoSil ApS
3
//   All Rights Reserved Worldwide
4
//
5
//   Licensed under the Apache License, Version 2.0 (the
6
//   "License"); you may not use this file except in
7
//   compliance with the License.  You may obtain a copy of
8
//   the License at
9
//
10
//       http://www.apache.org/licenses/LICENSE-2.0
11
//
12
//   Unless required by applicable law or agreed to in
13
//   writing, software distributed under the License is
14
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
15
//   CONDITIONS OF ANY KIND, either express or implied.  See
16
//   the License for the specific language governing
17
//   permissions and limitations under the License.
18
//----------------------------------------------------------------------
19
/// Standard implementation of a queue. Uses a normal SystemVerilog queue as
20
/// implementation. The class implements the queue API as defined by the queue
21
/// base class.
22
class cl_syoscb_queue_std extends cl_syoscb_queue;
23
  //-------------------------------------
24
  // Non randomizable variables
25
  //-------------------------------------
26
  /// Poor mans queue implementation as a SV queue
27
  local cl_syoscb_item items[$];
28
 
29
  //-------------------------------------
30
  // UVM Macros
31
  //-------------------------------------
32
  `uvm_component_utils_begin(cl_syoscb_queue_std)
33
    `uvm_field_queue_object(items, UVM_DEFAULT)
34
  `uvm_component_utils_end
35
 
36
  //-------------------------------------
37
  // Constructor
38
  //-------------------------------------
39
  extern function new(string name, uvm_component parent);
40
 
41
  //-------------------------------------
42
  // Queue API
43
  //-------------------------------------
44
  // Basic queue functions
45
  extern virtual function bit add_item(string producer, uvm_sequence_item item);
46
  extern virtual function bit delete_item(int unsigned idx);
47
  extern virtual function cl_syoscb_item get_item(int unsigned idx);
48
  extern virtual function int unsigned get_size();
49
  extern virtual function bit empty();
50
  extern virtual function bit insert_item(string producer, uvm_sequence_item item, int unsigned idx);
51
 
52
  // Iterator support functions
53
  extern virtual function cl_syoscb_queue_iterator_base create_iterator();
54
  extern virtual function bit delete_iterator(cl_syoscb_queue_iterator_base iterator);
55
endclass: cl_syoscb_queue_std
56
 
57
function cl_syoscb_queue_std::new(string name, uvm_component parent);
58
  super.new(name, parent);
59
endfunction: new
60
 
61
/// Queue API: See cl_syoscb_queue for more details
62
function bit cl_syoscb_queue_std::add_item(string producer, uvm_sequence_item item);
63
  cl_syoscb_item new_item;
64
 
65
  // Check that the max_queue_size for this queue is not reached
66
  if(this.cfg.get_max_queue_size(this.get_name())>0 &&
67
     this.get_size()==this.cfg.get_max_queue_size(this.get_name())) begin
68
    `uvm_error("QUEUE_ERROR", $sformatf("[%s]: Maximum number of items (%0d) for queue: %s reached",
69
                                       this.cfg.get_scb_name(),
70
                                       this.cfg.get_max_queue_size(this.get_name()),
71
                                       this.get_name()))
72
    return(1'b0);
73
  end
74
 
75
  // Create the new scoreboard item with META data which wraps the
76
  // uvm_sequence_item
77
  //
78
  // *NOTE*: No need for using create.
79
  //         New is okay since no customization is needed here
80
  //
81
  // *NOTE*: Create it once with a default name to be able to retrieve the unique
82
  //         instance id and then rename the object with a uniqueue name
83
  new_item = new(.name("default-item"));
84
  new_item.set_name({producer,"-item-", $psprintf("%0d", new_item.get_inst_id())});
85
 
86
  // Transfer the producer to the item
87
  // *NOTE*: No need to check the producer since this is checked by the parent component
88
  new_item.set_producer(.producer(producer));
89
 
90
  // Transfer the UVM sequence item to the item
91
  // *NOTE*: No need to copy it since it has been copied by the parent
92
  new_item.set_item(.item(item));
93
 
94
  // Insert the item in the queue
95
  this.items.push_back(new_item);
96
 
97
  // Count the number of inserts
98
  this.cnt_add_item++;
99
 
100
  // Signal that it worked
101
  return 1;
102
endfunction: add_item
103
 
104
/// Queue API: See cl_syoscb_queue for more details
105
function bit cl_syoscb_queue_std::delete_item(int unsigned idx);
106
  if(idx < this.items.size()) begin
107
    cl_syoscb_queue_iterator_base iter[$];
108
 
109
    // Wait to get exclusive access to the queue
110
    // if there are multiple iterators
111
    while(!this.iter_sem.try_get());
112
    items.delete(idx);
113
 
114
    // Update iterators
115
    iter = this.iterators.find(x) with (x.get_idx() < idx);
116
    for(int i = 0; i < iter.size(); i++) begin
117
      void'(iter[i].previous());
118
    end
119
 
120
    this.iter_sem.put();
121
    return 1;
122
  end else begin
123
    `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d is not present in queue: %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
124
    return 0;
125
  end
126
endfunction: delete_item
127
 
128
/// Queue API: See cl_syoscb_queue for more details
129
function cl_syoscb_item cl_syoscb_queue_std::get_item(int unsigned idx);
130
  if(idx < this.items.size()) begin
131
    return items[idx];
132
  end else begin
133
    `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d is not present in queue: %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
134
    return null;
135
  end
136
endfunction: get_item
137
 
138
/// Queue API: See cl_syoscb_queue for more details
139
function int unsigned cl_syoscb_queue_std::get_size();
140
  return this.items.size();
141
endfunction: get_size
142
 
143
/// Queue API: See cl_syoscb_queue for more details
144
function bit cl_syoscb_queue_std::empty();
145
  return(this.get_size()!=0 ? 0 : 1);
146
endfunction
147
 
148
/// Queue API: See cl_syoscb_queue for more details
149
function bit cl_syoscb_queue_std::insert_item(string producer, uvm_sequence_item item, int unsigned idx);
150
  cl_syoscb_item new_item;
151
 
152
  // Create the new scoreboard item with META data which wraps the
153
  // uvm_sequence_item
154
  //
155
  // *NOTE*: No need for using create.
156
  //         New is okay since no customization is needed here
157
  //
158
  // *NOTE*: Create it once with a default name to be able to retrieve the unique
159
  //         instance id and then rename the object with a uniqueue name
160
  new_item = new(.name("default-item"));
161
  new_item.set_name({producer,"-item-", $psprintf("%0d", new_item.get_inst_id())});
162
 
163
  // Transfer the producer to the item
164
  // *NOTE*: No need to check the producer since this is checked by the parent component
165
  new_item.set_producer(.producer(producer));
166
 
167
  // Transfer the UVM sequence item to the item
168
  // *NOTE*: No need to copy it since it has been copied by the parent
169
  new_item.set_item(.item(item));
170
 
171
  if(idx < this.items.size()) begin
172
    cl_syoscb_queue_iterator_base iter[$];
173
 
174
    // Wait to get exclusive access to the queue
175
    // if there are multiple iterators
176
    while(!this.iter_sem.try_get());
177
    this.items.insert(idx, new_item);
178
 
179
    // Update iterators
180
    iter = this.iterators.find(x) with (x.get_idx() >= idx);
181
    for(int i = 0; i < iter.size(); i++) begin
182
      // Call .next() blindly. This can never fail by design, since
183
      // if it was point at the last element then it points to the second last
184
      // element prior to the .next(). The .next() call will then just
185
      // set the iterator to the correct index again after the insertion
186
      void'(iter[i].next());
187
    end
188
 
189
    this.iter_sem.put();
190
    return 1;
191
  end else if(idx == this.items.size()) begin
192
    this.items.push_back(new_item);
193
    return 1;
194
  end else begin
195
    `uvm_info("OUT_OF_BOUNDS", $sformatf("[%s]: Idx: %0d too large for queue %0s", this.cfg.get_scb_name(), idx, this.get_name()), UVM_DEBUG);
196
    return 0;
197
  end
198
endfunction: insert_item
199
 
200
 
201
/// Queue API: See cl_syoscb_queue for more details
202
function cl_syoscb_queue_iterator_base cl_syoscb_queue_std::create_iterator();
203
  cl_syoscb_queue_iterator_std result;
204
 
205
  // Wait to get exclusive access to the queue
206
  // if there are multiple iterators
207
  while(this.iter_sem.try_get() == 0);
208
 
209
  result = cl_syoscb_queue_iterator_std::type_id::create(
210
                $sformatf("%s_iter%0d", this.get_name(), this.iter_idx));
211
 
212
  // No need to check return value since set_queue will issue
213
  // and `uvm_error of something goes wrong
214
  void'(result.set_queue(this));
215
 
216
  this.iterators[result] = result;
217
  this.iter_idx++;
218
  this.iter_sem.put();
219
 
220
  return result;
221
endfunction: create_iterator
222
 
223
/// Queue API: See cl_syoscb_queue for more details
224
function bit cl_syoscb_queue_std::delete_iterator(cl_syoscb_queue_iterator_base iterator);
225
  if(iterator == null) begin
226
    `uvm_info("NULL", $sformatf("[%s]: Asked to delete null iterator from list of iterators in %s",
227
                                this.cfg.get_scb_name(), this.get_name()), UVM_DEBUG);
228
    return 0;
229
  end else begin
230
    // Wait to get exclusive access to the queue
231
    // if there are multiple iterators
232
    while(!this.iter_sem.try_get());
233
 
234
    this.iterators.delete(iterator);
235
    this.iter_idx--;
236
    this.iter_sem.put();
237
    return 1;
238
  end
239
endfunction: delete_iterator

powered by: WebSVN 2.1.0

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