具有功能的系统verilog接口

system verilog interface with function

如何在界面中添加功能?我正在尝试使用具有计算总和功能的接口来实现半加器,carry.Following 是我的代码。当尝试不使用函数时,通过使用补充行将其作为 运行。

module top_ha_interface;   
  ha_interface nh1();   
  ha h1(nh1);   
  ha_tb h2(nh1); 
endmodule 

interface ha_interface;   
  logic sum,c_out;   
  logic a,b;   
  function summ(a,b,output sum,c_out);     
    sum=a^b;     
    c_out=a&b;   
  endfunction   
endinterface 

module ha(ha_interface nh1);   
//  assign nh1.sum=nh1.a^nh1.b;   
//  assign nh1.c_out=nh1.a&nh1.b;   
  nh1.summ(nh1.a,nh1.b);  
endmodule 

module ha_tb(ha_interface nh1);   
  initial   
  begin         
    nh1.a=1'b1;         
    nh1.b=1'b0;     
    #10 $display($time,"ns\t",nh1.sum,nh1.c_out);         
    nh1.a=1'b1;         
    nh1.b=1'b1;     
    #20 $display($time,"ns\t",nh1.sum,nh1.c_out);         
    nh1.a=1'b0;         
    nh1.b=1'b0;     
    #30 $display($time,"ns\t",nh1.sum,nh1.c_out);   
  end 
endmodule

函数是可综合的,但必须在 verilog 的任何程序块中使用。 (喜欢总是或初始)

Tasks and void functions are called as statements within procedural blocks

因此需要修改您的代码:

module ha(ha_interface nh1);   
//  assign nh1.sum=nh1.a^nh1.b;   
//  assign nh1.c_out=nh1.a&nh1.b;   
  always @ (*)
    nh1.summ(nh1.a,nh1.b, nh1.sum, nh1.c_out);  
endmodule