From c3dd0394c82716f1aeccda7042fbe9baec42aa22 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 15 May 2022 15:52:01 -0700 Subject: Only phase shift the RS232 tx clock when we are between bytes. --- hdl/rs232.sv | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'hdl/rs232.sv') 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 ( input bit clock , input bit reset + , output bit clock_busy + , output bit out_ready , input bit out_valid , input uart_byte_t out_data @@ -20,6 +22,8 @@ module rs232_tx uart_byte_t hold; bit parity; + assign clock_busy = hold_valid; + (* syn_encoding = "one-hot" *) enum int unsigned { START , DATA @@ -108,6 +112,7 @@ module rs232_rx ( input bit clock , input bit reset + , input bit clock_busy , output bit clock_out , input bit in_ready @@ -133,6 +138,7 @@ module rs232_rx bit [$clog2(OVERSAMPLE+1)+2:0] sample; bit [$clog2(OVERSAMPLE+1):0] clock_counter; + bit [$clog2(OVERSAMPLE+1):0] next_clock_counter; always @(posedge clock, posedge reset) begin if (reset) begin @@ -145,6 +151,7 @@ module rs232_rx parity = PARITY; sample = 0; clock_counter = 0; + next_clock_counter = 0; end else begin automatic bit ok = 0; @@ -170,6 +177,15 @@ module rs232_rx clock_out = 0; end + ++next_clock_counter; + if (next_clock_counter > OVERSAMPLE) begin + next_clock_counter = 0; + if (!clock_busy) begin + clock_out = 1; + clock_counter = 0; + end + end + if (ok) begin case (state) @@ -208,7 +224,7 @@ module rs232_rx in_data = buffer; end if (txd == 1 && parity == 0) begin - clock_counter = (OVERSAMPLE+1)/2; + next_clock_counter = (OVERSAMPLE+1)/2; end if (txd == 1) state = state.first; -- cgit v1.2.3