top.v 637 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
module tristate (en, i, io, o);
    input en;
    input i;
    inout [1:0] io;
    output [1:0] o;

    reg [1:0] io_buf;
    assign io = io_buf;

`ifndef BUG
    always @(en or i)
		io_buf[0] <= (en)? i : 1'bZ;

    always @(en or i)
		io_buf[1] <= (i)? en : 1'bZ;

    assign o = (en)? io : 2'bZZ;
`else
	always @(en or i)
Miodrag Milanovic committed
20
		io_buf[0] <= (en)? ~i : 1'bZ;
21 22

    always @(en or i)
Miodrag Milanovic committed
23
		io_buf[1] <= (i)? ~en : 1'bZ;
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

    assign o = (en)? ~io : 2'bZZ;
`endif
endmodule


module top (
input en,
input a,
inout [1:0] b,
output [1:0] c
);

tristate u_tri (
        .en (en ),
        .i (a ),
        .io (b ),
        .o (c )
    );

endmodule