1 |
16 |
HanySalah |
//
|
2 |
|
|
//------------------------------------------------------------------------------
|
3 |
|
|
// Copyright 2007-2011 Mentor Graphics Corporation
|
4 |
|
|
// Copyright 2007-2011 Cadence Design Systems, Inc.
|
5 |
|
|
// Copyright 2010-2011 Synopsys, Inc.
|
6 |
|
|
// Copyright 2013 NVIDIA Corporation
|
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 |
|
|
// Class: uvm_get_to_lock_dap
|
25 |
|
|
// Provides a 'Get-To-Lock' Data Access Policy.
|
26 |
|
|
//
|
27 |
|
|
// The 'Get-To-Lock' Data Access Policy allows for any number of 'sets',
|
28 |
|
|
// until the value is retrieved via a 'get'. Once 'get' has been called,
|
29 |
|
|
// it is illegal to 'set' a new value.
|
30 |
|
|
//
|
31 |
|
|
// The UVM uses this policy to protect the ~starting phase~ and ~automatic objection~
|
32 |
|
|
// values in .
|
33 |
|
|
//
|
34 |
|
|
|
35 |
|
|
class uvm_get_to_lock_dap#(type T=int) extends uvm_set_get_dap_base#(T);
|
36 |
|
|
|
37 |
|
|
// Used for self-references
|
38 |
|
|
typedef uvm_get_to_lock_dap#(T) this_type;
|
39 |
|
|
|
40 |
|
|
// Parameterized Utils
|
41 |
|
|
`uvm_object_param_utils(uvm_get_to_lock_dap#(T))
|
42 |
|
|
|
43 |
|
|
// Stored data
|
44 |
|
|
local T m_value;
|
45 |
|
|
|
46 |
|
|
// Lock state
|
47 |
|
|
local bit m_locked;
|
48 |
|
|
|
49 |
|
|
// Function: new
|
50 |
|
|
// Constructor
|
51 |
|
|
function new(string name="unnamed-uvm_get_to_lock_dap#(T)");
|
52 |
|
|
super.new(name);
|
53 |
|
|
m_locked = 0;
|
54 |
|
|
endfunction : new
|
55 |
|
|
|
56 |
|
|
// Group: Set/Get Interface
|
57 |
|
|
|
58 |
|
|
// Function: set
|
59 |
|
|
// Updates the value stored within the DAP.
|
60 |
|
|
//
|
61 |
|
|
// ~set~ will result in an error if the value has
|
62 |
|
|
// already been retrieved via a call to ~get~.
|
63 |
|
|
virtual function void set(T value);
|
64 |
|
|
if (m_locked)
|
65 |
|
|
`uvm_error("UVM/GET_TO_LOCK_DAP/SAG",
|
66 |
|
|
$sformatf("Attempt to set new value on '%s', but the data access policy forbids setting after a get!",
|
67 |
|
|
get_full_name()))
|
68 |
|
|
else begin
|
69 |
|
|
m_value = value;
|
70 |
|
|
end
|
71 |
|
|
endfunction : set
|
72 |
|
|
|
73 |
|
|
// Function: try_set
|
74 |
|
|
// Attempts to update the value stored within the DAP.
|
75 |
|
|
//
|
76 |
|
|
// ~try_set~ will return a 1 if the value was successfully
|
77 |
|
|
// updated, or a 0 if the value can not be updated due
|
78 |
|
|
// to ~get~ having been called. No errors will be reported
|
79 |
|
|
// if ~try_set~ fails.
|
80 |
|
|
virtual function bit try_set(T value);
|
81 |
|
|
if (m_locked)
|
82 |
|
|
return 0;
|
83 |
|
|
else begin
|
84 |
|
|
m_value = value;
|
85 |
|
|
return 1;
|
86 |
|
|
end
|
87 |
|
|
endfunction : try_set
|
88 |
|
|
|
89 |
|
|
// Function: get
|
90 |
|
|
// Returns the current value stored within the DAP, and 'locks' the DAP.
|
91 |
|
|
//
|
92 |
|
|
// After a 'get', the value contained within the DAP cannot
|
93 |
|
|
// be changed.
|
94 |
|
|
virtual function T get();
|
95 |
|
|
m_locked = 1;
|
96 |
|
|
return m_value;
|
97 |
|
|
endfunction : get
|
98 |
|
|
|
99 |
|
|
// Function: try_get
|
100 |
|
|
// Retrieves the current value stored within the DAP, and 'locks' the DAP.
|
101 |
|
|
//
|
102 |
|
|
// ~try_get~ will always return 1.
|
103 |
|
|
virtual function bit try_get(output T value);
|
104 |
|
|
value = get();
|
105 |
|
|
return 1;
|
106 |
|
|
endfunction : try_get
|
107 |
|
|
|
108 |
|
|
// Group: Introspection
|
109 |
|
|
//
|
110 |
|
|
// The ~uvm_get_to_lock_dap~ cannot support the standard UVM
|
111 |
|
|
// instrumentation methods (~copy~, ~clone~, ~pack~ and
|
112 |
|
|
// ~unpack~), due to the fact that they would potentially
|
113 |
|
|
// violate the access policy.
|
114 |
|
|
//
|
115 |
|
|
// A call to any of these methods will result in an error.
|
116 |
|
|
|
117 |
|
|
virtual function void do_copy(uvm_object rhs);
|
118 |
|
|
`uvm_error("UVM/GET_TO_LOCK_DAP/CPY",
|
119 |
|
|
"'copy()' is not supported for 'uvm_get_to_lock_dap#(T)'")
|
120 |
|
|
endfunction : do_copy
|
121 |
|
|
|
122 |
|
|
virtual function void do_pack(uvm_packer packer);
|
123 |
|
|
`uvm_error("UVM/GET_TO_LOCK_DAP/PCK",
|
124 |
|
|
"'pack()' is not supported for 'uvm_get_to_lock_dap#(T)'")
|
125 |
|
|
endfunction : do_pack
|
126 |
|
|
|
127 |
|
|
virtual function void do_unpack(uvm_packer packer);
|
128 |
|
|
`uvm_error("UVM/GET_TO_LOCK_DAP/UPK",
|
129 |
|
|
"'unpack()' is not supported for 'uvm_get_to_lock_dap#(T)'")
|
130 |
|
|
endfunction : do_unpack
|
131 |
|
|
|
132 |
|
|
// Group- Reporting
|
133 |
|
|
|
134 |
|
|
// Function- convert2string
|
135 |
|
|
virtual function string convert2string();
|
136 |
|
|
if (m_locked)
|
137 |
|
|
return $sformatf("(%s) %0p [LOCKED]", `uvm_typename(m_value), m_value);
|
138 |
|
|
else
|
139 |
|
|
return $sformatf("(%s) %0p [UNLOCKED]", `uvm_typename(m_value), m_value);
|
140 |
|
|
endfunction : convert2string
|
141 |
|
|
|
142 |
|
|
// Function- do_print
|
143 |
|
|
virtual function void do_print(uvm_printer printer);
|
144 |
|
|
super.do_print(printer);
|
145 |
|
|
printer.print_field_int("lock_state", m_locked, $bits(m_locked));
|
146 |
|
|
printer.print_generic("value",
|
147 |
|
|
`uvm_typename(m_value),
|
148 |
|
|
0,
|
149 |
|
|
$sformatf("%0p", m_value));
|
150 |
|
|
|
151 |
|
|
endfunction : do_print
|
152 |
|
|
|
153 |
|
|
endclass // uvm_get_to_lock_dap
|
154 |
|
|
|