summaryrefslogtreecommitdiff
path: root/sim/uart.sv
diff options
context:
space:
mode:
authorJulian Blake Kongslie2021-07-06 09:44:36 -0700
committerJulian Blake Kongslie2021-07-06 09:44:36 -0700
commit60e1775b874015a3451e4bde10a8eb30701b1165 (patch)
tree477a2835c0f7e616bdeeabe6aee85f8af8b79650 /sim/uart.sv
downloadbreadboarding-60e1775b874015a3451e4bde10a8eb30701b1165.tar.xz
Initial commit.
Diffstat (limited to 'sim/uart.sv')
-rw-r--r--sim/uart.sv47
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 @@
1module 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
14bit txfull;
15bit rxempty;
16
17assign txfull = 0;
18assign rxempty = 0;
19
20typedef enum
21 { TX
22 , RX
23 , OUTDATA
24 , OUTDATA_SEL0
25 } CtrlBit;
26
27bit [UROM_BITS-1:0] ctrl;
28urom#(UROM, UIP_BITS, UROM_BITS) urom(uip, ctrl);
29
30bit [0:0] sel;
31assign sel = {ctrl[OUTDATA_SEL0]};
32
33bit [BUS_BITS-1:0] dout;
34assign 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
40assign dbus = ctrl[OUTDATA] ? dout : {(BUS_BITS){1'bZ}};
41
42always @(posedge clk) begin
43 if (ctrl[TX])
44 $display("tx %x", dbus[7:0]);
45end
46
47endmodule