温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

SystemVerilog中的package怎么在设计中使用

发布时间:2021-12-17 16:35:11 来源:亿速云 阅读:331 作者:iii 栏目:互联网科技

这篇文章主要介绍“SystemVerilog中的package怎么在设计中使用”,在日常操作中,相信很多人在SystemVerilog中的package怎么在设计中使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”SystemVerilog中的package怎么在设计中使用”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

SystemVerilog中的packages用于在不同module和interface之间共享parameters、types、tasks和functions。

packages是一个name space,其和top level在同一个层次。

在任何SystemVerilog/Verilog设计项目中,设计团队通常都会共享一些parameters、types、tasks和functions。将这些通用结构放入packages中,就可以在团队中进行共享。

在packages中指定所有通用结构后,需要先analyze package。然后单独analyze和elaborate使用该packages中某些parameters、types、tasks和functions的模块。

无需reanalyze 这个package,当共享packages很大时,可以节省很多运行时间。

但是在使用packages时:

•不允许使用wirereg声明。

•packages内部声明的tasks和functions需要是automatic的。

•sequence, property和 program将被忽略

下面的例子中,有三个文件。test1.svtest2.sv文件要访问pkg1 package中的声明,使用“”运算符解析这些type声明(package_name :: type_name)和function声明(package_name :: function_name)。


package pkg1;  typedef struct {int a;logic b;} my_struct;  typedef logic [127:0] my_T;  function automatic my_T subtract(my_T one, two);    return(one - two);  endfunction  function automatic my_struct complex_add(my_struct one, two);    complex_add.a = one.a + two.a;    complex_add.b = one.b + two.b;  endfunctionendpackage : pkg1

package.sv—包含两个types(my_structmy_T),和两个functions(subtract
complex_add


module test1 (  input pkg1::my_T in1, in2,  input [127:0]test_vector,  output pkg1::my_T result,  output equal  );  assign result = pkg1::subtract(in1, in2);  assign equal = (in1 == test_vector);endmodule

test1.sv—使用my_T type 和subtract function


module test2 (input pkg1::my_struct in1, in2,output pkg1::my_struct result2);assign result2 = pkg1::complex_add(in1, in2);endmodule

 test2.sv—使用my_struct type和complex_add function

我们首先分析package.sv文件以创建临时pkg1.pvk文件。然后分别再analyze和elaborate test1和test2文件。

# Analyze the package file the first time, it creates pkg1.pvkfileanalyze -format sverilog package.sv

pkg1.pvk无法使用gvim/vim查看。

# Analyze/elaborate the first module, test1, that uses the packageanalyze -format sverilog test1.svelaborate test1# Analyze/elaborate the second module, test2, that uses the packageanalyze -format sverilog test2.svelaborate test2

同样,也可以直接使用通配符导入package中的所有内容,import p::*

到此,关于“SystemVerilog中的package怎么在设计中使用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI