diff options
| author | Julian Blake Kongslie | 2021-03-28 16:32:13 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-03-28 16:32:13 -0700 |
| commit | 9d5484923941eb393381b5769a4f1f66ff5df5ca (patch) | |
| tree | e98b8d5eac2b1c0aa1a459ff741693a9d0e3d3d4 /hdl/mem.sv | |
| parent | Some more interesting opcodes. (diff) | |
| download | noncpu-9d5484923941eb393381b5769a4f1f66ff5df5ca.tar.xz | |
Use a separate memory module.
Hopefully this will infer a memory the way we want in Quartus.
Diffstat (limited to '')
| -rw-r--r-- | hdl/mem.sv | 30 |
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 @@ | |||
| 1 | module 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 | |||
| 12 | parameter ADDR_BITS; | ||
| 13 | parameter DATA_BITS; | ||
| 14 | parameter INIT_FILE; | ||
| 15 | |||
| 16 | bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; | ||
| 17 | initial $readmemh(INIT_FILE, storage); | ||
| 18 | |||
| 19 | assign ready = 1; | ||
| 20 | |||
| 21 | always_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 | ||
| 28 | end | ||
| 29 | |||
| 30 | endmodule | ||
