Skip to content

Commit fc64e75

Browse files
committed
Simplify because one state variable not actually needed
1 parent a6324c6 commit fc64e75

File tree

6 files changed

+9
-22
lines changed

6 files changed

+9
-22
lines changed

Uart8Receiver.v

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ reg [1:0] in_reg = 2'b0; // shift reg for input signal conditioning
3232
reg [4:0] in_hold_reg = 5'b0; // shift reg for signal hold time checks
3333
reg [3:0] sample_count = 4'b0; // count ticks for 16x oversample
3434
reg [4:0] out_hold_count = 5'b0; // count ticks before clearing output data
35-
reg was_stop_good = 1'b0; // flag for stop signal hold time was met
3635
reg [2:0] bit_index = 3'b0; // index for 8-bit data
3736
reg [7:0] received_data = 8'b0; // storage for the deserialized data
3837
wire in_sample;
@@ -96,7 +95,6 @@ always @(posedge clk) begin
9695
// state variables
9796
sample_count <= 4'b0;
9897
out_hold_count <= 5'b0;
99-
was_stop_good <= 1'b0;
10098
received_data <= 8'b0;
10199
// outputs
102100
busy <= 1'b0;
@@ -120,8 +118,10 @@ always @(posedge clk) begin
120118
*/
121119
if (!in_sample) begin
122120
if (sample_count == 4'b0) begin
123-
if (&in_prior_hold_reg || was_stop_good) begin
124-
// meets the preceding min high hold time
121+
if (&in_prior_hold_reg || done && !err) begin
122+
// meets the preceding min high hold time -
123+
// note that {done} && !{err} encodes the fact that
124+
// the min hold time was met earlier in STOP_BIT state
125125
sample_count <= 4'b1;
126126
err <= 1'b0;
127127
end else begin
@@ -133,7 +133,6 @@ always @(posedge clk) begin
133133
sample_count <= sample_count + 4'b1;
134134
if (&sample_count[2:0]) begin // reached 7
135135
sample_count <= 4'b0; // start the interval count over
136-
was_stop_good <= 1'b0;
137136
busy <= 1'b1;
138137
err <= 1'b0;
139138
state <= `START_BIT;
@@ -199,7 +198,6 @@ always @(posedge clk) begin
199198
// changed to a start signal
200199
if (sample_count == 4'b1000 &&
201200
&in_prior_hold_reg) begin // meets the hold time
202-
was_stop_good <= 1'b1;
203201
// can accept the transmitted data and output it
204202
sample_count <= 4'b0;
205203
out_hold_count <= 5'b1;
@@ -217,7 +215,6 @@ always @(posedge clk) begin
217215
end
218216
end else begin
219217
if (&in_current_hold_reg) begin // meets min high hold time
220-
was_stop_good <= 1'b1;
221218
// can accept the transmitted data and output it
222219
sample_count <= 4'b0;
223220
done <= 1'b1;

tests/25.gtkw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[*]
55
[dumpfile] "25.vcd"
66
[dumpfile_mtime] "Sun Nov 27 13:41:17 2022"
7-
[dumpfile_size] 870294
7+
[dumpfile_size] 870249
88
[savefile] "25.gtkw"
99
[timestart] 704900
1010
[size] 1536 937
@@ -43,8 +43,6 @@ test.uart.rxInst.in_current_hold_reg[3:0]
4343
(3)test.uart.rxInst.in_current_hold_reg[3:0]
4444
@1001200
4545
-group_end
46-
@28
47-
test.uart.rxInst.was_stop_good
4846
@22
4947
test.uart.rxInst.sample_count[3:0]
5048
test.uart.rxInst.out_hold_count[4:0]

tests/26.gtkw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[*]
55
[dumpfile] "26.vcd"
66
[dumpfile_mtime] "Sun Nov 27 13:44:41 2022"
7-
[dumpfile_size] 870225
7+
[dumpfile_size] 870203
88
[savefile] "26.gtkw"
99
[timestart] 704900
1010
[size] 1536 937
@@ -43,8 +43,6 @@ test.uart.rxInst.in_current_hold_reg[3:0]
4343
(3)test.uart.rxInst.in_current_hold_reg[3:0]
4444
@1001200
4545
-group_end
46-
@28
47-
test.uart.rxInst.was_stop_good
4846
@22
4947
test.uart.rxInst.sample_count[3:0]
5048
test.uart.rxInst.out_hold_count[4:0]

tests/27.gtkw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[*]
55
[dumpfile] "27.vcd"
66
[dumpfile_mtime] "Sun Nov 27 13:48:44 2022"
7-
[dumpfile_size] 870278
7+
[dumpfile_size] 870233
88
[savefile] "27.gtkw"
99
[timestart] 704900
1010
[size] 1536 937
@@ -43,8 +43,6 @@ test.uart.rxInst.in_current_hold_reg[3:0]
4343
(3)test.uart.rxInst.in_current_hold_reg[3:0]
4444
@1401200
4545
-group_end
46-
@28
47-
test.uart.rxInst.was_stop_good
4846
@22
4947
test.uart.rxInst.sample_count[3:0]
5048
test.uart.rxInst.out_hold_count[4:0]

tests/27a.gtkw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[*]
55
[dumpfile] "27a.vcd"
66
[dumpfile_mtime] "Sun Nov 27 13:57:22 2022"
7-
[dumpfile_size] 870162
7+
[dumpfile_size] 870117
88
[savefile] "27a.gtkw"
99
[timestart] 704900
1010
[size] 1536 937
@@ -43,8 +43,6 @@ test.uart.rxInst.in_current_hold_reg[3:0]
4343
(3)test.uart.rxInst.in_current_hold_reg[3:0]
4444
@1401200
4545
-group_end
46-
@28
47-
test.uart.rxInst.was_stop_good
4846
@22
4947
test.uart.rxInst.sample_count[3:0]
5048
test.uart.rxInst.out_hold_count[4:0]

tests/28.gtkw

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[*]
55
[dumpfile] "28.vcd"
66
[dumpfile_mtime] "Sun Nov 27 14:02:30 2022"
7-
[dumpfile_size] 869773
7+
[dumpfile_size] 869728
88
[savefile] "28.gtkw"
99
[timestart] 704900
1010
[size] 1536 937
@@ -43,8 +43,6 @@ test.uart.rxInst.in_current_hold_reg[3:0]
4343
(3)test.uart.rxInst.in_current_hold_reg[3:0]
4444
@1401200
4545
-group_end
46-
@28
47-
test.uart.rxInst.was_stop_good
4846
@22
4947
test.uart.rxInst.sample_count[3:0]
5048
test.uart.rxInst.out_hold_count[4:0]

0 commit comments

Comments
 (0)