summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-03-28 16:32:13 -0700
committerJulian Blake Kongslie2021-03-28 16:32:13 -0700
commit9d5484923941eb393381b5769a4f1f66ff5df5ca (patch)
treee98b8d5eac2b1c0aa1a459ff741693a9d0e3d3d4 /hdl/mem.sv
parentSome more interesting opcodes. (diff)
downloadnoncpu-9d5484923941eb393381b5769a4f1f66ff5df5ca.tar.xz
Use a separate memory module.
Hopefully this will infer a memory the way we want in Quartus.
Diffstat (limited to 'hdl/mem.sv')
-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