diff options
| author | Julian Blake Kongslie | 2021-07-06 09:44:36 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2021-07-06 09:44:36 -0700 |
| commit | 60e1775b874015a3451e4bde10a8eb30701b1165 (patch) | |
| tree | 477a2835c0f7e616bdeeabe6aee85f8af8b79650 /sim/rf.sv | |
| download | breadboarding-60e1775b874015a3451e4bde10a8eb30701b1165.tar.xz | |
Initial commit.
Diffstat (limited to '')
| -rw-r--r-- | sim/rf.sv | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sim/rf.sv b/sim/rf.sv new file mode 100644 index 0000000..37502ce --- /dev/null +++ b/sim/rf.sv | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | module rf | ||
| 2 | #( parameter UROM = "<no file specified>" | ||
| 3 | , parameter UIP_BITS = 15 | ||
| 4 | , parameter UROM_BITS = 8 | ||
| 5 | , parameter BUS_BITS = 16 | ||
| 6 | , parameter NAME_BITS = 3 | ||
| 7 | ) | ||
| 8 | ( input bit clk | ||
| 9 | , input bit reset | ||
| 10 | , input bit [UIP_BITS-1:0] uip | ||
| 11 | , inout bit [BUS_BITS-1:0] abus | ||
| 12 | , inout bit [BUS_BITS-1:0] dbus | ||
| 13 | ); | ||
| 14 | |||
| 15 | bit [BUS_BITS-1:0] storage [0:(1<<NAME_BITS)-1]; | ||
| 16 | |||
| 17 | typedef enum | ||
| 18 | { STORE | ||
| 19 | , RESET | ||
| 20 | , OUTDATA | ||
| 21 | } CtrlBit; | ||
| 22 | |||
| 23 | bit [UROM_BITS-1:0] ctrl; | ||
| 24 | urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl); | ||
| 25 | |||
| 26 | assign dbus = ctrl[OUTDATA] ? storage[abus[NAME_BITS-1:0]] : {(BUS_BITS){1'bZ}}; | ||
| 27 | |||
| 28 | always @(posedge clk) begin | ||
| 29 | if (reset || ctrl[RESET]) begin | ||
| 30 | for (int i = 0; i < (1 << NAME_BITS); ++i) | ||
| 31 | storage[i] <= 0; | ||
| 32 | end else begin | ||
| 33 | if (ctrl[STORE]) begin | ||
| 34 | storage[abus[NAME_BITS-1:0]] <= dbus; | ||
| 35 | end | ||
| 36 | end | ||
| 37 | end | ||
| 38 | |||
| 39 | endmodule | ||
