即时更改时钟块时钟极性

Changing clocking block clock polarity on the fly

我正在创建能够切换其时钟极性的 UVM VIP。接口中使用时钟块。 例如,监视器应根据 UVM 配置使用传入时钟的上升沿或下降沿对数据进行采样 - 这种极性变化可能会在运行中发生。

可以这样实现:

// In the interface, two clocking blocks are defined
// one for posedge (passive_cb), one for negedge (passive_cbn).

task wait_clock_event();
   if (cfg.pol == 0) @vif.passive_cb;
   else @vif.passive_cbn;
endtask

task sample_data();
  if (cfg.pol == 0) pkt.data = vif.passive_cb.data;
  else pkt.data = vif.passive_cbn.data;
endtask

task run();
  wait_clock_event();
  sample_data();
endtask

这似乎可行,但会浪费代码行并且容易出错。

有没有更好的解决方案?

假设监视器对时钟块具有独占访问权限,您可以考虑使用 iff 限定符修改界面中的时钟事件。

bit pol;
clocking passive_cb @(posedge clk iff !pol, negedge clk iff pol);
  input data;
endclocking

如果 pol 在与目标时钟极性相同的时间步长内发生变化,则存在潜在的竞争条件。

然后您的监视器代码将包含一个设置函数,其他任务可以简化为我们只需要一个时钟块。

function void set_vifcb_pol();
  vif.pol = cfg.pol;
endfunction

task wait_clock_event();
  @vif.passive_cb;
endtask

task sample_data();
  pkt.data = vif.passive_cb.data;
endtask

task run();
  set_vifcb_pol();
  wait_clock_event();
  sample_data();
endtask