ClueLogic > UVM > UVM Tutorial for Candy Lovers – 9. Register Abstraction
This post will explain how to use the UVM Register Abstraction Layer (RAL) to generate register transactions. The figure
below shows the verification platform used for this post. Among other things, the jelly_bean_reg_block, the
jelly_bean_reg_adapter, and the jelly_bean_reg_predictor are the classes used for the register abstraction.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Verification Platform
The figure below shows the diagram of the RAL-related classes. The standard UVM classes are shown in pink, while the
jelly-bean classes are shown in light blue. The diagram looks busy, but bear in mind that I will explain each jelly-bean
class one by one.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Diagram of the Jelly-Bean-Register Related Classes
Register Definitions
In the previous posts, the DUT had no accessible registers. We are going to add the registers that hold jelly-bean recipe
information and its taste. We will also add a command input port to the DUT so that we can write a jelly-bean recipe to the
register and read its taste. The figure below shows the register definition of the DUT.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
DUT Registers
The source code of the DUT (jelly_bean_taster) is shown below. When the command input is WRITE, the values of flavor
color, sugar_free, and sour input ports are written to the RECIPE register (line 22 to 25). When the command input is READ
the TASTE register is read out and the taste output is driven accordingly (line 27).
Register Model
The model of the RECIPE register is defined by extending the uvm_reg class. Each field of the register is defined as a
uvm_reg_field (line 4 to 7). The fields are configured in the build function. Note that the name, build, is used for
convenience. Do not confuse it with the build_phase of the uvm_component because the uvm_reg is not a uvm_component
Register Block
The jelly_bean_reg_block contains the two registers created above and defines a register map.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
14 jb_recipe_reg.configure( .blk_parent( this ) );
15 jb_recipe_reg.build();
16
17 jb_taste_reg = jelly_bean_taste_reg::type_id::create( "jb_taste_reg" );
18 jb_taste_reg.configure( .blk_parent( this ) );
19 jb_taste_reg.build();
20
21 reg_map = create_map( .name( "reg_map" ), .base_addr( 8'h00 ),
22 .n_bytes( 1 ), .endian( UVM_LITTLE_ENDIAN ) );
23 reg_map.add_reg( .rg( jb_recipe_reg ), .offset( 8'h00 ), .rights( "WO" ) );
24 reg_map.add_reg( .rg( jb_taste_reg ), .offset( 8'h01 ), .rights( "RO" ) );
25 lock_model(); // finalize the address mapping
26 endfunction: build
27
28 endclass: jelly_bean_reg_block
Register Adapter
The jelly_bean_reg_adapter class provides two functions to convert between a uvm_reg_bus_op and a
jelly_bean_transaction. The reg2bus function converts a uvm_reg_bus_op into a jelly_bean_transaction, whereas
the bus2reg function converts a jelly_bean_transaction back to a uvm_reg_bus_op.
Advanced Topic: Even though a uvm_sequence is a uvm_sequence_item, you cannot let the reg2bus() function create a
uvm_sequence and return it. This is because when a register is read/written, the uvm_reg_map calls
uvm_sequence_base::start_item() passing the object returned by the reg2bus(), but the start_item() does not
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
expect a uvm_sequence. This will cause a fatal error. For more details, please see Register Access Methods.
Register Predictor
The register predictor updates the values of the register model based on observed bus transactions. As the jelly-bean
register predictor is not involved with any kind of extended features, the uvm_reg_predictor is used as is.
Agent
The jelly_bean_agent instantiates the jelly_bean_reg_adapter (line 35).
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
12 function new( string name, uvm_component parent );
13 super.new( name, parent );
14 endfunction: new
15
16 function void build_phase( uvm_phase phase );
17 super.build_phase( phase );
18
19 if ( ! uvm_config_db#( jelly_bean_agent_config )::get( .cntxt( this ),
20 .inst_name ( "" ),
21 .field_name( "jb_agent_cfg" ),
22 .value( jb_agent_cfg ))) begin
23 `uvm_error( "jelly_bean_agent", "jb_agent_cfg not found" )
24 end
25
26 jb_ap = new( .name( "jb_ap" ), .parent( this ) );
27 if ( jb_agent_cfg.active == UVM_ACTIVE ) begin
28 jb_seqr = jelly_bean_sequencer::type_id::create( .name( "jb_seqr" ),
29 .parent( this ) );
30 jb_drvr = jelly_bean_driver::type_id::create( .name( "jb_drvr" ),
31 .parent( this ) );
32 end
33 jb_mon = jelly_bean_monitor::type_id::create( .name( "jb_mon" ),
34 .parent( this ) );
35 jb_reg_adapter = jelly_bean_reg_adapter::type_id::create( .name( "jb_reg_adapter" ) );
36 endfunction: build_phase
37
38 function void connect_phase( uvm_phase phase );
39 super.connect_phase( phase );
40
41 jb_mon.jb_if = jb_agent_cfg.jb_if;
42 if ( jb_agent_cfg.active == UVM_ACTIVE ) begin
43 jb_drvr.seq_item_port.connect( jb_seqr.seq_item_export );
44 jb_drvr.jb_if = jb_agent_cfg.jb_if;
45 end
46 jb_mon.jb_ap.connect( jb_ap );
47 endfunction: connect_phase
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
48 endclass: jelly_bean_agent
Environment Configuration
The jelly_bean_env_config has a handle to the jelly_bean_reg_block so that the jelly_bean_env can access the
register model.
Environment
The jelly_bean_env instantiates the jelly_bean_agent and the jelly_bean_reg_predictor (line 28 to 31), then
connects register-related objects:
Firstly, in the connect_phase(), the set_sequencer() function associates the jelly-bean sequencer and the register
adapter with the register map (line 45 and 46). The set_sequencer() must be called before starting the sequence based
on a uvm_reg_sequence. A register block may have more than one register map.
Secondly, the register map and the register adapter are associated with the register predictor (line 49 and 50). The
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
register predictor will use the register map and the register adapter to convert a jelly_bean_transaction back to a
register operation.
Lastly, the register predictor is connected to the agent to subscribe the jelly_bean_transactions from the agent (line
51).
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
29 .parent( this ) );
30 jb_reg_predictor = jelly_bean_reg_predictor::type_id::create( .name( "jb_reg_predictor" ),
31 .parent( this ) );
32 if ( jb_env_cfg.has_jb_sb ) begin
33 jb_sb = jelly_bean_scoreboard::type_id::create( .name( "jb_sb" ),
34 .parent( this ) );
35 end
36 jb_fc_sub = jelly_bean_fc_subscriber::type_id::create( .name( "jb_fc_sub" ),
37 .parent( this ) );
38 endfunction: build_phase
39
40 function void connect_phase( uvm_phase phase );
41 super.connect_phase( phase );
42 jb_agent.jb_ap.connect( jb_fc_sub.analysis_export );
43 jb_agent.jb_ap.connect( jb_sb.jb_analysis_export );
44 if ( jb_env_cfg.jb_reg_block.get_parent() == null ) begin // if the top-level env
45 jb_env_cfg.jb_reg_block.reg_map.set_sequencer( .sequencer( jb_agent.jb_seqr ),
46 .adapter( jb_agent.jb_reg_adapter ) );
47 end
48 jb_env_cfg.jb_reg_block.reg_map.set_auto_predict( .on( 0 ) );
49 jb_reg_predictor.map = jb_env_cfg.jb_reg_block.reg_map;
50 jb_reg_predictor.adapter = jb_agent.jb_reg_adapter;
51 jb_agent.jb_ap.connect( jb_reg_predictor.bus_in );
52 endfunction: connect_phase
53
54 endclass: jelly_bean_env
Base Test
The base test instantiates a jelly_bean_reg_block (line 16 and 17) and stores its handle in the jelly_bean_env_config
(line 19 and 20).
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
18 endtask: body
19 endclass: jelly_bean_sequence
Register Test
The jelly_bean_reg_test creates a jelly_bean_reg_sequence we have just created and starts the sequence (line 12 to
15).
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Simulation
Let’s look at a simulation result. The simulation successfully generated a sour-green apple and read back its taste from the
DUT.
1 UVM_INFO jb3.sv(727) @ 30: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
2 ---------------------------------------------------------
3 Name Type Size Value
4 ---------------------------------------------------------
5 jb_tx jelly_bean_transaction - @7929
6 flavor jelly_bean_types::flavor_e 3 APPLE
7 color jelly_bean_types::color_e 2 GREEN
8 sugar_free integral 1 'h0
9 sour integral 1 'h1
10 command jelly_bean_types::command_e 2 WRITE
11 taste jelly_bean_types::taste_e 2 NO_TASTE
12 ---------------------------------------------------------
13
14 UVM_INFO jb3.sv(727) @ 60: uvm_test_top.jb_env.jb_sb [jelly_bean_scoreboard] You have a good sense of taste.
15 ----------------------------------------------------------
16 Name Type Size Value
17 ----------------------------------------------------------
18 jb_tx jelly_bean_transaction - @7928
19 flavor jelly_bean_types::flavor_e 3 NO_FLAVOR
20 color jelly_bean_types::color_e 2 NO_COLOR
21 sugar_free integral 1 'h0
22 sour integral 1 'h0
23 command jelly_bean_types::command_e 2 READ
24 taste jelly_bean_types::taste_e 2 YUMMY
25 ----------------------------------------------------------
I hope this tutorial helped you to understand the UVM Register Abstraction.
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com
Get source code
Share this:
Like this:
Loading...
Like
Be the first to like this.
UVM Tutorial for Candy Lovers – 8. Configurations UVM Tutorial for Candy Lovers – 10. Inside Candy
Factory
Jeremy says:
February 5, 2013 at 12:22 pm
open in browser PRO version Are you a developer? Try out the HTML to PDF API pdfcrowd.com