diff options
| author | Julian Blake Kongslie | 2021-03-28 17:19:12 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-03-28 17:19:12 -0700 |
| commit | 0c9e672cffa935f4db57d99e161a0c22b2b25cd9 (patch) | |
| tree | 40f53c1ba25d5e111c18da67a1b67c69ffb3ac89 /hdl/mem.sv | |
| parent | Pessimize JTAG UART somewhat. (diff) | |
| download | noncpu-0c9e672cffa935f4db57d99e161a0c22b2b25cd9.tar.xz | |
Yet another lame attempt.
Diffstat (limited to '')
| -rw-r--r-- | hdl/mem.sv | 36 |
1 files changed, 24 insertions, 12 deletions
| @@ -1,12 +1,17 @@ | |||
| 1 | `include "util.svh" | ||
| 2 | |||
| 1 | module mem | 3 | module 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 | ||
| 12 | parameter ADDR_BITS; | 17 | parameter ADDR_BITS; |
| @@ -16,14 +21,21 @@ parameter INIT_FILE; | |||
| 16 | bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; | 21 | bit [DATA_BITS-1:0] storage [0:(1<<ADDR_BITS)-1]; |
| 17 | initial $readmemh(INIT_FILE, storage); | 22 | initial $readmemh(INIT_FILE, storage); |
| 18 | 23 | ||
| 19 | assign ready = 1; | ||
| 20 | |||
| 21 | always_ff @(posedge clk) begin | 24 | always_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 |
| 28 | end | 40 | end |
| 29 | 41 | ||
