summaryrefslogtreecommitdiff
path: root/hdl/top.sv
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--hdl/top.sv40
1 files changed, 28 insertions, 12 deletions
diff --git a/hdl/top.sv b/hdl/top.sv
index ca45aa9..ffe6656 100644
--- a/hdl/top.sv
+++ b/hdl/top.sv
@@ -34,28 +34,42 @@ module top
34 34
35 //assign clock_out = internal_clock; 35 //assign clock_out = internal_clock;
36 36
37 bit rs232_clock = 0; 37 bit rs232_tx_clock = 0;
38 bit [17:0] rs232_div = 0; 38 bit [17:0] rs232_tx_div = 0;
39 always @(posedge internal_clock) begin 39 always @(posedge internal_clock) begin
40 if (internal_reset) begin 40 if (internal_reset) begin
41 rs232_clock = 0; 41 rs232_tx_clock = 0;
42 rs232_div = 0; 42 rs232_tx_div = 0;
43 end else begin 43 end else begin
44 if (++rs232_div == 49987) begin // (30MHz/2)/300 44 if (++rs232_tx_div == 130) begin // (30MHz/2)/115200
45 ++rs232_clock; 45 ++rs232_tx_clock;
46 rs232_div = 0; 46 rs232_tx_div = 0;
47 end 47 end
48 end 48 end
49 end 49 end
50 50
51 assign clock_out = rs232_clock; 51 assign clock_out = rs232_tx_clock;
52
53 bit rs232_rx_clock = 0;
54 bit [4:0] rs232_rx_div = 0;
55 always @(posedge internal_clock) begin
56 if (internal_reset) begin
57 rs232_rx_clock = 0;
58 rs232_rx_div = 0;
59 end else begin
60 if (++rs232_rx_div == 16) begin // (30MHz/2)/(115200*8)
61 ++rs232_rx_clock;
62 rs232_rx_div = 0;
63 end
64 end
65 end
52 66
53 bit wire_tx_ready; 67 bit wire_tx_ready;
54 bit wire_tx_valid; 68 bit wire_tx_valid;
55 uart_byte_t wire_tx_data; 69 uart_byte_t wire_tx_data;
56 70
57 rs232_tx wiretx 71 rs232_tx wiretx
58 ( .clock(rs232_clock) 72 ( .clock(rs232_tx_clock)
59 , .reset(internal_reset) 73 , .reset(internal_reset)
60 74
61 , .out_ready(wire_tx_ready) 75 , .out_ready(wire_tx_ready)
@@ -73,7 +87,7 @@ module top
73 #( .WIDTH_BITS($bits(uart_byte_t)) 87 #( .WIDTH_BITS($bits(uart_byte_t))
74 ) fifotx 88 ) fifotx
75 ( .clock_in(internal_clock) 89 ( .clock_in(internal_clock)
76 , .clock_out(rs232_clock) 90 , .clock_out(rs232_tx_clock)
77 91
78 , .in_ready(rs232_tx_ready) 92 , .in_ready(rs232_tx_ready)
79 , .in_valid(rs232_tx_valid) 93 , .in_valid(rs232_tx_valid)
@@ -88,8 +102,10 @@ module top
88 bit wire_rx_valid; 102 bit wire_rx_valid;
89 uart_byte_t wire_rx_data; 103 uart_byte_t wire_rx_data;
90 104
91 rs232_rx wirerx 105 rs232_rx
92 ( .clock(rs232_clock) 106 #( .OVERSAMPLE(7)
107 ) wirerx
108 ( .clock(rs232_rx_clock)
93 , .reset(internal_reset) 109 , .reset(internal_reset)
94 110
95 , .in_ready(wire_rx_ready) 111 , .in_ready(wire_rx_ready)