summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-03-28 17:19:12 -0700
committerJulian Blake Kongslie2021-03-28 17:19:12 -0700
commit0c9e672cffa935f4db57d99e161a0c22b2b25cd9 (patch)
tree40f53c1ba25d5e111c18da67a1b67c69ffb3ac89 /hdl/mem.sv
parentPessimize JTAG UART somewhat. (diff)
downloadnoncpu-0c9e672cffa935f4db57d99e161a0c22b2b25cd9.tar.xz
Yet another lame attempt.
Diffstat (limited to 'hdl/mem.sv')
-rw-r--r--hdl/mem.sv36
1 files changed, 24 insertions, 12 deletions
diff --git a/hdl/mem.sv b/hdl/mem.sv
index 906870d..9be5c4d 100644
--- a/hdl/mem.sv
+++ b/hdl/mem.sv
@@ -1,12 +1,17 @@
1`include "util.svh"
2
1module mem 3module mem
2 ( input bit clk 4 ( input bit clk
5 , input bit reset
3 6
4 , output bit ready 7 , output bit ready
5 , input bit valid 8 , input bit valid `define valid `past(valid)
6 , input bit write 9 , input bit write `define write `past(write)
7 , input bit [ADDR_BITS-1:0] address 10 , input bit [ADDR_BITS-1:0] address `define address `past(address)
8 , input bit [DATA_BITS-1:0] write_data 11 , input bit [DATA_BITS-1:0] write_data `define write_data `past(write_data)
9 , output bit [DATA_BITS-1:0] read_data // Valid exactly the cycle after address is consumed. 12
13 , output bit read_valid
14 , output bit [DATA_BITS-1:0] read_data
10 ); 15 );
11 16
12parameter ADDR_BITS; 17parameter ADDR_BITS;
@@ -16,14 +21,21 @@ parameter INIT_FILE;
16bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; 21bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1];
17initial $readmemh(INIT_FILE, storage); 22initial $readmemh(INIT_FILE, storage);
18 23
19assign ready = 1;
20
21always_ff @(posedge clk) begin 24always_ff @(posedge clk) begin
22 if (ready && valid) begin 25 if (reset) begin
23 if (write) 26 ready = 0;
24 storage[address] <= write_data; 27 read_valid = 0;
25 else 28 end else begin
26 read_data <= storage[address]; 29 read_valid = 0;
30 if (ready && `valid) begin
31 if (`write) begin
32 storage[`address] = `write_data;
33 end else begin
34 read_valid = 1;
35 read_data = storage[`address];
36 end
37 end
38 ready = 1;
27 end 39 end
28end 40end
29 41