simple_interface.sv 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
`default_nettype none

interface SimpleInterface(input logic clock, clear);
    logic [31:0] data;
    logic shift;

    modport Producer(
        output data,
        input shift,

        input clock, clear
    );

    modport Consumer(
        input data,
        output shift,

        input clock, clear
    );
endinterface : SimpleInterface

module Device(
    input logic [7:0] dataIn,
    output logic [31:0] dataOut,

    input logic clock, clear
);

    SimpleInterface theInterface(.clock, .clear);


    Producer producer(
        .myInterface(theInterface.Producer),
        .dataIn
    );

    Consumer consumer(
        .myInterface(theInterface.Consumer),
        .dataOut
    );

endmodule


// The producer takes the input and then transforms it for 4 cycles
module Producer(
    SimpleInterface.Producer myInterface,
    input logic [7:0] dataIn
);
    logic [31:0] inProgress;
    always_ff @(posedge myInterface.clock) begin
        if(myInterface.clear) begin
            inProgress <= 32'b0;
        end else if(myInterface.shift) begin
            inProgress <= {inProgress[23:0], dataIn};
        end
    end

    assign myInterface.data = inProgress;

endmodule

module Consumer(
    SimpleInterface.Consumer myInterface,
    output logic [31:0] dataOut
);

    // Just want this variable to make the test bench nicer
    logic local_shift;
    assign local_shift = myInterface.shift;

    always_ff @(posedge myInterface.clock)
        if(myInterface.clear) begin
            myInterface.shift <= 1'b0;
        end else begin
            myInterface.shift <= ~myInterface.shift;
        end

    assign dataOut = myInterface.data;

endmodule