简体   繁体   中英

Specman UVM: What is the difference between access a register directly and using read_reg_val()?

I'm working with vr_ad package for e. I've defined a register my_reg in the vr_ad_reg_file my_reg_file :

reg_def MY_REG MY_REG_FILE 20'h00018 {
    reg_fld my_reg_field     : uint (bits : 32)  : RW : 0x0;
};

I would like to access the value of the register. What is the difference (if any) between accessing the register directly:

some_var = my_reg_file.my_reg.my_reg_field;

and accessing the register using read_reg_val() :

some_var = my_reg_file.my_reg.read_reg_val();

Thank you for your help.

In your case, since your register has only one field, there are none. But to understand a bit deeper let's take the case where your register were defined like this:

reg_def MY_REG MY_REG_FILE 20'h00018 {
    reg_fld my_reg_field     : uint (bits : 32)  : W : 0x0;
};

Notice I made the field write only. Let's say your field gets updated with a value of 0x1010_1010 .

Calling my_reg.my_reg_field will return this value, 0x1010_1010 .

The read_reg_val() method returns the value you would get when doing a read access to this register. In this case, since the field is not readable, you'd get 0x0000_0000 (this value is configurable, but per default it's the reset value).

There is also a read_reg_rawval() method that returns the value that is stored in the register (ie it ignores the access policies of the fields). In our case it would return the value stored in the field, 0x1010_1010 .

read_reg_val() and read_reg_rawval() are useful when you have multiple fields declared in a register, because these methods will pack the values of all of them and return you a scalar value (of type vr_ad_data_t ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM