How can I add a function in an interface? I am trying to implement half adder using interface having function to calculate sum and carry.Following is my code for the same. When trying without functions it as running by using complemented lines.
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