从testbench访问uvm_config_db的最佳方法是什么?

ngu*_*rie 10 verilog system-verilog uvm

我想在我的顶级测试平台中创建一个时钟,其周期可以从测试中控制.我所做的是将句点设置为uvm_config_db并将其恢复到测试平台中.我必须输入#1以确保构建阶段已完成,否则get返回错误的值:

module testbench_top;
  int clk_period;

  bit clk = 0;

  initial begin
    #1;    
    void'(uvm_config_db #(int) ::get(null, "uvm_test_top.env", "clk_period", clk_period));
    // Create clk
    forever begin
      #(clk_period/2) clk = !clk;
    end
  end
Run Code Online (Sandbox Code Playgroud)

我被#1烦恼了.有没有更好的方法来检查配置是否已设置?我可以以某种方式阻止直到start_of_simulation_phase?

ngu*_*rie 13

我发现它隐藏在类引用中:您可以访问每个阶段的全局单例版本<phase name>_ph.然后我可以使用该wait_for_state函数来阻止,直到模拟阶段开始.模拟,它似乎工作:

module testbench_top;
  int clk_period;

  bit clk = 0;

  initial begin
    start_of_simulation_ph.wait_for_state(UVM_PHASE_STARTED);    
    if(!uvm_config_db #(int) ::get(null, "uvm_test_top.env", "clk_period", clk_period))
      `uvm_fatal("CONFIG", "clk_period not set");
    // Create clk
    forever begin
      #(clk_period/2) clk = !clk;
    end
  end
Run Code Online (Sandbox Code Playgroud)