Skip to content

Commit 5b8197b

Browse files
committed
Fix err output during the transition to start
1 parent 627ce97 commit 5b8197b

File tree

4 files changed

+177
-1
lines changed

4 files changed

+177
-1
lines changed

Uart8Receiver.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ always @(posedge clk) begin
107107
// outputs
108108
busy <= 1'b0;
109109
done <= 1'b0;
110-
err <= 1'b0;
110+
if (en && err && !in_sample) begin // in error condition already -
111+
// leave the output uninterrupted
112+
err <= 1'b1;
113+
end else begin
114+
err <= 1'b0;
115+
end
111116
out <= 8'b0; // output parallel data only during {done}
112117
// next state
113118
if (en) begin

tests/30.gtkw

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[*]
2+
[*] GTKWave Analyzer v3.3.81 (w)1999-2017 BSI
3+
[*] Sun Jan 01 23:26:14 2023
4+
[*]
5+
[dumpfile] "30.vcd"
6+
[dumpfile_mtime] "Sun Jan 01 23:25:38 2023"
7+
[dumpfile_size] 873907
8+
[savefile] "30.gtkw"
9+
[timestart] 704900
10+
[size] 1536 937
11+
[pos] -9 -9
12+
*-16.818604 1054500 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
13+
[treeopen] test.
14+
[treeopen] test.uart.
15+
[sst_width] 197
16+
[signals_width] 290
17+
[sst_expanded] 1
18+
[sst_vpaned_height] 444
19+
@28
20+
test.txByte_1[7:0]
21+
test.rx
22+
test.uart.rxInst.clk
23+
test.uart.rxInst.en
24+
test.uart.rxInst.busy
25+
test.uart.rxInst.done
26+
test.uart.rxInst.err
27+
test.uart.rxInst.in_sample
28+
@c00022
29+
test.uart.rxInst.in_prior_hold_reg[3:0]
30+
@28
31+
(0)test.uart.rxInst.in_prior_hold_reg[3:0]
32+
(1)test.uart.rxInst.in_prior_hold_reg[3:0]
33+
(2)test.uart.rxInst.in_prior_hold_reg[3:0]
34+
(3)test.uart.rxInst.in_prior_hold_reg[3:0]
35+
@1401200
36+
-group_end
37+
@c00022
38+
test.uart.rxInst.in_current_hold_reg[3:0]
39+
@28
40+
(0)test.uart.rxInst.in_current_hold_reg[3:0]
41+
(1)test.uart.rxInst.in_current_hold_reg[3:0]
42+
(2)test.uart.rxInst.in_current_hold_reg[3:0]
43+
(3)test.uart.rxInst.in_current_hold_reg[3:0]
44+
@1401200
45+
-group_end
46+
@22
47+
test.uart.rxInst.sample_count[3:0]
48+
test.uart.rxInst.out_hold_count[4:0]
49+
@28
50+
test.uart.rxInst.state[2:0]
51+
test.uart.rxInst.bit_index[2:0]
52+
test.uart.rxInst.received_data[7:0]
53+
test.uart.rxInst.out[7:0]
54+
[pattern_trace] 1
55+
[pattern_trace] 0

tests/30.v

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
`timescale 100ns/1ns
2+
`default_nettype none
3+
4+
`include "Uart8.v"
5+
6+
module test;
7+
8+
localparam CLOCK_FREQ = 12000000; // Alhambra board
9+
localparam SIM_STEP_FREQ = 1 / 0.0000001 / 2; // this sim timescale 100ns
10+
11+
// for the simulation timeline:
12+
// ratio SIM_STEP_FREQ MHz / CLOCK_FREQ MHz gives the output waveform in proper time
13+
// (*but note all clocks and the timeline are approximate due to rounding)
14+
localparam SIM_TIMESTEP_FACTOR = SIM_STEP_FREQ / CLOCK_FREQ;
15+
16+
reg clk;
17+
reg en_1;
18+
reg rx;
19+
wire rxBusy_2;
20+
wire rxDone_2;
21+
wire rxErr_2;
22+
reg [7:0] txByte_1;
23+
wire [7:0] rxByte_2;
24+
25+
Uart8 #(.CLOCK_RATE(CLOCK_FREQ)) uart(
26+
.clk(clk),
27+
28+
// rx interface
29+
.rxEn(en_1),
30+
.rx(rx),
31+
.rxBusy(rxBusy_2),
32+
.rxDone(rxDone_2),
33+
.rxErr(rxErr_2),
34+
.out(rxByte_2)
35+
36+
// tx interface (unused)
37+
);
38+
39+
initial clk = 1'b0;
40+
41+
always #SIM_TIMESTEP_FACTOR clk = ~clk;
42+
43+
initial begin
44+
$dumpfile(`DUMP_FILE_NAME);
45+
$dumpvars(0, test);
46+
47+
// #65 == 1 rx clock period (approximately) at 9600 baud
48+
#240
49+
en_1 = 1'b1;
50+
txByte_1 = 8'b11010110;
51+
rx = 1'b0;
52+
53+
$display(" tx data: %8b", txByte_1);
54+
#160
55+
rx = 1'b1;
56+
#360
57+
rx = 1'b0;
58+
#1075 // instead of #1042, this makes transmit clock sync with receive clock (a 3% difference)
59+
rx = txByte_1[0];
60+
61+
$display("%7.2fms | rx first bit: %1b", $realtime/10000, rx);
62+
#1075
63+
rx = txByte_1[1];
64+
65+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
66+
#1075
67+
rx = txByte_1[2];
68+
69+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
70+
#1075
71+
rx = txByte_1[3];
72+
73+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
74+
#1075
75+
rx = txByte_1[4];
76+
77+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
78+
#1075
79+
rx = txByte_1[5];
80+
81+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
82+
#1075
83+
rx = txByte_1[6];
84+
85+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
86+
#1075
87+
rx = txByte_1[7];
88+
89+
$display("%7.2fms | rx last bit: %1b", $realtime/10000, rx);
90+
#530
91+
rx = 1'b1;
92+
#530
93+
rx = 1'b0;
94+
95+
$display("%7.4fms | end of stop bit | start of start bit: %1b", $realtime/10000, rx);
96+
#530
97+
rx = 1'b1;
98+
99+
$display("%7.4fms | rx start bit glitch: %1b", $realtime/10000, rx);
100+
#545
101+
rx = txByte_1[0];
102+
103+
$display("%7.2fms | rx first bit: %1b", $realtime/10000, rx);
104+
#1075
105+
rx = txByte_1[1];
106+
107+
$display("%7.2fms | rx next bit: %1b", $realtime/10000, rx);
108+
#1075
109+
rx = txByte_1[2];
110+
#1120
111+
112+
$finish();
113+
end
114+
115+
endmodule

tests/Key.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@
2727
27. One frame, and next xaction starts during the READY state: success
2828
28: One frame, next xaction does not start in READY state, goes to RESET state: fail to start second xaction because rx stop signal too long (*shows err)
2929
29. Error at beginning of next xaction due to rx start signal not long enough to meet its extra hold requirement: success accepting previous xaction (*shows done, shows err)
30+
30. Error at end of xaction held over to beginning of next xaction: fail to accept, fail to start (*shows err sustained high, no glitch low-high)

0 commit comments

Comments
 (0)