@@ -135,6 +135,7 @@ always @(posedge clk) begin
135135 // meets the preceding min high hold time -
136136 // note that {done} && !{err} encodes the fact that
137137 // the min hold time was met earlier in STOP_BIT state
138+ // or READY state
138139 sample_count <= 4'b1 ;
139140 err <= 1'b0 ;
140141 end else begin
@@ -256,17 +257,45 @@ always @(posedge clk) begin
256257 * Wait one full bit cycle to sustain the {out} data, the
257258 * {done} signal or the {err} signal
258259 */
259- sample_count <= sample_count + 4'b1 ;
260- if (! err && ! in_sample) begin
261- // accept the trigger to start, right from stop signal high
262- // (in this case transmit signaling of {done} is in progress)
263- sample_count <= 4'b1 ;
264- out_hold_count <= sample_count + 5'b00010 ; // continue counting
265- state <= `IDLE;
260+ sample_count <= sample_count + 4'b1 ;
261+ if (! err && ! in_sample || & sample_count) begin
262+ // check if this is the change to a start signal -
263+ // in_sample has met the min high hold time
264+ // any time it drops to low in this state
265+ // (also in these cases, namely !{err} or tick 15 special case,
266+ // signaling of {done} is in progress)
267+ if (& sample_count) begin // reached 15, last tick, and no error
268+ // (signaling of {done} is now complete)
269+ if (in_sample) begin
270+ // not transitioning to start bit -
271+ // sample_count wraps around to zero
272+ received_data <= 8'b0 ;
273+ busy <= 1'b0 ;
274+ end else begin
275+ // transitioning to start bit -
276+ // sustain the {busy} signal high
277+ sample_count <= 4'b1 ;
278+ end
279+ done <= 1'b0 ;
280+ out <= 8'b0 ;
281+ state <= `IDLE;
282+ end else begin
283+ // in_sample drops from high to low
284+ // (signaling of {done} continues)
285+ sample_count <= 4'b1 ;
286+ // continue the counting
287+ out_hold_count <= sample_count + 5'b00010 ;
288+ state <= `IDLE;
289+ end
266290 end else if (& sample_count[3 :1 ]) begin // reached 14 -
267291 // additional tick 15 comes from transitting the READY state
268292 // to get to the RESET state
269- state <= `RESET;
293+ if (err || ! in_sample) begin
294+ state <= `RESET;
295+ end
296+ // otherwise, signaling of {done} is in progress (i.e. !{err}) -
297+ // in this case, on tick 15, will be checking if in_sample
298+ // dropped from high to low on the entry to IDLE state
270299 end
271300 end
272301
0 commit comments