UVM: config_db (set and get) mechanism - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

204


148
 
1
/*
2
Author: Sujeet Kumar Layek
3
Designation: IP/SoC Verification Engineer
4
*/
5
6
7
8
import uvm_pkg::*;
9
`include "uvm_macros.svh"
10
11
// TOP
12
module top;
13
  
14
  int a = 5; 
15
  ;
16
  
17
  initial
18
    begin
19
      
20
      // Setting the value of the variable for lower hierarchy
21
      uvm_config_db #(int) :: set (null,"*","inttt",a);
22
      
23
      // Calling the 'test' from top.
24
      run_test();
25
      
26
    end
27
  
28
endmodule
29
30
31
// SEQUENCER 
32
class seqr extends uvm_sequencer;
33
34
   `uvm_sequencer_utils(seqr)
35
     
36
  function new (string name, uvm_component parent);
37
    super.new(name, parent);
38
  endfunction
39
40
endclass
41
42
43
// SEQUENCE
44
class seq extends uvm_sequence;
45
  `uvm_object_utils (seq)
46
  
47
  int d = 10; // This 'd' will take the value of 'a' which has been set in top.
48
  
49
  function new(string name = "seq");
50
    super.new(name);
51
  endfunction
52
53
  
54
  virtual task body();
55
    $display("get_full_name:");
56
    `uvm_info (get_full_name(), $sformatf (" :: Set the local value of 'SEQ' D = %0d\n", d), UVM_LOW )
57
    $display("get_type_name:");
58
    `uvm_info (get_type_name(), $sformatf (" :: Set the local value of 'SEQ' D = %0d\n", d), UVM_LOW )
59
    $display("get_name:");
60
    `uvm_info (get_name(), $sformatf (" :: Set the local value of 'SEQ' D = %0d\n", d), UVM_LOW )
61
    
62
    uvm_config_db #(int) :: get (null, get_full_name(),"inttt", d);
63
    
64
    $display("\n************************************");
65
    $display("Class 'SEQ' get from top :: D = %0d",d);
66
    $display("************************************\n");
67
  endtask
68
69
endclass
70
71
72
73
// ENV
74
class env extends uvm_component;
75
  `uvm_component_utils(env)
76
  
77
  int c;
78
  seqr seqr_h;
79
  
80
  function new(string name = "env", uvm_component parent);
81
    super.new(name,parent);
82
  endfunction
83
  
84
  function void build_phase (uvm_phase phase);
85
    
86
    // Creating 'SEQUENCER' inside 'ENV'
87
    seqr_h = seqr::type_id::create("seqr_h",this);
88
    
89
    // Getting the value of the variable in ENV in a different variable
90
    uvm_config_db #(int) :: get (this,"","int",c);
91
    
92
    $display("\n************************************");
93
    $display("Class 'ENV' get from top :: C = %0d",c);
94
    $display("************************************\n");
95
      
96
  endfunction
97
      
98
endclass
99
100
    
101
102
// TEST
103
class test extends uvm_component;
104
  `uvm_component_utils(test)
105
  
106
  int b;
107
  env env_h;
108
  seq seq_h;
109
110
  
111
  function new(string name = "test", uvm_component parent);
112
    super.new(name,parent);
113
  endfunction
114
  
115
  function void build_phase (uvm_phase phase);
116
    
117
    // Creating 'ENV' inside 'TEST'
118
    env_h = env::type_id::create("env_h",this);
119
   
120
    // Getting the value of the variable in TEST in a different variable
121
    uvm_config_db #(int) :: get (this,"","int",b);
122
    $display("\n************************************");
123
    $display("Class 'TEST' get from top :: B = %0d",b);
124
    $display("************************************\n");
125
    
126
  endfunction
127
128
  
129
  virtual function void end_of_elaboration_phase (uvm_phase phase);
130
    $display ("\nPrinting the UVM Topology: -\n");
131
    uvm_top.print_topology ();
132
  endfunction
133
  
134
    
135
  // Start the sequence
136
  virtual task run_phase(uvm_phase phase);
137
    
138
    // Creating 'SEQ' inside 'TEST'
139
    seq_h = seq::type_id::create("seq_h");
140
    
141
    // UVM Objection
142
    phase.raise_objection(this);
143
      seq_h.start (env_h.seqr_h);
144
    phase.drop_objection(this);
145
    
146
  endtask
147
    
148
endclass
xxxxxxxxxx
1
22
 
1
// Code your design here
2
3
/*
4
5
Differences between
6
    get_full_name,
7
    get_type_name and
8
    get_name
9
in UVM.
10
11
get_full_name():
12
    It will show the complete hierarchical path starting from tb_top.test.env.. 
13
    and so on till your object type in the output log file.
14
15
get_type_name(): 
16
    It will return only the "class name" irrespective of hierarchy.
17
18
get_name():
19
    It will return the "handle name" you have defined for the same class where 
20
    it has been used.
21
22
*/
3663 views and 3 likes     
 
**Scenario -**
Create a UVM based environment for the following specifications: -
Top module name: top
1. Take a variable as int a = 5 and set it using config_db for lower hierarchy.
2. Get the value of the variable using "config_db" into another variable as b, c and d, into test, environment and sequence class respectively.
3. Set a local value for 'd' as 10, in sequence class.
4. Use get_full_name, get_type_name and get_name to print 'd' value before getting and printing the 'set' data from uvm_top.
4. Print the topology as well.
5. Pass the uvm test name from command line.
**Can we get the config data base into my sequecnce class?** 
YES, we can!!!.
You can use the uvm_config_db from where ever you want. 
In objects to get the configuration we should not provide empty quotes as a second argument because objects don't have a hierarchy. Instead, we use get_full_name as the second argument that returns the path of the sequencer on which the sequence is started.
If the get method is called in the constructor, get full_name() can not return the path & get fails as the sequence is not yet started.
Once the sequence is started then the get method should be called, so the get method should be called from the task body before the sequence item is randomized as the task body is called by start.
**UVM configuration:**
The UVM configuration database accessed by the class uvm_config_db is a great way to pass different objects between multiple testbench components.
There are two primary functions used to put and retrive items from the database which are set() and get().

Scenario -

Create a UVM based environment for the following specifications: -

Top module name: top

  1. Take a variable as int a = 5 and set it using config_db for lower hierarchy.
  2. Get the value of the variable using "config_db" into another variable as b, c and d, into test, environment and sequence class respectively.
  3. Set a local value for 'd' as 10, in sequence class.
  4. Use get_full_name, get_type_name and get_name to print 'd' value before getting and printing the 'set' data from uvm_top.
  5. Print the topology as well.
  6. Pass the uvm test name from command line.

Can we get the config data base into my sequecnce class?

YES, we can!!!.
You can use the uvm_config_db from where ever you want.

In objects to get the configuration we should not provide empty quotes as a second argument because objects don't have a hierarchy. Instead, we use get_full_name as the second argument that returns the path of the sequencer on which the sequence is started.

If the get method is called in the constructor, get full_name() can not return the path & get fails as the sequence is not yet started.

Once the sequence is started then the get method should be called, so the get method should be called from the task body before the sequence item is randomized as the task body is called by start.

UVM configuration:
The UVM configuration database accessed by the class uvm_config_db is a great way to pass different objects between multiple testbench components.
There are two primary functions used to put and retrive items from the database which are set() and get().

342720:0