当前位置:网站首页>SystemVerilog中interface(接口)介绍
SystemVerilog中interface(接口)介绍
2022-07-25 05:20:00 【向芯】
interface出现背景
随着设计复杂度的增加,模块之间的连接也变得更加复杂。两个RTL模块之间可能有几十个连接信号,这些信号必须按照正确的顺序排列以使它们正确地通信。当在两个模块中增加一个新的信号的时候,不但需要编辑模块代码以增加新的端口,还需要编辑上一层次中连接器件的网单代码,任何一层次出现错误都会导致设计无法正常工作。
传统方法:使用信号名映射的信号连接方法,但这无疑增加了代码输入量,而且很容易出错。
解决办法:用接口,它是systemVerilog中一种代表一捆线的结构,它是具有智能同步和连接功能的代码。一个接口可以像模块那样例化,也可以像信号线一样连接到端口。
接口作用:
接口包含了连接、同步、甚至两个或多个块之间的通信功能,他们连接了设计块和测试平台。
举例说明:
(1)仲裁器接口:
interface arb_if(input bit clk);
logic [1:0] grant,request;
logic rst;
endinterface(2)使用接口的仲裁器
module arb (arb_if arbif);
...
always @(posedge arbif.clk or posedge arbif.rst) begin
if(arbif.rst)
arbif.grant<=2'b00;//将数据传给接口
else
arbif.grant<=next_grant;
...
end
endmodule(3)使用仲裁器接口的测试平台
module test (arb_if arbif)
...
initial begin
//此处省略了复位代码
@(posedge arbif.clk) arbif.request <=2'b01;
$display("@%0t: Drove req=01",$time);
repeat (2) @(posedge arbif.clk);
if(arbif.grant !=2'b01) $display("@%0t:al:grant!=2'b01",$time);
$finish
end
endmodule : test
(4)使用仲裁器接口的top模块
module top;
bit clk;
always #5 clk=~clk;
arb_if arbif(clk);
arb_al (arbif);
test_t1(arbif);
endmodule : top例子好处:
连接变得更加简洁而不易出错。如果你希望在一个接口放入一个新的信号,你只需要在接口定义和实际使用这个接口的模块中做修改。你不需要改变其他任何模块,例如在top模块,信号只是穿过该模块,而不进行任何操作。这种特性极大地降低了连线出错的机率。
===================不符合Verilog-2001的旧代码处理办法================
如果不能对符合 Verilog-2001的旧的源代码进行修改,将其中的端口改为接口,你可以将接口的信号直接连接到每个端口上。下例中的arb_port就是就代码模块。

边栏推荐
猜你喜欢

LeetCode 15:三数之和

Small case of data analysis: visualize recruitment data and view the most needed technologies in the field~

ping命令

Dragon Dragon community released the first Anolis OS Security Guide to escort users' business systems

自己实现is_base_of
![[globally unique ID] how to handle the ID primary key after dividing the database and table?](/img/a1/800ee868b74ce5d98956d4a0e2c075.png)
[globally unique ID] how to handle the ID primary key after dividing the database and table?

1310_一个printf的实现分析

微信小程序相关操作示例

微服务 - 网关Gateway组件

Why does the official not recommend using UUID as MySQL primary key
随机推荐
Implement is by yourself_ class
Special analysis of data security construction in banking industry
When we talk about immutable infrastructure, what are we talking about
微服务 - 网关Gateway组件
1310_一个printf的实现分析
How to judge whether it is attacked by DDoS
The second day of rhcsa summer vacation
STL notes (III): input / output stream
What is virtual DOM? How to implement a virtual DOM
STL notes (VI): container vector
一篇文章带你读懂Redis的哨兵模式
How do novices open accounts for stock speculation? Is it safe for securities companies to open accounts online?
How to carry out the function test with simple appearance and complex interior?
Introduction to base ring tree
Learning records [email protected] R & D effectiveness measurement indicators
[no title] 1
Leetcode 15: sum of three numbers
Bypass XSS filters in Web Applications
搭建私有CA服务器
Teach you three ways to optimize the performance from 20s to 500ms