system verilog interface with function -


how can add function in interface? trying implement half adder using interface having function calculate sum , carry.following code same. when trying without functions running 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 

function synthesizable, must used, within procedural block of verilog. (like or initial)

tasks , void functions called statements within procedural blocks

so required modifications in code :

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, nh1.sum, nh1.c_out);   endmodule 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -