下冰雹 · 2022年11月10日 · 北京市

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
作者: 芯片验证工程师
文章来源:芯片验证工程师

推荐阅读

更多IC设计技术干货请关注IC设计技术专栏。
迎添加极术小姐姐微信(id:aijishu20)加入技术交流群,请备注研究方向。
推荐阅读
关注数
11351
内容数
1224
主要交流IC以及SoC设计流程相关的技术和知识
目录
极术微信服务号
关注极术微信号
实时接收点赞提醒和评论通知
安谋科技学堂公众号
关注安谋科技学堂
实时获取安谋科技及 Arm 教学资源
安谋科技招聘公众号
关注安谋科技招聘
实时获取安谋科技中国职位信息