summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
blob: 906870d643d54747ceb9e14fbeb70572867e0bef (plain) (blame)
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
module mem
    (   input   bit clk

    ,   output  bit                 ready
    ,   input   bit                 valid
    ,   input   bit                 write
    ,   input   bit [ADDR_BITS-1:0] address
    ,   input   bit [DATA_BITS-1:0] write_data
    ,   output  bit [DATA_BITS-1:0] read_data   // Valid exactly the cycle after address is consumed.
    );

parameter ADDR_BITS;
parameter DATA_BITS;
parameter INIT_FILE;

bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1];
initial $readmemh(INIT_FILE, storage);

assign ready = 1;

always_ff @(posedge clk) begin
    if (ready && valid) begin
        if (write)
            storage[address] <= write_data;
        else
            read_data <= storage[address];
    end
end

endmodule