summaryrefslogtreecommitdiff
path: root/hdl/rs232.sv
diff options
context:
space:
mode:
Diffstat (limited to 'hdl/rs232.sv')
-rw-r--r--hdl/rs232.sv18
1 files changed, 17 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;