summaryrefslogtreecommitdiff
path: root/hdl/mem.sv
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-04-05 10:20:02 -0700
committerJulian Blake Kongslie2021-04-05 10:20:02 -0700
commit6a1c04608090cc8fc88aafac0b4899e4cbb9cae9 (patch)
tree9a03984357020c00dfeed299a8b321f832a48bd4 /hdl/mem.sv
parentMake PC ADDR-sized rather than DATA-sized for now (diff)
downloadnoncpu-6a1c04608090cc8fc88aafac0b4899e4cbb9cae9.tar.xz
Change our simulator timing model to use continuous assignment guards.
Instead of depending on verilator getting $past right, this (ab-)uses the SystemVerilog scheduling model which allows us to get a consistent view of the universe by "isolating" the blocking updates. Easier to code to and seems to be more reliable in verilator.
Diffstat (limited to 'hdl/mem.sv')
-rw-r--r--hdl/mem.sv34
1 files changed, 21 insertions, 13 deletions
diff --git a/hdl/mem.sv b/hdl/mem.sv
index 9be5c4d..c362e37 100644
--- a/hdl/mem.sv
+++ b/hdl/mem.sv
@@ -5,10 +5,10 @@ module mem
5 , input bit reset 5 , input bit reset
6 6
7 , output bit ready 7 , output bit ready
8 , input bit valid `define valid `past(valid) 8 , input bit valid
9 , input bit write `define write `past(write) 9 , input bit write
10 , input bit [ADDR_BITS-1:0] address `define address `past(address) 10 , input bit [ADDR_BITS-1:0] address
11 , input bit [DATA_BITS-1:0] write_data `define write_data `past(write_data) 11 , input bit [DATA_BITS-1:0] write_data
12 12
13 , output bit read_valid 13 , output bit read_valid
14 , output bit [DATA_BITS-1:0] read_data 14 , output bit [DATA_BITS-1:0] read_data
@@ -18,24 +18,32 @@ 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
21bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; 29bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1];
22initial $readmemh(INIT_FILE, storage); 30initial $readmemh(INIT_FILE, storage);
23 31
24always_ff @(posedge clk) begin 32always_ff @(posedge clk) begin
25 if (reset) begin 33 if (reset) begin
26 ready = 0; 34 ready_ = 0;
27 read_valid = 0; 35 read_valid_ = 0;
28 end else begin 36 end else begin
29 read_valid = 0; 37 read_valid_ = 0;
30 if (ready && `valid) begin 38 if (ready_ && valid_) begin
31 if (`write) begin 39 if (write_) begin
32 storage[`address] = `write_data; 40 storage[address_] = write_data_;
33 end else begin 41 end else begin
34 read_valid = 1; 42 read_valid_ = 1;
35 read_data = storage[`address]; 43 read_data_ = storage[address_];
36 end 44 end
37 end 45 end
38 ready = 1; 46 ready_ = 1;
39 end 47 end
40end 48end
41 49