상호 작용
SystemVerilog는 인터페이스를 사용하여 블록 간의 통신을 모델링합니다. 인터페이스는 지능형 연결 번들로 볼 수 있습니다. 인터페이스에는 두 개 이상의 블록 간의 통신을 연결하고 동기화하는 기능이 포함되어 있으며 설계 블록과 테스트 플랫폼을 연결합니다.
클럭 및 재설정은 인터페이스 명령문의 일부이거나 독립적 인 내부 포트 일 수 있습니다.
인터페이스 사용의 장점 :
(1) 인터페이스는 설계 및 재사용이 용이합니다. 설계에 동일한 통신 프로토콜을 사용하는 버스 연결 세트가 여러 개있는 경우 AXI4 버스의 여러 세트와 같은 인터페이스를 고려해야합니다. AXIS 버스,
(2) 새 신호를 추가해야하는 경우 다른 모듈이 아닌 인터페이스에서 한 번만 선언하면됩니다.
프로그램 예
다음 프로그램은 인터페이스 및 태스크 사용법을 보여 주며, 인터페이스는 tb로 정의되며, 인터페이스 정의는 실제 프로젝트에서 별도의 .sv 파일에 배치 할 수 있습니다.
adder.v
`timescale 1ns / 1ps
// Company:
// Engineer:
//
// Create Date: 11/27/2020
// Author Name: Sniper
// Module Name: adder
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
module adder(
input clk,
input rst_n,
input [7:0] a,
input [7:0] b,
input write_en,
output reg [8:0] p,
output reg out_en
);
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
begin
p <= 0;
out_en <= 0;
end
else
begin
if(write_en)
begin
p <= a + b;
out_en <= 1;
end
else
out_en <= 0;
end
end
endmodule
tb_adder.sv
`timescale 1ns / 1ps
// Company:
// Engineer:
//
// Create Date: 11/27/2020
// Author Name: Sniper
// Module Name: tb_adder
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
interface adderInterface(input bit clk, input bit rst_n);
//write in
logic [7:0] a;
logic [7:0] b;
logic write_en;
//output
logic [8:0] p;
logic out_en;
//task
task init;
begin
a = 0;
b = 0;
write_en = 0;
end
endtask
task write(input [7:0] data_a, input [7:0] data_b);
begin
@(posedge clk);
write_en <= 0;
a <= data_a;
b <= data_b;
@(posedge clk);
write_en <= 1;
@(posedge clk);
write_en <= 0;
end
endtask
task catch;
begin
@(posedge clk);
if(out_en)
begin
$display("Catch one output: %0d ", p);
end
end
endtask
endinterface
module tb_adder;
//system signals
reg clk;
reg rst_n;
//interface
adderInterface adder_if(clk, rst_n);
initial
begin
clk = 0;
rst_n = 0;
adder_if.init;
repeat(10) @(posedge clk);
rst_n <= 1;
for(int i=0;i<8;i++)
adder_if.write(2,i);
end
initial
begin
forever adder_if.catch;
end
//clock
always #5 clk = ~clk;
//DUT
adder DUT
(
.clk(clk),
.rst_n(rst_n),
.a(adder_if.a),
.b(adder_if.b),
.write_en(adder_if.write_en),
.p(adder_if.p),
.out_en(adder_if.out_en)
);
initial
begin
$dumpfile("curve.vcd");
$dumpvars(0,DUT);
end
initial #1000 $finish;
endmodule
가동 결과
[IC@IC sim]$ vcs -R -sverilog ../rtl/adder.v ../bench/tb_adder.sv -l run.log
...
Catch one output: 2
Catch one output: 3
Catch one output: 4
Catch one output: 5
Catch one output: 6
Catch one output: 7
Catch one output: 8
Catch one output: 9
$finish called from file "../bench/tb_adder.sv", line 123.
$finish at simulation time 1000000
V C S S i m u l a t i o n R e p o r t
Time: 1000000 ps
CPU Time: 0.140 seconds; Data structure size: 0.0Mb
...
[IC@IC sim]$