diff options
Diffstat (limited to '')
| -rw-r--r-- | sim/counter.sv | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sim/counter.sv b/sim/counter.sv new file mode 100644 index 0000000..1316783 --- /dev/null +++ b/sim/counter.sv | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | module counter | ||
| 2 | #( parameter UROM = "<no file specified>" | ||
| 3 | , parameter UIP_BITS = 15 | ||
| 4 | , parameter UROM_BITS = 8 | ||
| 5 | , parameter BUS_BITS = 16 | ||
| 6 | ) | ||
| 7 | ( input bit clk | ||
| 8 | , input bit reset | ||
| 9 | , input bit [UIP_BITS-1:0] uip | ||
| 10 | , inout bit [BUS_BITS-1:0] abus | ||
| 11 | , inout bit [BUS_BITS-1:0] dbus | ||
| 12 | ); | ||
| 13 | |||
| 14 | bit [BUS_BITS-1:0] x; | ||
| 15 | |||
| 16 | typedef enum | ||
| 17 | { LOAD | ||
| 18 | , INCREMENT | ||
| 19 | , DECREMENT | ||
| 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] ? x : {(BUS_BITS){1'bZ}}; | ||
| 27 | |||
| 28 | always @(posedge clk) begin | ||
| 29 | if (ctrl[LOAD]) begin | ||
| 30 | x <= dbus; | ||
| 31 | end else if (ctrl[INCREMENT]) begin | ||
| 32 | x <= x + 1; | ||
| 33 | end else if (ctrl[DECREMENT]) begin | ||
| 34 | x <= x - 1; | ||
| 35 | end | ||
| 36 | end | ||
| 37 | |||
| 38 | endmodule | ||
