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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [dap/] [uvm_set_before_get_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_set_before_get_dap
25
// Provides a 'Set Before Get' Data Access Policy.
26
//
27
// The 'Set Before Get' Data Access Policy enforces that the value must
28
// be written at ~least~ once before it is read.  This DAP can be used to
29
// pass shared information to multiple components during standard configuration,
30
// even if that information hasn't yet been determined.
31
//
32
// Such DAP objects can be useful for passing a 'placeholder' reference, before
33
// the information is actually available.  A good example of this would be
34
// the virtual sequencer:
35
//
36
//| typedef uvm_set_before_get_dap#(uvm_sequencer_base) seqr_dap_t;
37
//| virtual_seqeuncer_type virtual_sequencer;
38
//| agent_type my_agent;
39
//| seqr_dap_t seqr_dap;
40
//|
41
//| function void my_env::build_phase(uvm_phase phase);
42
//|   seqr_dap = seqr_dap_t::type_id::create("seqr_dap");
43
//|   // Pass the DAP, because we don't have a reference to the
44
//|   // real sequencer yet...
45
//|   uvm_config_db#(seqr_dap_t)::set(this, "virtual_sequencer", "seqr_dap", seqr_dap);
46
//|
47
//|   // Create the virtual sequencer
48
//|   virtual_sequencer = virtual_sequencer_type::type_id::create("virtual_sequencer", this);
49
//|
50
//|   // Create the agent
51
//|   agent = agent_type::type_id::create("agent", this);
52
//| endfunction
53
//|
54
//| function void my_env::connect_phase(uvm_phase phase);
55
//|   // Now that we know the value is good, we can set it
56
//|   seqr_dap.set(agent.sequencer);
57
//| endfunction
58
//
59
// In the example above, the environment didn't have a reference to the
60
// agent's sequencer yet, because the agent hadn't executed its ~build_phase~.
61
// The environment needed to give the virtual sequencer a "Set before get" DAP
62
// so that the virtual sequencer (and any sequences one it), could ~eventually~
63
// see the agent's sequencer, when the reference was finally available.  If
64
// the virtual sequencer (or any sequences on it) attempted to 'get' the
65
// reference to the agent's sequencer ~prior~ to the environment assigning it,
66
// an error would have been reported.
67
 
68
class uvm_set_before_get_dap#(type T=int) extends uvm_set_get_dap_base#(T);
69
 
70
   // Used for self-references
71
   typedef uvm_set_before_get_dap#(T) this_type;
72
 
73
   // Parameterized Utils
74
   `uvm_object_param_utils(uvm_set_before_get_dap#(T))
75
 
76
   // Stored data
77
   local T m_value;
78
 
79
   // Set state
80
   local bit m_set;
81
 
82
   // Function: new
83
   // Constructor
84
   function new(string name="unnamed-uvm_set_before_get_dap#(T)");
85
      super.new(name);
86
      m_set = 0;
87
   endfunction : new
88
 
89
   // Group: Set/Get Interface
90
 
91
   // Function: set
92
   // Updates the value stored within the DAP.
93
   //
94
   virtual function void set(T value);
95
      m_set = 1;
96
      m_value = value;
97
   endfunction : set
98
 
99
   // Function: try_set
100
   // Attempts to update the value stored within the DAP.
101
   //
102
   // ~try_set~ will always return a 1.
103
   virtual function bit try_set(T value);
104
      set(value);
105
      return 1;
106
   endfunction : try_set
107
 
108
   // Function: get
109
   // Returns the current value stored within the DAP.
110
   //
111
   // If 'get' is called before a call to  or , then
112
   // an error will be reported.
113
   virtual  function T get();
114
      if (!m_set) begin
115
         `uvm_error("UVM/SET_BEFORE_GET_DAP/NO_SET",
116
                    $sformatf("Attempt to get value on '%s', but the data access policy forbits calling 'get' prior to calling 'set' or 'try_set'!",
117
                              get_full_name()))
118
      end
119
      return m_value;
120
   endfunction : get
121
 
122
   // Function: try_get
123
   // Attempts to retrieve the current value stored within the DAP
124
   //
125
   // If the value has not been 'set', then try_get will return a 0,
126
   // otherwise it will return a 1, and set ~value~ to the current
127
   // value stored within the DAP.
128
   virtual function bit try_get(output T value);
129
      if (!m_set) begin
130
        return 0;
131
      end
132
      else begin
133
         value = m_value;
134
         return 1;
135
      end
136
   endfunction : try_get
137
 
138
   // Group: Introspection
139
   //
140
   // The ~uvm_set_before_get_dap~ cannot support the standard UVM
141
   // instrumentation methods (~copy~, ~clone~, ~pack~ and
142
   // ~unpack~), due to the fact that they would potentially
143
   // violate the access policy.
144
   //
145
   // A call to any of these methods will result in an error.
146
 
147
   virtual function void do_copy(uvm_object rhs);
148
      `uvm_error("UVM/SET_BEFORE_GET_DAP/CPY",
149
                 "'copy()' is not supported for 'uvm_set_before_get_dap#(T)'")
150
   endfunction : do_copy
151
 
152
   virtual function void do_pack(uvm_packer packer);
153
      `uvm_error("UVM/SET_BEFORE_GET_DAP/PCK",
154
                 "'pack()' is not supported for 'uvm_set_before_get_dap#(T)'")
155
   endfunction : do_pack
156
 
157
   virtual function void do_unpack(uvm_packer packer);
158
      `uvm_error("UVM/SET_BEFORE_GET_DAP/UPK",
159
                 "'unpack()' is not supported for 'uvm_set_before_get_dap#(T)'")
160
   endfunction : do_unpack
161
 
162
   // Group- Reporting
163
 
164
   // Function- convert2string
165
   virtual function string convert2string();
166
      if (m_set)
167
        return $sformatf("(%s) %0p [SET]", `uvm_typename(m_value), m_value);
168
      else
169
        return $sformatf("(%s) %0p [UNSET]", `uvm_typename(m_value), m_value);
170
   endfunction : convert2string
171
 
172
   // Function- do_print
173
   virtual function void do_print(uvm_printer printer);
174
      super.do_print(printer);
175
      printer.print_field_int("set_state", m_set, $bits(m_set));
176
      printer.print_generic("value",
177
                            `uvm_typename(m_value),
178
                            0,
179
                            $sformatf("%0p", m_value));
180
 
181
   endfunction : do_print
182
 
183
endclass // uvm_set_before_get_dap
184
 

powered by: WebSVN 2.1.0

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