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/control.sv | |
| download | breadboarding-60e1775b874015a3451e4bde10a8eb30701b1165.tar.xz | |
Initial commit.
Diffstat (limited to '')
| -rw-r--r-- | sim/control.sv | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/sim/control.sv b/sim/control.sv new file mode 100644 index 0000000..7808f61 --- /dev/null +++ b/sim/control.sv | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | module control | ||
| 2 | #( parameter UROM = "<no file specified>" | ||
| 3 | , parameter UIP_BITS = 15 | ||
| 4 | , parameter UROM_BITS = 8 | ||
| 5 | , parameter BUS_BITS = 16 | ||
| 6 | , parameter CONST_0 = "<no file specified>" | ||
| 7 | , parameter CONST_1 = "<no file specified>" | ||
| 8 | , parameter RESET = ~0 | ||
| 9 | ) | ||
| 10 | ( input bit clk | ||
| 11 | , input bit reset | ||
| 12 | , output bit [UIP_BITS-1:0] uip | ||
| 13 | , inout bit [BUS_BITS-1:0] abus | ||
| 14 | , inout bit [BUS_BITS-1:0] dbus | ||
| 15 | ); | ||
| 16 | |||
| 17 | typedef enum | ||
| 18 | { HALT | ||
| 19 | , SET_UIP_COND | ||
| 20 | , NOCOND | ||
| 21 | , OUTADDR | ||
| 22 | , OUTDATA | ||
| 23 | } CtrlBit; | ||
| 24 | |||
| 25 | bit [UROM_BITS-1:0] ctrl; | ||
| 26 | urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl); | ||
| 27 | |||
| 28 | bit [UROM_BITS*2-1:0] constant; | ||
| 29 | urom#(CONST_0, UIP_BITS, UROM_BITS) const_0(uip, constant[1*UROM_BITS-1:0*UROM_BITS]); | ||
| 30 | urom#(CONST_1, UIP_BITS, UROM_BITS) const_1(uip, constant[2*UROM_BITS-1:1*UROM_BITS]); | ||
| 31 | |||
| 32 | assign abus = ctrl[OUTADDR] ? constant : {(BUS_BITS){1'bZ}}; | ||
| 33 | assign dbus = ctrl[OUTDATA] ? constant : {(BUS_BITS){1'bZ}}; | ||
| 34 | |||
| 35 | bit cond; | ||
| 36 | assign cond = (dbus != 0) || ctrl[NOCOND]; | ||
| 37 | |||
| 38 | always @(posedge clk) begin | ||
| 39 | if (reset) begin | ||
| 40 | uip <= RESET; | ||
| 41 | end else begin | ||
| 42 | if (! ctrl[HALT]) begin | ||
| 43 | if (ctrl[SET_UIP_COND] && cond) begin | ||
| 44 | uip <= abus[UIP_BITS-1:0]; | ||
| 45 | end else begin | ||
| 46 | uip <= uip + 1; | ||
| 47 | end | ||
| 48 | end else begin | ||
| 49 | $finish; | ||
| 50 | end | ||
| 51 | end | ||
| 52 | end | ||
| 53 | |||
| 54 | endmodule | ||
