|
@@ -45,6 +45,8 @@ module i2c (
|
|
|
|
|
|
reg busy; // Data received, running
|
|
|
reg end_s, end_p; // Trailing S(r) or P
|
|
|
+ reg started; // S sent, but not P
|
|
|
+ reg is_sr; // Sending an S(r)
|
|
|
|
|
|
reg [1:0] outsymb; // Output symbol [abnormal, data]
|
|
|
|
|
@@ -66,6 +68,7 @@ module i2c (
|
|
|
sda_out <= 1'b1;
|
|
|
phase <= 2'b00;
|
|
|
do_read <= 1'b0;
|
|
|
+ started <= 1'b0;
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
@@ -109,11 +112,12 @@ module i2c (
|
|
|
// started or not.
|
|
|
if (~busy)
|
|
|
begin
|
|
|
- outsymb[1] <= 1'b1;
|
|
|
+ outsymb <= { 1'b1, ~started };
|
|
|
end
|
|
|
else
|
|
|
begin
|
|
|
- bitctr <= bitctr + 1'b1;
|
|
|
+ bitctr <= bitctr + 1'b1;
|
|
|
+ started <= 1'b1;
|
|
|
|
|
|
case (bitctr)
|
|
|
4'd0, 4'd1, 4'd2, 4'd3, 4'd4,
|
|
@@ -124,28 +128,36 @@ module i2c (
|
|
|
do_read <= 1'b1;
|
|
|
if (bitctr[3])
|
|
|
begin
|
|
|
- bitctr <= end_p ? 4'd12 :
|
|
|
- end_s ? 4'd14 : 4'd0;
|
|
|
- busy <= end_p;
|
|
|
+ bitctr <= end_p ? 4'd12 :
|
|
|
+ end_s ? 4'd14 : 4'd0;
|
|
|
+ busy <= end_p;
|
|
|
+ // If we are to be followed by
|
|
|
+ // an S(r) condition, we are not
|
|
|
+ // really "started".
|
|
|
+ started <= ~(end_s | end_p);
|
|
|
end
|
|
|
end // case: 4'd0, 4'd1, 4'd2, 4'd3, 4'd4,...
|
|
|
|
|
|
// Stop condition
|
|
|
4'd12: begin
|
|
|
+ started <= 1'b0;
|
|
|
outsymb <= 2'b10; // A0
|
|
|
end
|
|
|
|
|
|
4'd13: begin
|
|
|
+ started <= 1'b0;
|
|
|
outsymb <= 2'b11; // A1
|
|
|
busy <= 1'b0;
|
|
|
end
|
|
|
|
|
|
// Start condition
|
|
|
4'd14: begin
|
|
|
+ started <= 1'b1;
|
|
|
outsymb <= 2'b11; // A1
|
|
|
end
|
|
|
|
|
|
4'd15: begin
|
|
|
+ started <= 1'b1;
|
|
|
outsymb <= 2'b00; // N0
|
|
|
end
|
|
|
|