diff options
| author | Julian Blake Kongslie | 2021-04-07 17:02:03 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-04-07 17:02:03 -0700 |
| commit | 238a43e587bfbe6574d34ef36553619249797260 (patch) | |
| tree | e1b3b0c0c4c6254d2d4a851a2eb1bf2cac2169a2 /hdl/mem.sv | |
| parent | Don't rebuild verilator just for memory file changes. (diff) | |
| download | noncpu-238a43e587bfbe6574d34ef36553619249797260.tar.xz | |
Switch back to $past-based scheduling; my clever idea wasn't clever enough.
Diffstat (limited to 'hdl/mem.sv')
| -rw-r--r-- | hdl/mem.sv | 26 |
1 files changed, 9 insertions, 17 deletions
| @@ -18,32 +18,24 @@ parameter ADDR_BITS; | |||
| 18 | parameter DATA_BITS; | 18 | parameter DATA_BITS; |
| 19 | parameter INIT_FILE; | 19 | parameter 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 | |||
| 29 | bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; | 21 | bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; |
| 30 | initial $readmemh(INIT_FILE, storage); | 22 | initial $readmemh(INIT_FILE, storage); |
| 31 | 23 | ||
| 32 | always_ff @(posedge clk) begin | 24 | always_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 |
| 48 | end | 40 | end |
| 49 | 41 | ||
