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

Subversion Repositories uart2bus_testbench

[/] [uart2bus_testbench/] [trunk/] [tb/] [uvm_src/] [comps/] [uvm_agent.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 Synopsys, Inc.
6
//   All Rights Reserved Worldwide
7
//
8
//   Licensed under the Apache License, Version 2.0 (the
9
//   "License"); you may not use this file except in
10
//   compliance with the License.  You may obtain a copy of
11
//   the License at
12
//
13
//       http://www.apache.org/licenses/LICENSE-2.0
14
//
15
//   Unless required by applicable law or agreed to in
16
//   writing, software distributed under the License is
17
//   distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
18
//   CONDITIONS OF ANY KIND, either express or implied.  See
19
//   the License for the specific language governing
20
//   permissions and limitations under the License.
21
//------------------------------------------------------------------------------
22
 
23
//------------------------------------------------------------------------------
24
//
25
// CLASS: uvm_agent
26
//
27
// The uvm_agent virtual class should be used as the base class for the user-
28
// defined agents. Deriving from uvm_agent will allow you to distinguish agents
29
// from other component types also using its inheritance. Such agents will
30
// automatically inherit features that may be added to uvm_agent in the future.
31
//
32
// While an agent's build function, inherited from , can be
33
// implemented to define any agent topology, an agent typically contains three
34
// subcomponents: a driver, sequencer, and monitor. If the agent is active,
35
// subtypes should contain all three subcomponents. If the agent is passive,
36
// subtypes should contain only the monitor.
37
//------------------------------------------------------------------------------
38
 
39
virtual class uvm_agent extends uvm_component;
40
  uvm_active_passive_enum is_active = UVM_ACTIVE;
41
 
42
  // Function: new
43
  //
44
  // Creates and initializes an instance of this class using the normal
45
  // constructor arguments for : ~name~ is the name of the
46
  // instance, and ~parent~ is the handle to the hierarchical parent, if any.
47
  //
48
  // The int configuration parameter is_active is used to identify whether this
49
  // agent should be acting in active or passive mode. This parameter can
50
  // be set by doing:
51
  //
52
  //| uvm_config_int::set(this, ", "is_active", UVM_ACTIVE);
53
 
54
  function new (string name, uvm_component parent);
55
    super.new(name, parent);
56
  endfunction
57
 
58
  function void build_phase(uvm_phase phase);
59
     int active;
60
     uvm_resource_pool rp;
61
     uvm_resource_types::rsrc_q_t rq;
62
 
63
     super.build_phase(phase);
64
     // is_active is treated as if it were declared via `uvm_field_enum,
65
     // which means it matches against uvm_active_passive_enum, int,
66
     // int unsigned, uvm_integral_t, uvm_bitstream_t, and string.
67
     rp = uvm_resource_pool::get();
68
     rq = rp.lookup_name(get_full_name(), "is_active", null, 0);
69
     uvm_resource_pool::sort_by_precedence(rq);
70
     for (int i = 0; i < rq.size(); i++) begin
71
        uvm_resource_base rsrc = rq.get(i);
72
        uvm_resource#(uvm_active_passive_enum) rap;
73
 
74
        if ($cast(rap, rsrc)) begin
75
           is_active = rap.read(this);
76
           break;
77
        end
78
        else begin
79
           uvm_resource#(uvm_integral_t) rit;
80
           if ($cast(rit, rsrc)) begin
81
              is_active = uvm_active_passive_enum'(rit.read(this));
82
              break;
83
           end
84
           else begin
85
              uvm_resource#(uvm_bitstream_t) rbs;
86
              if ($cast(rbs, rsrc)) begin
87
                 is_active = uvm_active_passive_enum'(rbs.read(this));
88
                 break;
89
              end
90
              else begin
91
                 uvm_resource#(int) ri;
92
                 if ($cast(ri, rsrc)) begin
93
                    is_active = uvm_active_passive_enum'(ri.read(this));
94
                    break;
95
                 end
96
                 else begin
97
                    uvm_resource#(int unsigned) riu;
98
                    if ($cast(riu, rsrc)) begin
99
                       is_active = uvm_active_passive_enum'(riu.read(this));
100
                       break;
101
                    end
102
                    else begin
103
                       uvm_resource#(string) rs;
104
                       if ($cast(rs, rsrc)) begin
105
                          void'(uvm_enum_wrapper#(uvm_active_passive_enum)::from_name(rs.read(this), is_active));
106
                          break;
107
                       end
108
                    end // else: !if($cast(riu, rsrc))
109
                 end // else: !if($cast(ri, rsrc))
110
              end // else: !if($cast(rbs, rsrc))
111
           end // else: !if($cast(rit, rsrc))
112
        end // else: !if($cast(rap, rsrc))
113
     end // for (int i = 0; found == 0 && i < rq.size(); i++)
114
 
115
  endfunction
116
 
117
  const static string type_name = "uvm_agent";
118
 
119
  virtual function string get_type_name ();
120
    return type_name;
121
  endfunction
122
 
123
  // Function: get_is_active
124
  //
125
  // Returns UVM_ACTIVE is the agent is acting as an active agent and
126
  // UVM_PASSIVE if it is acting as a passive agent. The default implementation
127
  // is to just return the is_active flag, but the component developer may
128
  // override this behavior if a more complex algorithm is needed to determine
129
  // the active/passive nature of the agent.
130
 
131
  virtual function uvm_active_passive_enum get_is_active();
132
    return is_active;
133
  endfunction
134
endclass
135
 

powered by: WebSVN 2.1.0

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