diff options
Diffstat (limited to '')
| -rw-r--r-- | sim/uart.sv | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sim/uart.sv b/sim/uart.sv new file mode 100644 index 0000000..3b434da --- /dev/null +++ b/sim/uart.sv | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | module uart | ||
| 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 txfull; | ||
| 15 | bit rxempty; | ||
| 16 | |||
| 17 | assign txfull = 0; | ||
| 18 | assign rxempty = 0; | ||
| 19 | |||
| 20 | typedef enum | ||
| 21 | { TX | ||
| 22 | , RX | ||
| 23 | , OUTDATA | ||
| 24 | , OUTDATA_SEL0 | ||
| 25 | } CtrlBit; | ||
| 26 | |||
| 27 | bit [UROM_BITS-1:0] ctrl; | ||
| 28 | urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl); | ||
| 29 | |||
| 30 | bit [0:0] sel; | ||
| 31 | assign sel = {ctrl[OUTDATA_SEL0]}; | ||
| 32 | |||
| 33 | bit [BUS_BITS-1:0] dout; | ||
| 34 | assign dout = | ||
| 35 | (ctrl[RX]) ? {(BUS_BITS){1'b1}} : | ||
| 36 | (sel == 0) ? {{(BUS_BITS-1){1'b0}}, txfull} : | ||
| 37 | (sel == 1) ? {{(BUS_BITS-1){1'b0}}, rxempty} : | ||
| 38 | {(BUS_BITS){1'bX}}; | ||
| 39 | |||
| 40 | assign dbus = ctrl[OUTDATA] ? dout : {(BUS_BITS){1'bZ}}; | ||
| 41 | |||
| 42 | always @(posedge clk) begin | ||
| 43 | if (ctrl[TX]) | ||
| 44 | $display("tx %x", dbus[7:0]); | ||
| 45 | end | ||
| 46 | |||
| 47 | endmodule | ||
