Created
June 21, 2014 10:47
-
-
Save tejainece/15ac5c47c3a58328e385 to your computer and use it in GitHub Desktop.
Using SystemVerilog interfaces with pure Verilog modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all: compile gsim | |
| .PHONY: compile gsim | |
| compile: | |
| if [ -d work]; then vdel -lib work -all; fi | |
| vlib work | |
| vmap work work | |
| vlog -sv mux.sv | |
| vlog -sv mux_tb.sv | |
| gsim: | |
| vsim -novopt mux_tb | |
| clean: | |
| if [ -d work ]; then vdel -lib work -all; fi | |
| if [ -f transcript ]; then rm transcript; fi | |
| if [ -f vsim.wlf ]; then rm vsim.wlf; fi | |
| rm *~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| all: compile gsim | |
| .PHONY: compile gsim | |
| compile: | |
| if [ -d work]; then vdel -lib work -all; fi | |
| vlib work | |
| vmap work work | |
| vlog -sv mux.v | |
| vlog -sv muxv_tb.sv | |
| gsim: | |
| vsim -novopt muxv_tb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface mux_if(); | |
| bit [3:0] in1, in2; | |
| bit sel; | |
| bit [3:0] out; | |
| endinterface | |
| module mux(mux_if muxif); | |
| always_comb begin | |
| if (muxif.sel == 1) begin | |
| muxif.out = muxif.in2; | |
| end else begin | |
| muxif.out = muxif.in1; | |
| end | |
| end | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module mux(out, sel, in1, in2); | |
| input bit [3:0] in1, in2; | |
| input bit sel; | |
| output bit [3:0] out; | |
| always_comb begin | |
| if (sel == 1) begin | |
| out = in2; | |
| end else begin | |
| out = in1; | |
| end | |
| end | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module mux_tb(); | |
| mux_if muxif(); | |
| mux i_mux(muxif); | |
| initial begin | |
| muxif.in1 = 4'b1010; | |
| muxif.in2 = 4'b0101; | |
| muxif.sel = 0; | |
| #10 | |
| muxif.sel = 1; | |
| #10 | |
| muxif.in1 = 4'b1111; | |
| muxif.in2 = 4'b0000; | |
| #10 | |
| muxif.sel = 0; | |
| #10 | |
| muxif.in1 = 4'b1100; | |
| #10 $finish; | |
| end | |
| endmodule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface mux_if(); | |
| bit [3:0] in1, in2; | |
| bit sel; | |
| bit [3:0] out; | |
| endinterface | |
| module muxv_tb(); | |
| mux_if muxif(); | |
| mux i_mux(.out(muxif.out), .sel(muxif.sel), .in1(muxif.in1), .in2(muxif.in2)); | |
| initial begin | |
| muxif.in1 = 4'b1010; | |
| muxif.in2 = 4'b0101; | |
| muxif.sel = 0; | |
| #10 | |
| muxif.sel = 1; | |
| #10 | |
| muxif.in1 = 4'b1111; | |
| muxif.in2 = 4'b0000; | |
| #10 | |
| muxif.sel = 0; | |
| #10 | |
| muxif.in1 = 4'b1100; | |
| #10 $finish; | |
| end | |
| endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment