Browse Source

i2c: fix spurious Sr condition; revert to 400 kHz

Fix problem with spurious Sr condition on I2C causing the RTC read to
fail.
H. Peter Anvin 3 years ago
parent
commit
c26574cc6a
7 changed files with 19 additions and 7 deletions
  1. 17 5
      fpga/i2c.sv
  2. BIN
      fpga/output_files/max80.jbc
  3. BIN
      fpga/output_files/max80.jic
  4. BIN
      fpga/output_files/max80.pof
  5. BIN
      fpga/output_files/max80.sof
  6. 1 1
      fw/boot.mif
  7. 1 1
      fw/rtc.c

+ 17 - 5
fpga/i2c.sv

@@ -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
 

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


+ 1 - 1
fw/boot.mif

@@ -1069,7 +1069,7 @@ CONTENT BEGIN
 0426 : 8082FFE5;
 0427 : DE067139;
 0428 : DA26DC22;
-0429 : 0D100793;
+0429 : 03400793;
 042A : D64ED84A;
 042B : A8F02423;
 042C : 64B537C5;

+ 1 - 1
fw/rtc.c

@@ -58,7 +58,7 @@ void read_rtc(void)
     int i;
     struct tms tms;
 
-    i2c_set_speed(100);
+    i2c_set_speed(400);
 
     i2c_send(RTC_WCMD, 0);