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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [dap/] [uvm_simple_lock_dap.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-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_simple_lock_dap
25
// Provides a 'Simple Lock' Data Access Policy.
26
//
27
// The 'Simple Lock' Data Access Policy allows for any number of 'sets',
28
// so long as the value is not 'locked'.  The value can be retrieved using
29
// 'get' at any time.
30
//
31
// The UVM uses this policy to protect the ~file name~ value in the
32
// .
33
//
34
 
35
class uvm_simple_lock_dap#(type T=int) extends uvm_set_get_dap_base#(T);
36
 
37
   // Used for self-references
38
   typedef uvm_simple_lock_dap#(T) this_type;
39
 
40
   // Parameterized Utils
41
   `uvm_object_param_utils(uvm_simple_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_simple_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 DAP has
62
   // been locked.
63
   virtual function void set(T value);
64
      if (m_locked)
65
        `uvm_error("UVM/SIMPLE_LOCK_DAP/SAG",
66
                   $sformatf("Attempt to set new value on '%s', but the data access policy forbids setting while locked!",
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 the DAP being locked.  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
91
   //
92
   virtual  function T get();
93
      return m_value;
94
   endfunction : get
95
 
96
   // Function: try_get
97
   // Retrieves the current value stored within the DAP
98
   //
99
   // ~try_get~ will always return 1.
100
   virtual function bit try_get(output T value);
101
      value = get();
102
      return 1;
103
   endfunction : try_get
104
 
105
   // Group: Locking
106
 
107
   // Function: lock
108
   // Locks the data value
109
   //
110
   // The data value cannot be updated via  or  while locked.
111
   function void lock();
112
      m_locked = 1;
113
   endfunction : lock
114
 
115
   // Function: unlock
116
   // Unlocks the data value
117
   //
118
   function void unlock();
119
      m_locked = 0;
120
   endfunction : unlock
121
 
122
   // Function: is_locked
123
   // Returns the state of the lock.
124
   //
125
   // Returns:
126
   // 1 - The value is locked
127
   // 0 - The value is unlocked
128
   function bit is_locked();
129
      return m_locked;
130
   endfunction : is_locked
131
 
132
   // Group: Introspection
133
   //
134
   // The ~uvm_simple_lock_dap~ cannot support the standard UVM
135
   // instrumentation methods (~copy~, ~clone~, ~pack~ and
136
   // ~unpack~), due to the fact that they would potentially
137
   // violate the access policy.
138
   //
139
   // A call to any of these methods will result in an error.
140
 
141
   virtual function void do_copy(uvm_object rhs);
142
      `uvm_error("UVM/SIMPLE_LOCK_DAP/CPY",
143
                 "'copy()' is not supported for 'uvm_simple_lock_dap#(T)'")
144
   endfunction : do_copy
145
 
146
   virtual function void do_pack(uvm_packer packer);
147
      `uvm_error("UVM/SIMPLE_LOCK_DAP/PCK",
148
                 "'pack()' is not supported for 'uvm_simple_lock_dap#(T)'")
149
   endfunction : do_pack
150
 
151
   virtual function void do_unpack(uvm_packer packer);
152
      `uvm_error("UVM/SIMPLE_LOCK_DAP/UPK",
153
                 "'unpack()' is not supported for 'uvm_simple_lock_dap#(T)'")
154
   endfunction : do_unpack
155
 
156
   // Group- Reporting
157
 
158
   // Function- convert2string
159
   virtual function string convert2string();
160
      if (m_locked)
161
        return $sformatf("(%s) %0p [LOCKED]", `uvm_typename(m_value), m_value);
162
      else
163
        return $sformatf("(%s) %0p [UNLOCKED]", `uvm_typename(m_value), m_value);
164
   endfunction : convert2string
165
 
166
   // Function- do_print
167
   virtual function void do_print(uvm_printer printer);
168
      super.do_print(printer);
169
      printer.print_int("lock_state", m_locked, $bits(m_locked));
170
      printer.print_generic("value",
171
                            `uvm_typename(m_value),
172
                            0,
173
                            $sformatf("%0p", m_value));
174
 
175
   endfunction : do_print
176
 
177
endclass // uvm_simple_lock_dap
178
 

powered by: WebSVN 2.1.0

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