0% found this document useful (0 votes)
26 views8 pages

Part1 Uvm Macros Config DB

The document provides an overview of the uvm_config_db class, which is a static class used for managing configuration values in a testbench environment. It details methods for setting, getting, checking existence, and waiting for modifications of various data types, including integers, strings, objects, and arrays. Numerous examples illustrate the usage of these methods in practical scenarios within a UVM (Universal Verification Methodology) context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views8 pages

Part1 Uvm Macros Config DB

The document provides an overview of the uvm_config_db class, which is a static class used for managing configuration values in a testbench environment. It details methods for setting, getting, checking existence, and waiting for modifications of various data types, including integers, strings, objects, and arrays. Numerous examples illustrate the usage of these methods in practical scenarios within a UVM (Universal Verification Methodology) context.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

VIKRAM RENESAS

PART 1:
uvm_config_db

Explanations • Methods are static


• Scope resolution used::
• uvm_config_db is a static class, not an object or component.
• uvm_config_db provides static methods to store and retrieve configuration values from different components in the
testbench.
• It is used primarily for passing configuration information (e.g., parameter values) between different parts of the
testbench without the need to explicitly create instances or pass values manually between components.
• The class itself does not instantiate objects, nor does it extend the uvm_component base class

CLASS DECLARATION class uvm_config_db#(type T = int) extends uvm_resource_db#(T)

METHODS

static function bit get( uvm_component cntxt,string inst_name,string field_name,inout T value )


get
Example: uvm_config_db #(int) :: get (null, get_full_name(),"inttt", d);

set • If a setting is made at build time, the cntxt hierarchy is used to determine the setting’s precedence in the database.
Settings from hierarchically higher levels have higher precedence.
• Settings from the same level of hierarchy have a last setting wins semantic.
Declaration static function void set( uvm_component cntxt,string inst_name,string field_name,T value )

Example 1 // Top-level configuration setting


uvm_config_db#(int)::set(uvm_root::get(), "*", "my_config", 10);
// Lower-level sub-component configuration setting
uvm_config_db#(int)::set(sub_component, "*", "my_config", 20);

In this case, if a component accesses my_config from the uvm_config_db, it will get the value 10 from the top-level
component, unless the lower-level sub-component (or a descendant) overrides it. If the sub-component has a setting
of 20, the child component (sub-component) will use 20, not 10.

Example 2 // Same level, setting multiple values for the same config
uvm_config_db#(int)::set(uvm_root::get(), "*", "my_config", 10);
uvm_config_db#(int)::set(uvm_root::get(), "*", "my_config", 20);
my_config will be set to 20 because it was the last value set at the same level
exists Check if a value for field_name is available in inst_name
Declaration static function bit exists(uvm_component cntxt, string inst_name, string field_name, bit spell_chk=)

wait_modified  Blocking
 Wait for a configuration setting to be set for field_name in cntxt and inst_name. The task blocks until a new
configuration setting is applied that effects the specified field.

static task wait_modified(uvm_component cntxt,string inst_name,string field_name)


Declaration

TYPES

uvm_config_int Convenience type for uvm_config_db#(uvm_bitstream_t)


uvm_config_string Convenience type for uvm_config_db#(string)
uvm_config_object Convenience type for uvm_config_db#(uvm_object)
uvm_config_wrapper Convenience type for uvm_config_db#(uvm_object_wrapper)

1/5/2025 Page 1
VIKRAM RENESAS

Examples

Virtual Interface (Example with set, get, exists, and wait_modified)

// Virtual Interface example


virtual mem_if intf;
mem_if modified_intf;

// Setting a virtual interface


uvm_config_db#(virtual mem_if)::set(uvm_root::get(), "*", "vif", intf);

// Getting the virtual interface


uvm_config_db#(virtual mem_if)::get(uvm_root::get(), "*", "vif", intf);

// Checking if the virtual interface exists


if (uvm_config_db#(virtual mem_if)::exists(uvm_root::get(), "*", "vif")) begin
$display("Virtual Interface exists in the config db.");
end else begin
$display("Virtual Interface does not exist in the config db.");
end

// Waiting for the virtual interface to be modified


uvm_config_db#(virtual mem_if)::wait_modified(uvm_root::get(), "*", "vif", modified_intf);

Integer (Example with set, get, exists, and wait_modified)

int a = 42;
int fetched_a;
int modified_a;

// Setting an integer value


uvm_config_db#(int)::set(null, "*", "inttt", a);

// Getting the integer value


uvm_config_db#(int)::get(uvm_root::get(), "*", "inttt", fetched_a);

// Checking if the integer exists


if (uvm_config_db#(int)::exists(uvm_root::get(), "*", "inttt")) begin
$display("Integer exists in the config db.");
end else begin
$display("Integer does not exist in the config db.");
end

// Waiting for the integer value to be modified


uvm_config_db#(int)::wait_modified(uvm_root::get(), "*", "inttt", modified_a);

String (Example with set, get, exists, and wait_modified)

// String example
string config_str = "Test Configuration";
string fetched_str;
string modified_str

// Setting a string value


uvm_config_db#(string)::set(uvm_root::get(), "*", "config_string", config_str);

1/5/2025 Page 2
VIKRAM RENESAS

// Getting the string value


uvm_config_db#(string)::get(uvm_root::get(), "*", "config_string", fetched_str);
$display("Fetched String: %s", fetched_str);

// Checking if the string exists


if (uvm_config_db#(string)::exists(uvm_root::get(), "*", "config_string")) begin
$display("String exists in the config db.");
end else begin
$display("String does not exist in the config db.");
end

// Waiting for the string value to be modified


uvm_config_db#(string)::wait_modified(uvm_root::get(), "*", "config_string", modified_str);

Object (Class Handle) (Example with set, get, exists, and wait_modified)

class my_class;
int value;
function new(int v);
value = v;
endfunction
endclass

my_class obj = new(100);


my_class fetched_obj;
my_class modified_obj;

// Setting a class object handle


uvm_config_db#(my_class)::set(uvm_root::get(), "*", "obj_handle", obj);

// Getting the class object handle


uvm_config_db#(my_class)::get(uvm_root::get(), "*", "obj_handle", fetched_obj);
$display("Fetched Object Value: %0d", fetched_obj.value);

// Checking if the class object exists


if (uvm_config_db#(my_class)::exists(uvm_root::get(), "*", "obj_handle")) begin
$display("Object handle exists in the config db.");
end else begin
$display("Object handle does not exist in the config db.");
end

// Waiting for the class object handle to be modified


uvm_config_db#(my_class)::wait_modified(uvm_root::get(), "*", "obj_handle", modified_obj);

Transaction Handle (Example with set, get, exists, and wait_modified)

// Transaction Handle example


uvm_sequence_item tx = new();
uvm_sequence_item fetched_tx;
uvm_sequence_item modified_tx;

// Setting a transaction handle


uvm_config_db#(uvm_sequence_item)::set(uvm_root::get(), "*", "transaction", tx);

// Getting the transaction handle


uvm_config_db#(uvm_sequence_item)::get(uvm_root::get(), "*", "transaction", fetched_tx);
$display("Fetched Transaction: %p", fetched_tx);

1/5/2025 Page 3
VIKRAM RENESAS

// Checking if the transaction exists


if (uvm_config_db#(uvm_sequence_item)::exists(uvm_root::get(), "*", "transaction")) begin
$display("Transaction handle exists in the config db.");
end else begin
$display("Transaction handle does not exist in the config db.");
end

// Waiting for the transaction handle to be modified


uvm_config_db#(uvm_sequence_item)::wait_modified(uvm_root::get(), "*", "transaction", modified_tx);

Enum (Example with set, get, exists, and wait_modified)

// Enum example
typedef enum {IDLE, RUN, STOP} state_t;
state_t current_state = RUN;
state_t fetched_state;
state_t modified_state;

// Setting an enum value


uvm_config_db#(state_t)::set(uvm_root::get(), "*", "current_state", current_state);

// Getting the enum value


uvm_config_db#(state_t)::get(uvm_root::get(), "*", "current_state", fetched_state);

// Checking if the enum exists


if (uvm_config_db#(state_t)::exists(uvm_root::get(), "*", "current_state")) begin
$display("Enum exists in the config db.");
end else begin
$display("Enum does not exist in the config db.");
end

// Waiting for the enum value to be modified


uvm_config_db#(state_t)::wait_modified(uvm_root::get(), "*", "current_state", modified_state);

Array (Static) (Example with set, get, exists, and wait_modified)

// Static Array example


int my_array[3] = '{1, 2, 3};
int fetched_array[3];
int modified_array[3];

// Setting a static array


uvm_config_db#(int[3])::set(uvm_root::get(), "*", "my_array", my_array);

// Getting the static array


uvm_config_db#(int[3])::get(uvm_root::get(), "*", "my_array", fetched_array);

// Checking if the static array exists


if (uvm_config_db#(int[3])::exists(uvm_root::get(), "*", "my_array")) begin
$display("Array exists in the config db.");
end else begin
$display("Array does not exist in the config db.");
end

// Waiting for the array to be modified


uvm_config_db#(int[3])::wait_modified(uvm_root::get(), "*", "my_array", modified_array);

1/5/2025 Page 4
VIKRAM RENESAS

Dynamic Array (Example with set, get, exists, and wait_modified)

// Dynamic Array example


int my_dynamic_array[];
my_dynamic_array = new[3];
my_dynamic_array[0] = 10;
my_dynamic_array[1] = 20;
my_dynamic_array[2] = 30;
int fetched_dynamic_array[];
int modified_dynamic_array[];

// Setting a dynamic array


uvm_config_db#(int)::set(uvm_root::get(), "*", "dynamic_array", my_dynamic_array);

// Getting the dynamic array


uvm_config_db#(int)::get(uvm_root::get(), "*", "dynamic_array", fetched_dynamic_array);

// Checking if the dynamic array exists


if (uvm_config_db#(int)::exists(uvm_root::get(), "*", "dynamic_array")) begin
$display("Dynamic array exists in the config db.");
end else begin
$display("Dynamic array does not exist in the config db.");
end

// Waiting for the dynamic array to be modified


uvm_config_db#(int)::wait_modified(uvm_root::get(), "*", "dynamic_array", modified_dynamic_array);

Struct (Example with set, get, exists, and wait_modified)

// Define a simple struct type


typedef struct { bit [7:0] byte1; simple_struct_t;
module top;
// Declare the struct objects
simple_struct_t my_struct;
simple_struct_t fetched_struct;
simple_struct_t modified_struct;
initial begin
// Initialize the struct with some values
my_struct.byte1 = 8'hAA; // Set byte1 to 0xAA
my_struct.byte2 = 8'hBB; // Set byte2 to 0xBB

// Set the struct into the UVM Config DB with key "my_struct_key"
uvm_config_db#(simple_struct_t)::set(uvm_root::get(), "*", "my_struct_key", my_struct);

// Fetch the struct from the UVM Config DB


uvm_config_db#(simple_struct_t)::get(uvm_root::get(), "*", "my_struct_key", fetched_struct);

// Display the fetched struct values


$display("Fetched struct - byte1: %0h, byte2: %0h", fetched_struct.byte1, fetched_struct.byte2);

// Check if the struct exists in the config DB


if (uvm_config_db#(simple_struct_t)::exists(uvm_root::get(), "*", "my_struct_key")) begin
$display("Struct exists in the config db.");
end else begin
$display("Struct does not exist in the config db.");
end

1/5/2025 Page 5
VIKRAM RENESAS

// Modify the struct's values


modified_struct.byte1 = 8'hCC; // Set byte1 to 0xCC
modified_struct.byte2 = 8'hDD; // Set byte2 to 0xDD

// Set the modified struct into the UVM Config DB


uvm_config_db#(simple_struct_t)::set(uvm_root::get(), "*", "my_struct_key", modified_struct);

Union (Example with set, get, exists, and wait_modified)

// Union example
typedef union {
int i;
real r;
} int_or_real_t;

int_or_real_t my_union;
my_union.i = 10;
int_or_real_t fetched_union;
int_or_real_t modified_union;

// Setting a union value


uvm_config_db#(int_or_real_t)::set(uvm_root::get(), "*", "my_union", my_union);

// Getting the union value


uvm_config_db#(int_or_real_t)::get(uvm_root::get(), "*", "my_union", fetched_union);

// Checking if the union exists


if (uvm_config_db#(int_or_real_t)::exists(uvm_root::get(), "*", "my_union")) begin
$display("Union exists in the config db.");
end else begin
$display("Union does not exist in the config db.");
end

// Waiting for the union value to be modified


uvm_config_db#(int_or_real_t)::wait_modified(uvm_root::get(), "*", "my_union", modified_union);

uvm_config_wrapper(Example with set, get, exists, and wait_modified)

// Define the wrapper class


class uvm_config_wrapper;
// Configuration variables
int value;
string description;
// Constructor to initialize the values
function new(input int v = 0, input string desc = "");
value = v;
description = desc;
endfunction
endclass
module top;
// Declare the wrapper object
uvm_config_wrapper config_wrapper;
uvm_config_wrapper fetched_wrapper;
uvm_config_wrapper modified_wrapper;
initial begin
// Initialize the wrapper with some values
config_wrapper = new(42, "Initial configuration");

// Set the wrapper object into the UVM Config DB uvm_config_db#(uvm_config_wrapper)::set(uvm_root::get(), "*",
"my_config_key", config_wrapper);

1/5/2025 Page 6
VIKRAM RENESAS

// Fetch the wrapper object from the config DB


uvm_config_db#(uvm_config_wrapper)::get(uvm_root::get(), "*", "my_config_key", fetched_wrapper);

// Check if the wrapper exists in the config DB


if (uvm_config_db#(uvm_config_wrapper)::exists(uvm_root::get(), "*", "my_config_key")) begin
$display("Config exists in the config db.");
end else begin
$display("Config does not exist in the config db.");
end

// Modify the fetched wrapper's values


modified_wrapper = new(100, "Modified configuration");
// Set the modified wrapper into the config DB
uvm_config_db#(uvm_config_wrapper)::set(uvm_root::get(), "*", "my_config_key", modified_wrapper);
// Wait for the configuration to be modified
uvm_config_db#(uvm_config_wrapper)::wait_modified(uvm_root::get(), "*", "my_config_key", modified_wrapper);
// Fetch the modified wrapper object
uvm_config_db#(uvm_config_wrapper)::get(uvm_root::get(), "*", "my_config_key", fetched_wrapper);
$display("Modified config - Value: %0d, Description: %s", fetched_wrapper.value, fetched_wrapper.description);

uvm_config_db_options

Methods

turn_on_tracing switch for UVM that dumps information on all the set() and get() calls within a simulation.
Turn tracing on for the configuration database. This causes all reads and writes to the database to display information
about the accesses. Tracing is off by default.
Switch +UVM_CONFIG_DB_TRACE
Declaration static function void turn_on_tracing()
// Turn on tracing for the configuration database
uvm_config_db#(int)::turn_on_tracing();
Example $display("Tracing is ON: %0d", uvm_config_db#(int)::is_tracing());

turn_off_tracing Turn tracing off for the configuration database.


Declaration static function void turn_off_tracing()
// Turn off tracing for the configuration database
uvm_config_db#(int)::turn_off_tracing();
Example $display("Tracing is OFF: %0d", uvm_config_db#(int)::is_tracing());

is_tracing Returns 1 if the tracing facility is on and 0 if it is off.


Declaration static function bit is_tracing()
// Check tracing status after turning it off
Example $display("Tracing is OFF after setting another value: %0d", uvm_config_db#(int)::is_tracing());

1/5/2025 Page 7
VIKRAM RENESAS

PART 2:
 APB UVM ENVIRONMENT FOR CONFIG DB TO EXPERIMENT ALL ABOVE METHODS AND EXAMPLES.
 UVM_RESOURSE_DB

1/5/2025 Page 8

You might also like