ARM技术论坛
直播中

王艳

8年用户 1372经验值
私信 关注
[经验]

SV Structure作为module的input/output

在SV中可以使用结构体作为模块的输入或输出,这使得它可以更加清晰地传递更多的信号,以简化RTL代码,类似于interface。

typedef struct {
 bit [7:0] intr = 'h AA;
 logic [23:0] addr = 'h FF_FF_FF;
 } ext;
 
 module SU (
 output ext extOut);
 
 assign extOut = '{intr: 8'hFF, addr:24'haa_aa_aa};
 initial begin
 #1; $display($stime,,, "extOut = %p", extOut);
 end
 endmodule
 
 module top;
 ext extIn;
 //connect extOut of 'SU' with extIn of 'top'
 SU SUInst(.extOut(extIn));
 initial begin
 #2; $display($stime,,, "extIn = %p", extIn);
 end
 endmodule

仿真log:

1 extOut = '{intr:'hff, addr:'haaaaaa}
 2 extIn = '{intr:'hff, addr:'haaaaaa}
 V C S S i m u l a t i o n R e p o r t

在上面的例子中,我们首先定义了一个名为“ext”的unpacked struct,然后直接作为module的output。

再声明一个moudle top,连接到这个struct。最后打印表明这个结构体确实完成了连接,打印相同的信息。

struct可以作为参数传递给task或function,前提是这个struct需要先使用typedef声明为用户自定义类型

typedef struct {
 logic [31:0] addr;
 logic [63:0] data;
 logic [3:0] BEnable;
 } control;
 function Dbus (input control ct1);
 ….
 endfunction

原作者: 芯片验证工程师

更多回帖

发帖
×
20
完善资料,
赚取积分