summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--hdl/mem.sv30
1 files changed, 30 insertions, 0 deletions
diff --git a/hdl/mem.sv b/hdl/mem.sv
new file mode 100644
index 0000000..906870d
--- /dev/null
+++ b/hdl/mem.sv
@@ -0,0 +1,30 @@
1module mem
2 ( input bit clk
3
4 , output bit ready
5 , input bit valid
6 , input bit write
7 , input bit [ADDR_BITS-1:0] address
8 , input bit [DATA_BITS-1:0] write_data
9 , output bit [DATA_BITS-1:0] read_data // Valid exactly the cycle after address is consumed.
10 );
11
12parameter ADDR_BITS;
13parameter DATA_BITS;
14parameter INIT_FILE;
15
16bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1];
17initial $readmemh(INIT_FILE, storage);
18
19assign ready = 1;
20
21always_ff @(posedge clk) begin
22 if (ready && valid) begin
23 if (write)
24 storage[address] <= write_data;
25 else
26 read_data <= storage[address];
27 end
28end
29
30endmodule