summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--hdl/rs232.sv18
-rw-r--r--hdl/top.sv5
2 files changed, 22 insertions, 1 deletions
diff --git a/hdl/rs232.sv b/hdl/rs232.sv
index b898a9c..2a31e31 100644
--- a/hdl/rs232.sv
+++ b/hdl/rs232.sv
@@ -8,6 +8,8 @@ module rs232_tx
8 ( input bit clock 8 ( input bit clock
9 , input bit reset 9 , input bit reset
10 10
11 , output bit clock_busy
12
11 , output bit out_ready 13 , output bit out_ready
12 , input bit out_valid 14 , input bit out_valid
13 , input uart_byte_t out_data 15 , input uart_byte_t out_data
@@ -20,6 +22,8 @@ module rs232_tx
20 uart_byte_t hold; 22 uart_byte_t hold;
21 bit parity; 23 bit parity;
22 24
25 assign clock_busy = hold_valid;
26
23 (* syn_encoding = "one-hot" *) enum int unsigned 27 (* syn_encoding = "one-hot" *) enum int unsigned
24 { START 28 { START
25 , DATA 29 , DATA
@@ -108,6 +112,7 @@ module rs232_rx
108 ( input bit clock 112 ( input bit clock
109 , input bit reset 113 , input bit reset
110 114
115 , input bit clock_busy
111 , output bit clock_out 116 , output bit clock_out
112 117
113 , input bit in_ready 118 , input bit in_ready
@@ -133,6 +138,7 @@ module rs232_rx
133 138
134 bit [$clog2(OVERSAMPLE+1)+2:0] sample; 139 bit [$clog2(OVERSAMPLE+1)+2:0] sample;
135 bit [$clog2(OVERSAMPLE+1):0] clock_counter; 140 bit [$clog2(OVERSAMPLE+1):0] clock_counter;
141 bit [$clog2(OVERSAMPLE+1):0] next_clock_counter;
136 142
137 always @(posedge clock, posedge reset) begin 143 always @(posedge clock, posedge reset) begin
138 if (reset) begin 144 if (reset) begin
@@ -145,6 +151,7 @@ module rs232_rx
145 parity = PARITY; 151 parity = PARITY;
146 sample = 0; 152 sample = 0;
147 clock_counter = 0; 153 clock_counter = 0;
154 next_clock_counter = 0;
148 end else begin 155 end else begin
149 automatic bit ok = 0; 156 automatic bit ok = 0;
150 157
@@ -170,6 +177,15 @@ module rs232_rx
170 clock_out = 0; 177 clock_out = 0;
171 end 178 end
172 179
180 ++next_clock_counter;
181 if (next_clock_counter > OVERSAMPLE) begin
182 next_clock_counter = 0;
183 if (!clock_busy) begin
184 clock_out = 1;
185 clock_counter = 0;
186 end
187 end
188
173 if (ok) begin 189 if (ok) begin
174 case (state) 190 case (state)
175 191
@@ -208,7 +224,7 @@ module rs232_rx
208 in_data = buffer; 224 in_data = buffer;
209 end 225 end
210 if (txd == 1 && parity == 0) begin 226 if (txd == 1 && parity == 0) begin
211 clock_counter = (OVERSAMPLE+1)/2; 227 next_clock_counter = (OVERSAMPLE+1)/2;
212 end 228 end
213 if (txd == 1) 229 if (txd == 1)
214 state = state.first; 230 state = state.first;
diff --git a/hdl/top.sv b/hdl/top.sv
index 2ee6be9..d7e6acc 100644
--- a/hdl/top.sv
+++ b/hdl/top.sv
@@ -52,6 +52,8 @@ module top
52 bit rs232_rx_clock; 52 bit rs232_rx_clock;
53 assign rs232_rx_clock = internal_clock; 53 assign rs232_rx_clock = internal_clock;
54 54
55 bit rs232_clock_busy;
56
55 bit wire_tx_ready; 57 bit wire_tx_ready;
56 bit wire_tx_valid; 58 bit wire_tx_valid;
57 uart_byte_t wire_tx_data; 59 uart_byte_t wire_tx_data;
@@ -63,6 +65,8 @@ module top
63 ( .clock(rs232_tx_clock) 65 ( .clock(rs232_tx_clock)
64 , .reset(rs232_tx_reset) 66 , .reset(rs232_tx_reset)
65 67
68 , .clock_busy(rs232_clock_busy)
69
66 , .out_ready(wire_tx_ready) 70 , .out_ready(wire_tx_ready)
67 , .out_valid(wire_tx_valid) 71 , .out_valid(wire_tx_valid)
68 , .out_data(wire_tx_data) 72 , .out_data(wire_tx_data)
@@ -102,6 +106,7 @@ module top
102 ( .clock(rs232_rx_clock) 106 ( .clock(rs232_rx_clock)
103 , .reset(internal_reset) 107 , .reset(internal_reset)
104 108
109 , .clock_busy(rs232_clock_busy)
105 , .clock_out(rs232_tx_clock) 110 , .clock_out(rs232_tx_clock)
106 111
107 , .in_ready(wire_rx_ready) 112 , .in_ready(wire_rx_ready)