UVM实战指南(5)

2019-08-30 16:37

第13行:city组件中包含一个street子组件 第19行:street在build()阶段通过工厂模式被创建

第26行:在run()方法中,city调用get_child(),得到street子组件的信息。 第27行:get_parent()函数返回city的父组件,即state. 第28行:get_full_name()函数返回关于父组件的完整的层次结构 第47-48行:实例化创建两个state对象,也通过工厂模式创建 第50行:调用run_test()开始UVM的各阶段仿真。 结果如下:

---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- Florida state - @580 Capital_City city - @711 Main_St street - @712 ---------------------------------------------------------------------- ---------------------------------------------------------------------- Name Type Size Value ---------------------------------------------------------------------- New_York state - @638 Capital_City city - @776 Main_St street - @769 ----------------------------------------------------------------------

UVM_INFO @0: New_York.Capital_City [city] Parent:New_York Child:Main_St UVM_INFO @0: New_York.Capital_City.Main_St [INFO1] I vacationed here in 2010 UVM_INFO @0: Florida.Capital_City [city] Parent:Florida Child:Main_St UVM_INFO @0: Florida.Capital_City.Main_St [INFO1] I vacationed here in 2010 Simulation complete via $finish(1) at time 100 NS + 0 ./uvm_st_ci_st.sv:75 initial #100 $finish;

4.4.3 组件uvm_top

有一个特殊的UVM组件叫做\。此组件是uvm_root类的单一实例,也是由

uvm_component继承而来。uvm_top组件负责对所有的组件进行阶段控制,并且提供了查找功能(uvm_top.find()和uvm_top.find_all()),方便定位一些特定的组件。uvm_top组件还提供了一个存储全局配置的地方。调用set_config_*()函数相当于调用uvm_top.set_config_*(). 对消息打

印函数也如此,调用uvm_report_*(或者`uvm_info/warning/error/fatal)等价于调用uvm_top.uvm_report*函数。

4.5 UVM配置机制

通用的验证组件复用的一个重要方面是其具备可以配置为期望的工作模式的能力。UVM提供了一个灵活的配置机制,允许在运行时配置属性和组件拓扑结构,而不需要派生和使用工厂模式。组件属性的配置通过set_config* 应用接口界面(API)来实现,包括以下3个API:

virtual function void set_config_int (string inst_name,string field_name, uvm_bitstream_t value)

virtual function void set_config_string (string inst_name,string field_name, string value ) virtual function void set_config_object (string inst_name, string field_name,uvm_object value, bit clone = 1 )

参数描述: ? ? ?

inst_name: 组件的层次路径,可以使用通用字符“*”

field_name:需要配置的字段名字,此字段在对象实例中有定义.

value: 字段配置值. 根据set_config的调用不同,可以是uvm_bitsream, string或者uvm_object类型的值 ?

clone: 仅对set_config object有效,表示提供一个不同的拷贝,或者仅仅传递value对象的引用

通过umv_field_*宏注册的UVM属性字段将会自动的通过组件的super.build()方法进行更新。这些属性可以用来控制组件build()方法的执行。同时,也可以通过get_config_*方法在build()阶段之前手动的获得配置值。 注意: 如果要影响测试向量的拓扑结构,配置设定必须在build阶段之前完成。 下面的实例演示了配置机制的使用,我们通过使用配置机制来设置state的名字和每个state的投票数。 实例4-6: 配置机制 1. 2. 3.

module test;

class state extends uvm_component; string state_name;

4. 5. 6. 7. 8. 9.

int unsigned num_votes;

// Configurable fields must use the field declaration macros. Use the // UVM_READONLY flag if the property should not be configurable. `uvm_component_utils_begin(state)

`uvm_field_string(state_name, UVM_DEFAULT) `uvm_field_int(num_votes, UVM_DEFAULT | UVM_DEC)

10. `uvm_component_utils_end

11. function new(string name, uvm_component parent); 12. super.new(name, parent); 13. endfunction : new

14. function void end_of_elaboration(); 15. this.print();

16. endfunction : end_of_elaboration 17. endclass : state

18. state my_state1, my_state2; 19. initial begin

20. // configure BEFORE create

21. set_config_string(\ 22. set_config_string(\ 23. set_config_int(\ 24. // create

25. my_state1 = state::type_id::create(\ 26. my_state2 = state::type_id::create(\ 27. fork 28. run_test();

29. #100 global_stop_request(); 30. join 31. end

32. endmodule : test

第23行:我们使用“*”来配置num_votes字段。所有的state都将使用此配置值。 下面的信息显示了在end_of_elaboration阶段之后组件的配置信息。

--------------------------------------------------------------- Name Type Size Value --------------------------------------------------------------- my_state1 state - @16 state_name string 7 GEORGIA

num_votes integral 32 'd7 --------------------------------------------------------------- my_state2 state - @18 state_name string 11 CONNECTICUT num_votes integral 32 'd7 ---------------------------------------------------------------

下面的例子演示了如何使用get_config*调用。如果不使用自动宏,或者需要在build()前或后询问设定时,我们使用此函数。此例子中我们使用get_config_int来决定是否需要创建覆盖率组(covergroup)。

1. 2.

module test;

typedef enum bit [2:0] {FLORIDA, NEW_YORK, GEORGIA, CALIFORNIA, MICHIGAN,

3. 4. 5. 6. 7. 8. 9.

TEXAS, MARYLAND, CONNECTICUT} state_name_enum; class state extends uvm_component; bit coverage_enable = 1; state_name_enum = FLORIDA; `uvm_component_utils_begin(state)

`uvm_field_string(state_name_enum, state_name, UVM_DEFAULT) `uvm_field_int(coverage_enable, UVM_DEFAULT|UVM_READONLY)

10. `uvm_component_utils_end 11. covergroup state_cg; 12. coverpoint state_name; 13. endgroup : state_cg

14. function new(string name=\ 15. super.new(name, parent);

16. void'(get_config_int(\); 17. if (coverage_enable)

18. state_cg = new(); // covergroup must be new’ed in constructor 19. endfunction : new

20. function void end_of_elaboration(); 21. if(coverage_enable) state_cg.sample(); 22. this.print();

23. endfunction : end_of_elaboration 24. endclass : state 25. state my_state; 26. initial begin

27. set_config_int(\ 28. set_config_int(\ 29. my_state = state::type_id::create(\ 30. fork 31. run_test(); 32. #100 $finish; 33. join 34. end

35. endmodule : test

第16行:既然covergroup只能在构造函数中创建,因此我们必须在构造函数中调用get_config_int()来获取coverage_enable字段值。其他的字段值在build()阶段获得(注:前提是umv_field_*宏注册过的

field)。

第28行:将my_state的coverage_enable设置为0,此例子中,coverage组将不被创建。

下次内容: UVM事务级建模(TLM)

UVM实战指南——第3部分

2010-12-30 18:02:53| 分类: SystemVerilog|字号 订阅

译者序:

英文来源:

http://www.low-powerdesign.com/article_Cadence-UVM_101010.html

(*)题外话:TLM可能是UVM中最重要的概念,掌握了TLM,就可以开始尝试编写一些小程序了。翻译这篇文章,也是为了巩固加强对TLM的理解。

(*)几个名词:transaction翻译为事务或者交易;packet翻译为封包,packet属于transaction;monitor翻译为监视器;driver翻译为驱动器;scoreboard翻译为记分牌;有些词汇直接被运用到UVM源代码上,所以有时候用英文更容易描述清楚。 (*)语言的目的是为了交流,翻译不是为了纯粹的语言转换,而是为了传递思想。

4.6 UVM中事务级建模(TLM)


UVM实战指南(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《苹果树上的外婆》整本书读书规划

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: