我们说我有双向接口。我希望TB能够从DUT接收数据,我希望TB能够将数据驱动到DUT。我需要在代码中放入clocking
块,因为我遇到了竞争条件问题。我可以通过在正确的位置放置一个#1来解决这些问题,但我知道时钟块是正确的解决方案。 I部分遇到困难的部分是双向部分。如果它是一个方向我可能没问题,但双向接口的语法正在绊倒我。是制作2个时钟模块,2个modports还是其他东西的正确解决方案?
interface MyInterface
(input bit i_Clk);
logic [15:0] r_Data;
logic r_DV = 1'b0;
clocking CB @(posedge i_Clk);
default input #1step output #1step;
endclocking : CB
task t_Clock_Cycles(int N);
repeat (N) @(posedge i_Clk);
endtask : t_Clock_Cycles
modport Driver (clocking CB, output r_Data, r_DV);
modport Receiver (clocking CB, input r_Data, r_DV);
endinterface : MyInterface
package MyPackage;
class MyDriver;
virtual MyInterface.Driver hook;
function new(virtual MyInterface.Driver hook);
this.hook = hook;
endfunction : new
task t_Drive(input [15:0] i_Data);
forever
begin
hook.CB.r_Data = i_Data;
hook.CB.r_DV = 1'b1;
hook.CB.t_Clock_Cycles(1);
end
endtask : t_Drive
endclass : MyDriver
endpackage : MyPackage
module MyModule;
import MyPackage::*;
logic r_Clk = 1'b0;
MyInterface hook(.i_Clk(r_Clk));
always #5 r_Clk = ~r_Clk;
MyDriver d1 = new(hook.Driver);
initial
begin
d1.t_Drive(16'hABCD);
end
endmodule // MyModule
答案 0 :(得分:1)
使用时钟模块的重点是声明要同步访问哪些信号。您应该将信号添加到时钟模块中:
clocking CB @(posedge i_Clk);
default input #1step output #1step;
inout r_Data;
inout r_DV;
endclocking : CB
由于您还希望对驱动程序和接收器具有不同的访问权限,这意味着您需要两个不同的时钟块:
clocking CB_driver @(posedge i_Clk);
default input #1step output #1step;
output r_Data;
output_DV;
endclocking : CB_driver
// ... direction reversed for CB_receiver
不幸的是,你不可能说你的驱动程序/接收器类中有某个时钟块的引用:
class Driver
virtual MyInterface.CB_driver hook; // !!! Not allowed
endclass
如果您想限制您的驱动程序只能通过CB_driver
,那么您可以使用modport
:
interface MyInterface;
modport Driver(CB_driver);
endinterface
class Driver;
virtual MyInterface.Driver hook;
endclass
这样,您可以在驾驶信号时参考hook.CB_driver
。您的接收器也是如此。