summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
diff options
context:
space:
mode:
Diffstat (limited to 'hdl/mem.sv')
-rw-r--r--hdl/mem.sv26
1 files changed, 9 insertions, 17 deletions
diff --git a/hdl/mem.sv b/hdl/mem.sv
index c362e37..9c5f567 100644
--- a/hdl/mem.sv
+++ b/hdl/mem.sv
@@ -18,32 +18,24 @@ parameter ADDR_BITS;
18parameter DATA_BITS; 18parameter DATA_BITS;
19parameter INIT_FILE; 19parameter INIT_FILE;
20 20
21`output(ready)
22`input(valid)
23`input(write)
24`input(address)
25`input(write_data)
26`output(read_valid)
27`output(read_data)
28
29bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; 21bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1];
30initial $readmemh(INIT_FILE, storage); 22initial $readmemh(INIT_FILE, storage);
31 23
32always_ff @(posedge clk) begin 24always_ff @(posedge clk) begin
33 if (reset) begin 25 if (reset) begin
34 ready_ = 0; 26 ready = 0;
35 read_valid_ = 0; 27 read_valid = 0;
36 end else begin 28 end else begin
37 read_valid_ = 0; 29 read_valid = 0;
38 if (ready_ && valid_) begin 30 if (ready && `lag(valid)) begin
39 if (write_) begin 31 if (`lag(write)) begin
40 storage[address_] = write_data_; 32 storage[`lag(address)] = `lag(write_data);
41 end else begin 33 end else begin
42 read_valid_ = 1; 34 read_valid = 1;
43 read_data_ = storage[address_]; 35 read_data = storage[`lag(address)];
44 end 36 end
45 end 37 end
46 ready_ = 1; 38 ready = 1;
47 end 39 end
48end 40end
49 41