2016-07-11 2 views
0

나는 시스템 Verilog에 인터페이스시스템 Verilog 모듈과 인터페이스를 바인딩하는 방법은 무엇입니까?

interface add_sub_if(
input bit clk, 
input [7:0] a, 
input [7:0] b, 
input  doAdd, 
input [8:0] result 
); 

    clocking dut_cb @(posedge clk); 
    output a; 
    output b; 
    output doAdd; 
    input  result; 
    endclocking // cb 

    modport dut(clocking dut_cb); 

endinterface: add_sub_if 

하고 난이 인터페이스

module dummy(add_sub_if.dut _if); 
    .... 
endmodule: dummy 

내 결핵이를 연결하는 이상적인 방법은 무엇입니까를 사용하는 SV 모듈이?

인터페이스를 인스턴스화하는 경우 전선을 만들어야합니다.

만약 내가 바인딩을 사용하는 경우에도 인터페이스가있는 편리함보다 두드러진 개별 신호의 포트 매핑을 수행해야합니다.

또 하나의 추가 질문은 다른 인터페이스에 그러한 인터페이스를 할당하는 방법입니다. 사전에

감사합니다,

Rajdeep

답변

2

당신은 IEEE Std 1800-2012 3.5 절 (인터페이스)의 인터페이스 정의 및 사용의 간단한 예를 찾을 수 있습니다. 인터페이스 정의 방법과 인터페이스를 디자인에 연결하는 방법을 보여줍니다 (이미 완료 한 방식). 또한 인터페이스가 (난 당신의 편의를 위해 사양에서 아래 코드를 직접 복사) 최상위 모듈/래퍼 내부 인스턴스 (및 연결) 할 수있는 방법을 보여줍니다

interface simple_bus(input logic clk); // Define the interface 
    logic req, gnt; 
    logic [7:0] addr, data; 
    logic [1:0] mode; 
    logic start, rdy; 
endinterface: simple_bus 

module memMod(simple_bus a); // simple_bus interface port 
    logic avail; 
    // When memMod is instantiated in module top, a.req is the req 
    // signal in the sb_intf instance of the 'simple_bus' interface 
    always @(posedge clk) a.gnt <= a.req & avail; 
endmodule 

module cpuMod(simple_bus b); // simple_bus interface port 
    ... 
endmodule 

module top; 
    logic clk = 0; 

    simple_bus sb_intf(.clk(clk)); // Instantiate the interface 

    memMod mem(.a(sb_intf)); // Connect interface to module instance 
    cpuMod cpu(.b(sb_intf)); // Connect interface to module instance 

endmodule 

당신이 인터페이스 엮은하면, 테스트 케이스 프로그램의 모든 신호를 구동/샘플링 할 수 있습니다 (인터페이스를 전달해야 함을 기억하십시오). , 당신이 내 GitHub의 페이지에서 사용할 수있는 source code of a UVM testbench을 확인할 수 있습니다

program testcase(simple_bus tb_if); 

    initial begin 
    tb_if.mode <= 0; 
    repeat(3) #20 tb_if.req <= 1'b1; 
    [...] 
    $finish; 
    end 

endprogram 

실제 예를 들어이 경우, 같은 것을 할 것입니다. 인터페이스 연결은 xge_test_top.sv 파일에서 수행됩니다.

+0

안녕 AndresM, 이는 다음과 같습니다 인터페이스 simple_bus (입력 로직 CLK 인터페이스 입력 로직 REQ를 정의 //, 입력 로직 GNT , 입력 논리 [7 : 0] addr, 입력 논리 데이터, 입력 논리 [1 : 0] 모드, 출력 논리 시작, 출력 rdy); end interface : simple_bus 그러면이 인터페이스를 어떻게 연결해야합니까? 나는 똑같은 좋은 예를 찾을 수 없었다. – justrajdeep

+0

테스트 케이스 프로그램에서 신호를 보내는 방법을 알 수 있도록 일부 코드를 제 답변에 추가했습니다. 그것을 확인하십시오 - 이것은 당신이 가지고 있을지도 모르는 질문을 분명히 명확히해야합니다. – AndresM

1

시스템 Verilog 모듈에서 인터페이스를 바인딩 할 수 있습니다.

여기서는 샘플 코드를 제공하여 시스템 verilog 모듈과 dut에서 인터페이스를 바인딩하는 방법을 이해할 수 있도록 도와줍니다.

여기에서는 Verilog 모듈과 시스템 Verilog 모듈을 제공합니다. 코드의 주요 부분은 Verilog 및 시스템 Verilog 모듈이 연결된 인터페이스입니다.

의 Verilog 모듈 코드 (DUT)

module dff(qn,d,clk,reset); 

output qn; 
input d,clk,reset; 
reg qn; 

[email protected](posedge clk,negedge reset) 

begin 

if (!reset) 

begin 
qn=1'bx; 
end 

else if (d==0) 
begin 
qn=0; 
end 
else if (d==1) 
begin 
qn=1; 
end 

end 

endmodule 

시스템의 Verilog 모듈 코드 (테스트 벤치)

interface melay_intf(input bit clk); 

    logic o,clk,rst,i; 

    clocking [email protected](posedge clk); 
    input o; 
    output i,rst; 
    endclocking 

endinterface 

module top; 
    bit clk; 

    always 
    #1 clk = ~clk; 

    melay_intf i1(clk); 

    dff d1(.o(i1.o),.clk(i1.clk),.rst(i1.rst),.i(i1.i)); 

    melay_tes(i1.tes); 

endmodule 

program melay_tes(melay_intf i1); 

    initial 
    #100 $finish; 

    initial 
    begin 
     i1.rst <= 0; 
     #4 i1.rst <= 1; 
     #4 i1.rst <= 0; 

     i1.i = 1; 
      #2 i1.i = 0; 
      #2 i1.i = 1; 
      #2 i1.i = 0; 
      #2 i1.i = 1; 
      #2 i1.i = 0; 


     repeat(10) 
     begin 
      i1.i = 1; 
      #2 i1.i = $urandom_range(0,1); 
     end 
    end 

    initial 
    $monitor("output = %d clk = %d rst = %d i = %d",i1.o,i1.clk,i1.rst,i1.i); 
    initial 
    begin 
     $dumpfile("mem.vcd"); 
     $dumpvars(); 

    end 
endprogram 

여기서 중요한 부분은 인터페이스이며에서 I가 클로킹 블록을 사용 동기화 목적. 여기 클록 킹 c1 @ (posedge clk); 그래서 클럭킹 블록 안에있는 모든 신호는 i, o, rst입니다.이 신호는 clk 신호가 발생할 때마다 그 값을 변경합니다.

여기 dff d1 (.o (i1.o), .clk (i1.clk), .stst (i1.rst), .i (i1.i)); 중요한 모듈에서 발견 한 중요한 점은 Verilog 신호와 시스템 Verilog 신호를 연결했다는 것입니다.

Verilog 모듈 이름은 "dff"입니다. 나는 dff verilog 모듈의 인스턴스를 가져 와서 연결을 만들었다. 여기서 i1.o, i1.clk, i1.rst, i1.i는 o, clk, rst에 연결된 시스템 Verilog 신호이며 도트 규칙을 사용하여 Verilog 모듈의 신호를 나타냅니다.

+0

안녕하세요 Ashutosh, 인터페이스는 '로직'으로 '클럭'이 없어야합니다. 'melay_tes (i1.tes);를 찾을 수 없습니다.'tes'는 무엇입니까 – justrajdeep

+0

실제로 미안하지만 코드를 업데이트하는 실수가 있습니다. 정확한 코드를 알려 드릴 것입니다. 테스트 벤치와 덤프는 모두 다릅니다. –

2

여기는 testbench가있는 fsm dut입니다.

이 fsm dut은 상태 전환 1 - 0 - 1 - 0을 순서대로 수행합니다.

테스트 벤치가 제대로 작동하는지 확인합니다.

를 Verilog 모듈 코드 (DUT) :

module melay_fsm(o,clk,rst,i); 
output o; 
input i,clk,rst; 
reg o; 
reg [1:0]state; 
// [1:0]state; 
[email protected](posedge clk,posedge rst) 
begin 
if(rst) 
begin 
state <=2'b00; 
end 
else 
begin 
case(state) 
2'b00: 
begin 
if(i) 
state<=2'b01; 
else 
state<=2'b00; 
end 

2'b01: 
begin 
if(!i) 
state<=2'b10; 
else 
state<=2'b01; 
end 

2'b10: 
begin 
if(i) 
state<=2'b11; 
else 
state<=2'b00; 
end 

2'b11: 
begin 
if(!i) 
state<=2'b00; 
else 
state<=2'b01; 
end 
endcase 
end 
end 

[email protected](posedge clk,negedge rst) 
begin 
if(rst) 
o<=1'b0; 
else if(state==2'b11 && i==0) 
o<=1'b1; 
else 
o<=1'b0; 
end 
endmodule 

시스템을 Verilog 모듈 코드 (테스트 벤치) :

interface melay_intf(input bit clk); 

    logic o,rst,i; 
    wire clk; 

    clocking [email protected](posedge clk); 
    input o; 
    output i,rst; 
    endclocking 

    modport tes(clocking c1); 

endinterface 

    module top; 
     bit clk; 

     always 
     #1 clk = ~clk; 

     melay_intf i1(clk); 

     melay_fsm a1(.o(i1.o),.clk(i1.clk),.rst(i1.rst),.i(i1.i)); 

     melay_tes(i1); 

    endmodule 

    program melay_tes(melay_intf i1); 

     initial 
     #100 $finish; 

     initial 
     begin 
      i1.rst <= 0; 
      #4 i1.rst <= 1; 
      #4 i1.rst <= 0; 

      i1.i = 1; 
       #2 i1.i = 0; 
       #2 i1.i = 1; 
       #2 i1.i = 0; 
       #2 i1.i = 1; 
       #2 i1.i = 0; 


      repeat(10) 
      begin 
       i1.i = 1; 
       #2 i1.i = $urandom_range(0,1); 
      end 
     end 

     initial 
     $monitor("output = %d clk = %d rst = %d i = %d",i1.o,i1.clk,i1.rst,i1.i); 
     initial 
     begin 
      $dumpfile("mem.vcd"); 
      $dumpvars(); 

     end 
    endprogram 

중요한 것은 여기로주의해야 할 최고 모듈에 신호 연결입니다 .

melay_fsma1 (.o (i1.o), .clk (i1.clk), .st (i1.rst) ,. i (i1.i));

제대로 testbench 및 dut와 인터페이스를 바인딩하는 방법을 준수하십시오. 다음 사항을 준수하십시오.

나는 모든 dut의 신호와 인터페이스를 정의합니다.

맨 위 모듈에서 인터페이스 (melay_intf)의 인스턴스 (i1)을 가져 왔습니다.

상단 모듈에서 dut (melay_fsm) 인스턴스 (a1)를 가져 왔습니다.

지금 melay_fsm A1 (.o 인 (i1.o) ,. CLK (i1.clk) ,. 처음 (i1.rst) ,. 난 (i1.i))

모든 DUT의 관찰 신호는 인터페이스로 연결됩니다.

테스트 벤치에서 인터페이스 (i1)의 인스턴스를 전달했습니다. melay_tes (i1)

따라서 testbench는 인터페이스 신호에 액세스 할 수 있으며 인터페이스 신호는 dut의 신호에 연결됩니다.

이제 인터페이스를 통해 테스트 벤치에서 dut의 신호에 액세스 할 수 있습니다.

이제 올바른 흐름을 이해할 수 있다고 생각합니다.

의심되는 항목이 있으면 질문 해주세요.내 혼란이 대신 인터페이스는 다음과 같이 정의되는 경우 인터페이스의, 어디

+0

감사합니다 Asutosh, 그건 설명합니다. – justrajdeep

+0

실제로 신호를 연결하는 두 가지 방법이 있습니다. (1) 포트 순서에 의해 연결됨 (암시 적) (2) 여기에 설명 된 이름으로 연결된 모듈들 melay_fsm a1 (.o (i1.o), .clk (i1.clk), .rst (i1.rst) ,. i (i1.i)). 이것은 바람직한 방법입니다. 포트 순서 (암시 적)로 연결된 (1)의 경우 각 신호를 올바르게 일치시켜야합니다. 따라서 바람직한 방법은 아닙니다. –

관련 문제