【UVM源码学习】uvm_coreservice


  uvm_coreservice.svh提供了一系列uvm_factory、uvm_report_server、uvm_root、uvm_component等UVM核心功能共同需要的方法。该文件中主要实现了两个类,一是uvm_coreservice_t,一是uvm_default_coreservice


  uvm_coeservice_t,基类,提供以下表格中的纯虚函数,用户使用时需自定义。uvm_default_coreservice,派生自uvm_coreservice_t,uvm_coreservice中纯虚函数的默认实现。

序号方法描述
1get_factory返回当前所有使能的uvm factory
2set_factory设置当前的uvm factory
3get_report_server返回当前的全局report_server
4set_report_server设置当前的report_server
5get_default_tr_database返回当前默认database
6set_default_tr_database设置当前默认database
7set_component_visitor设置component_visitor,这些visitor在end_of_elaboration_phase中会用到
8get_component_visitor返回当前的component visitor
9get_root返回uvm_root例化
10inst coreservice type,用户定义
11get返回inst,为空则new一个



请逐行注释下面的代码:class riscv_instr_base_test extends uvm_test; riscv_instr_gen_config cfg; string test_opts; string asm_file_name = "riscv_asm_test"; riscv_asm_program_gen asm_gen; string instr_seq; int start_idx; uvm_coreservice_t coreservice; uvm_factory factory; uvm_component_utils(riscv_instr_base_test) function new(string name="", uvm_component parent=null); super.new(name, parent); void'($value$plusargs("asm_file_name=%0s", asm_file_name)); void'($value$plusargs("start_idx=%0d", start_idx)); endfunction virtual function void build_phase(uvm_phase phase); super.build_phase(phase); coreservice = uvm_coreservice_t::get(); factory = coreservice.get_factory(); uvm_info(gfn, "Create configuration instance", UVM_LOW) cfg = riscv_instr_gen_config::type_id::create("cfg"); uvm_info(gfn, "Create configuration instance...done", UVM_LOW) uvm_config_db#(riscv_instr_gen_config)::set(null, "*", "instr_cfg", cfg); if(cfg.asm_test_suffix != "") asm_file_name = {asm_file_name, ".", cfg.asm_test_suffix}; // Override the default riscv instruction sequence if($value$plusargs("instr_seq=%0s", instr_seq)) begin factory.set_type_override_by_name("riscv_instr_sequence", instr_seq); end if (riscv_instr_pkg::support_debug_mode) begin factory.set_inst_override_by_name("riscv_asm_program_gen", "riscv_debug_rom_gen", {gfn, ".asm_gen.debug_rom"}); end endfunction function void report_phase(uvm_phase phase); uvm_report_server rs; int error_count; rs = uvm_report_server::get_server(); error_count = rs.get_severity_count(UVM_WARNING) + rs.get_severity_count(UVM_ERROR) + rs.get_severity_count(UVM_FATAL); if (error_count == 0) begin uvm_info("", "TEST PASSED", UVM_NONE); end else begin uvm_info("", "TEST FAILED", UVM_NONE); end uvm_info("", "TEST GENERATION DONE", UVM_NONE); super.report_phase(phase); endfunction virtual function void apply_directed_instr(); endfunction task run_phase(uvm_phase phase); int fd; for(int i = 0; i < cfg.num_of_tests; i++) begin string test_name; randomize_cfg(); riscv_instr::create_instr_list(cfg); riscv_csr_instr::create_csr_filter(cfg); asm_gen = riscv_asm_program_gen::type_id::create("asm_gen", , gfn); asm_gen.cfg = cfg; asm_gen.get_directed_instr_stream(); test_name = $sformatf("%0s_%0d.S", asm_file_name, i+start_idx); apply_directed_instr(); uvm_info(gfn, "All directed instruction is applied", UVM_LOW) asm_gen.gen_program(); asm_gen.gen_test_file(test_name); end endtask virtual function void randomize_cfg(); DV_CHECK_RANDOMIZE_FATAL(cfg); uvm_info(`gfn, $sformatf("riscv_instr_gen_config is randomized:\n%0s", cfg.sprint()), UVM_LOW) endfunction endclass
05-24
uvm_active_passive_enum 是 UVM (Universal Verification Methodology) 中定义的一个枚举类型,用于区分 UVM 组件(如 agent)的工作模式是主动(active)还是被动(passive)。在 UVM 中,agent 组件可以是主动的,也可以是被动的,这取决于其子组件的行为。 - 主动模式(active): 在主动模式下,agent 会生成事务(transactions),并将其发送到被测设备(DUT)。主动 agent 通常包含 sequencer,它负责从 sequencer 获取序列并发送事务到驱动(driver)。 - 被动模式(passive): 被动模式下,agent 不生成事务,而是响应来自其他主动 agent 的事务。被动 agent 不包含 sequencer,而是可能包含监视器(monitor)和检查器(checker),用于观察通信并进行验证。 uvm_active_passive_enum 通常用于 agent 的构造函数中,以便在创建 agent 实例时指定其模式。例如: ```verilog class my_agent extends uvm_agent; `uvm_component_utils(my_agent) uvm_active_passive_enum m_mode; // 枚举类型的成员变量 function new(string name, uvm_component parent); super.new(name, parent); endfunction virtual function void build_phase(uvm_phase phase); // 根据 m_mode 的值决定构建主动或被动 agent case(m_mode) UVM_ACTIVE: begin // 构建主动 agent 相关组件 end UVM_PASSIVE: begin // 构建被动 agent 相关组件 end default: `uvm_fatal("MODE", "Invalid agent mode") endcase endfunction endclass ``` 在 UVM 的配置中,可以通过 uvm_config_db#() 来设置 agent 的模式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MangoPapa

请作者喝瓶可乐吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值