APB UVM Agent  0.0.1
apb_seq_item.svh
Go to the documentation of this file.
1 //------------------------------------------------------------
2 // Copyright 2010 Mentor Graphics Corporation
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 
20 /**
21 * Base APB transaction.
22 *
23 * The transaction is used by both apb_driver and apb_monitor. For the driver, the
24 * transaction type works for request and response.
25 *
26 * Implements the basic transaction attributes (address, data, read/write control).
27 * More advanced attributes (e.g. error injection, byte enables, etc.) are not
28 * supported.
29 */
30 class apb_seq_item extends uvm_sequence_item;
31 
32 // UVM Factory Registration Macro
33 //
34 `uvm_object_utils(apb_seq_item)
35 
36 //------------------------------------------
37 // Data Members (Outputs rand, inputs non-rand)
38 //------------------------------------------
39 
40 //! Bus address.
41 rand logic[31:0] addr;
42 
43 //! Read/write data.
44 rand logic[31:0] data;
45 
46 //! Read/write (=0/1) transaction type.
47 rand logic we;
48 
49 //! Number of APB clock cycles since the apb_driver received the transaction to
50 //! the actual start of the transaction on the APB bus.
51 rand int delay;
52 
53 //! Indicates a failure to drive the item on the bus.
54 bit error;
55 
56 //------------------------------------------
57 // Constraints
58 //------------------------------------------
59 
60 //! Constrains the randomized transactions for double-word alignment.
61 constraint addr_alignment {
62  addr[1:0] == 0;
63 }
64 
65 constraint delay_bounds {
66  delay inside {[1:20]};
67 }
68 
69 //------------------------------------------
70 // Methods
71 //------------------------------------------
72 
73 // Standard UVM Methods:
74 
75 /**
76 * Conventional UVM object constructor.
77 */
78 extern function new(string name = "apb_seq_item");
79 
80 /*
81 * Implements a class specific deep copy.
82 */
83 extern function void do_copy(uvm_object rhs);
84 
85 /*
86 * Implements a class specific comparison.
87 */
88 extern function bit do_compare(uvm_object rhs, uvm_comparer comparer);
89 
90 /*
91 * Implements a class specific string conversion.
92 */
93 extern function string convert2string();
94 
95 /*
96 * Implements a class specific printing.
97 */
98 extern function void do_print(uvm_printer printer);
99 
100 /*
101 * Implements a class specific recording.
102 */
103 extern function void do_record(uvm_recorder recorder);
104 
105 endclass:apb_seq_item
106 
107 function apb_seq_item::new(string name = "apb_seq_item");
108  super.new(name);
109 endfunction
110 
111 function void apb_seq_item::do_copy(uvm_object rhs);
112  apb_seq_item rhs_;
113 
114  if(!$cast(rhs_, rhs)) begin
115  `uvm_fatal("do_copy", "cast of rhs object failed")
116  end
117  super.do_copy(rhs);
118  // Copy over data members:
119  addr = rhs_.addr;
120  data = rhs_.data;
121  we = rhs_.we;
122  delay = rhs_.delay;
123 
124 endfunction:do_copy
125 
126 function bit apb_seq_item::do_compare(uvm_object rhs, uvm_comparer comparer);
127  apb_seq_item rhs_;
128 
129  if(!$cast(rhs_, rhs)) begin
130  `uvm_error("do_copy", "cast of rhs object failed")
131  return 0;
132  end
133  return super.do_compare(rhs, comparer) &&
134  addr == rhs_.addr &&
135  data == rhs_.data &&
136  we == rhs_.data;
137  // Delay is not relevant to the comparison
138 endfunction:do_compare
139 
140 function string apb_seq_item::convert2string();
141  string s;
142 
143  $sformat(s, "%s\n", super.convert2string());
144  // Convert to string function reusing s:
145  $sformat(s, "%s\n addr\t%0h\n data\t%0h\n we\t%0b\n delay\t%0d\n", s, addr, data, we, delay);
146  return s;
147 
148 endfunction:convert2string
149 
150 function void apb_seq_item::do_print(uvm_printer printer);
151  if(printer.knobs.sprint == 0) begin
152  $display(convert2string());
153  end
154  else begin
155  printer.m_string = convert2string();
156  end
157 endfunction:do_print
158 
159 function void apb_seq_item:: do_record(uvm_recorder recorder);
160  super.do_record(recorder);
161 
162  // Use the record macros to record the item fields:
163  `uvm_record_field("addr", addr)
164  `uvm_record_field("data", data)
165  `uvm_record_field("we", we)
166  `uvm_record_field("delay", delay)
167 endfunction:do_record
bit error
Indicates a failure to drive the item on the bus.
Base APB transaction.
new(string name="apb_seq_item")
Conventional UVM object constructor.
void do_copy(uvm_object rhs)
constraint addr_alignment()
Constrains the randomized transactions for double-word alignment.
rand int delay
Number of APB clock cycles since the apb_driver received the transaction to the actual start of the t...
uvm_object_utils(apb_seq_item) rand logic< 31 rand logic< 31:0 > data
Bus address.
rand logic we
Read/write (=0/1) transaction type.