double_clock.sv 964 Bytes
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
`default_nettype none

module Device(
    input logic clock, clear,
    output logic [3:0] data
);

    SharedMemory memory(
        .clock1(clock),
        .clock2(clock),
        .clear,
        .data1(data[1:0]),
        .data2(data[3:2])
    );

endmodule

module SharedMemory(
    input logic clock1, clock2, clear,
    output logic [1:0] data1, data2
);

    logic [3:0] memory;

    // Just a dumb example to generate interesting values
    always_ff @(posedge clock1) begin
        if(clear)
            memory <= 4'b0;
        else
            memory <= {~memory[2:0], 1'b0};
    end

    always_ff @(posedge clock1)
        data1 <= memory[1:0];

    // Technically this is pretty dangerous since it is being generated on
    // clock1 domain so we would need a bunch of other logic to make sure this
    // is safe, but for the example we'll just ignore that stuff.
    always_ff @(posedge clock2) begin
        data2 <= memory[3:2];
    end


endmodule