Вы находитесь на странице: 1из 25

 info@cluelogic.

com Welcome to ClueLogic

ClueLogic Search... Search


Provi d i n g th e cl u es to sol ve you r veri fi cati on p rob l ems

Home Services Events ClueBlog About 

ClueLogic > UVM > UVM Tutorial for Candy Lovers – 16. Register Access Methods

UVM Tutorial for Candy Lovers – 16. Register Access


Methods
 February 1, 2013  Keisuke Shimizu

Last Updated on April 11, 2014

The register abstraction layer (RAL) of UVM provides several methods to access registers. This post will explain how the
register-access methods work. In Register Abstraction, we introduced the overview of RAL and explained how to define
registers. In this post, we will cover how to access the registers.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Properties of uvm_reg_field
Before diving into the register-access methods, let’s look at how a register value is stored. As seen in Register Abstraction
uvm_reg_field is the lowest register-abstraction layer which represents the bits of a register. The uvm_reg_field uses
several properties to store a variety of register-field values:

m_reset["HARD"] stores a hard reset value. Note that the m_reset is an associative array with a kind of reset as the
key.
m_mirrored stores the value of what we think in our design under test (DUT).
m_desired stores the value of what we want to set to the DUT.
value stores the value to be sampled in a functional coverage, or the value to be constrained when the field is
randomized.

Note that among these properties, only the value property is public. The other properties are local, thus we cannot access
them directly from the out side of the class. We will show you how to access these local properties using register-access
methods later.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Properties of uvm_reg_field

configure()
The first thing we do after creating a uvm_reg_field is configuring it. In Register Abstraction, we configured the flavor
field as follows. Note that in Register Abstraction, we defined the flavor field as "WO" (write-only), but we defined it as
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
"RW" (read/write) here to make the field more generic.

1 flavor = uvm_reg_field::type_id::create( "flavor" );


2 flavor.configure( .parent ( this ),
3 .size ( 3 ),
4 .lsb_pos ( 0 ),
5 .access ( "RW" ),
6 .volatile ( 0 ),
7 .reset ( 0 ),
8 .has_reset ( 1 ),
9 .is_rand ( 1 ),
10 .individually_accessible( 0 ) );

If the has_reset argument is 1, the value of reset argument is taken as the "HARD" reset value. If the has_reset value is
0, the value of reset is ignored. The value of reset should match the reset state of the DUT. If you want to modify the
reset value after the configuration, you can use set_reset() method.

flavor.set_reset( .value( 0 ), .kind( "HARD" ) ); // kind == "HARD" by default

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the configure() and set_reset() methods work

reset()
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The reset() method resets the properties of a register field, if the m_reset[kind] exists. The default kind is "HARD". If
the m_reset[kind] does not exist, the reset() method does nothing. Note that the reset() method does not reset a
register in the DUT. It only resets the properties of a register-field object.

flavor.reset( .kind( "HARD" ) ); // kind == "HARD" by default

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the reset() method works

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
set()
The set() method sets the desired value of a register field. The set() method does not set the value to a register in the
DUT. It only sets the value to the m_desired and the value properties of a register-field object. To actually set the value to
the register in the DUT, use write() or update() method. These methods will be explained later.

flavor.set( .value( 1 ) );

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the set() method works

get()
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The get() method gets the desired value of a register field. The get() method does not get the value from a register in
the DUT. It only gets the value of the m_desired property. To actually get the value from the DUT, use read() or mirror()
methods. These methods will be explained later. Similarly to the get() method, there are two more getters to access the
local properties. The get_reset() retrieves the value of the m_reset[kind] property, while the get_mirrored_value()
method retrieves the value of the m_mirrored property.

uvm_reg_data_t desired_value = flavor.get();


uvm_reg_data_t reset_value = flavor.get_reset( .kind( "HARD" ) ); // kind == "HARD" by default
uvm_reg_data_t mirrored_value = flavor.get_mirrored_value();

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the get(), get_reset(), and get_mirrored_value() methods work

randomize()
The randomize() method is a SystemVerilog method. It randomizes the value property of a register-field object. After the
randomization, the post_randomize() method copies the value of the value property to the m_desired property. Note
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
that the pre_randomize() method copies the value of the m_desired to the value property if the rand_mode of the value
property is OFF.

assert( flavor.randomize() );

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the randomize() method works

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
write()
The write() method actually writes a value to the DUT.

uvm_status_e status;

flavor.write( .status( status ), .value( 1 ) );

The write() method involves multiple steps.

1. A uvm_reg_item object corresponding to the write operation is created.


2. The uvm_reg_adapter converts the write operation to a corresponding bus transaction.
3. The uvm_driver executes the bus transaction to the DUT.
4. The uvm_monitor captures the bus transaction.
5. The uvm_reg_predictor asks the uvm_reg_adapter to convert the bus transaction to a corresponding register
operation.
6. The register operation is converted to a uvm_reg_item.
7. The uvm_reg_item is used to update the value, m_mirrored, and m_desired properties.

Note that if the individually_accessible argument was 0 when the register field was configured, the entire register
containing the field is written, because the field is not individually accessible. In this case, the m_mirrored values are used
as the write values for the other fields.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the write() method works

read()
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The read() method actually reads a register value from the DUT.

uvm_status_e status;
uvm_reg_data_t value;

flavor.read( .status( status ), .value( value ) );

Similarly to the write() method, the read() method involves multiple steps.

1. A uvm_reg_item object corresponding to the read operation is created.


2. The uvm_reg_adapter converts the read operation to a corresponding bus transaction.
3. The uvm_driver executes the bus transaction to the DUT.
4. The uvm_reg_apapter converts the bus transaction with read data to a register operation.
5. The read() method returns the read value to the caller.
6. In the mean time, the uvm_monitor captures the bus transaction.
7. The uvm_reg_predictor asks the uvm_reg_adapter to convert the bus transaction to a corresponding register
operation.
8. The register operation is converted to a uvm_reg_item.
9. The uvm_reg_item is used to update the value, m_mirrored, and m_desired properties.

Note that if the individually_accessible argument was 0 when the register field was configured, the entire register
containing the field is read. In this case, the m_mirrored values are updated for the other fields as well.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the read() method works

update()
The update() method actually writes a register value to the DUT. The update() method belongs to the uvm_reg class. The
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
uvm_reg_field class does not have the update() method.

uvm_status_e status;

jb_recipe_reg.update( .status( status ) );

The differences between the write() method and the update() method are:

The write() method takes a value as its argument, while the update() method uses the value of the m_desired
property as the value to write.
The update() method writes the value only if the m_mirrored and the m_desired are not equal.

Before the update() is executed


open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The update() method internally calls the write( .value( m_desired ) ). Because of this, the value of the m_mirrored
will be updated as well, after the update.

After the update() is executed

mirror()
The mirror() method actually reads a register from the DUT.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
uvm_status_e status;

flavor.mirror( .status( status ), .check( UVM_CHECK ) );

The differences between the read() method and the mirror() method are:

The read() method returns the register value to the caller, while the mirror() method does not return the register
value. The mirror() method only updates the value of the m_mirrored property.
The mirror() method compares the read value against the m_desired if the value of the check argument is
UVM_CHECK. Note that the UVM Class Library document states that it compares the read value against the mirrored
value, but if you look at the line 2,944 of uvm_reg.svh of uvm-1.1c code base, it actually compares against the desired
value, not against the mirrored value.

April 11, 2014: uvm-1.1d code base has corrected this issue. The mirror() compares the read value against the
mirrored value now. Please see the line 2,951 of uvm_reg.svh if you are curious about this fix.)

Another caveat about the check is that if you set the volatile argument to be 1 when you configured the register
field, the register field won’t be checked even though you set the check argument to be UVM_CHECK. This is because we
cannot predict the value of the register field deterministically as it might have been changed (volatile) in the DUT.

The mirror() method internally calls do_read() method. This is the same method the read() method internally calls.
Because of this, the mirror() method will update the value and the m_desired properties, in addition to the m_mirrored
property.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the mirror() method works

predict()
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
The predict() method updates the mirrored value.

flavor.predict( .value( 1 ) );

The predict() method also updates the value and the m_desired properties.

open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
How the predict() method works

Summary
The table below summarizes how each method updates the properties of the register-field object.

m_reset
Method ["HARD"] value m_desired m_mirrored DUT

configure set the value of


(.reset(val), val
.has_reset(1))

set_reset(val) set the value of


val

reset() copy the value copy the value of copy the value of
of m_reset m_reset m_reset
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
of
["HARD"] ["HARD"] ["HARD"]

set(val) set the value of set the value of


val val

get_reset() return the


value of
m_reset
["HARD"]

get() return the value


of m_desired

get_mirrored_value() return the value


of m_mirrored

randomize() randomize copy the value of


value

write(.value(val)) set the value of set the value of set the value of write the value
val val val of val

read(.value(val)) set the read set the read set the read value read the
value value register

update() set the value of set the value of set the value of write the value
m_desired m_desired m_desired of m_desired

mirror() set the read set the read set the read value read the
value value register

predict set the value of set the value of set the value of
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
predict set the value of set the value of set the value of
(.value(val)) val val val

In this post, we only covered so-called front-door access. We will cover back-door access in a separate post. I hope this
tutorial helped you to understand the register access methods.

Share this:

LinkedIn 4 Facebook Google Twitter Email Print

Like this:

Loading...

Like
Be the first to like this.

 UVM  configure, get, get_mirrored_value, get_reset, m_desired, m_mirrored, m_reset, mirror, predict, randomize, read,
reset, set, set_reset, update, uvm_reg, uvm_reg_adapter, uvm_reg_data_t, uvm_reg_field, uvm_reg_item, uvm_reg_predictor, write

UVM Tutorial for Candy Lovers – 15. “Do” Hooks UVM Tutorial for Candy Lovers – 17. Register Read
Demystified

78 thoughts on “UVM Tutorial for Candy Lovers – 16. Register Access Methods”

Arun says:
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com

Вам также может понравиться