首页 > 解决方案 > 写入时钟块之前的 SystemVerilog 计算

问题描述

我有一个任务,它的工作是通过时钟块将数据驱动到总线上。见片段:

task effects_driver::ReadQueueData();
  stream_intf_.cycles(); // clocking block event
  if (sample_q_.size() >= 2) // check to see if there is enough data in the queue
    begin
      automatic bit [31:0] sample0, sample1;
      sample0 = sample_q_.pop_front(); // read from queue
      sample1 = sample_q_.pop_front(); // read from queue
      stream_intf_.cb.AXIS_TDATA <= {sample1, sample0}; // drive two samples at once
      stream_intf_.cb.AXIS_TVALID <= 1;
    end
  else
    ...
endtask

您会注意到,我需要先从队列中读取几个项目,然后再将其写入时钟块。这是正确的方法吗?我是否保证模拟器会在将自动变量写入时钟块之前对其执行这些阻塞分配?

谢谢!

PS 我经常遇到这种情况——我需要在写入时钟块之前即时进行一些快速计算。

标签: blockingnonblockinghdl

解决方案


我相信您的意思是问“我是否保证模拟器会在将自动变量写入时钟块之前对其执行这些阻塞分配?” 因为这就是你的代码正在做的事情。

答案是肯定的,阻塞赋值保证在执行后面的语句之前完成。

另请注意,不需要声明sample0andsample1具有自动生命周期,因为类方法始终具有自动生命周期。其中声明的变量是隐式自动的。


推荐阅读