瀏覽代碼

fix-ef2-input-synchronizer-clocks

root 3 月之前
父節點
當前提交
5b3492dc35
共有 2 個文件被更改,包括 18 次插入 和 6 次删除
  1. 12 3
      src/common/uart_rx_byte.v
  2. 6 3
      src/rtl/prod2u_p4_i2c_stop_start_read.v

+ 12 - 3
src/common/uart_rx_byte.v

@@ -21,15 +21,25 @@ module uart_rx_byte #(
     localparam [1:0] ST_DATA = 2'd2;
     localparam [1:0] ST_DATA = 2'd2;
     localparam [1:0] ST_STOP = 2'd3;
     localparam [1:0] ST_STOP = 2'd3;
 
 
-    (* async_reg = "true" *) reg [1:0] rx_sync_pipe;
+    (* keep = "true" *) reg [1:0] rx_sync_pipe;
     reg [1:0] state;
     reg [1:0] state;
     reg [COUNTER_BITS-1:0] bit_counter;
     reg [COUNTER_BITS-1:0] bit_counter;
     reg [2:0] bit_index;
     reg [2:0] bit_index;
     reg [7:0] data_reg;
     reg [7:0] data_reg;
 
 
+    // Keep the asynchronous input synchronizer on an ordinary, explicitly
+    // clocked two-flop path. TD maps async_reg plus async-reset metadata to an
+    // unclocked first-stage primitive on EF2; synchronous reset avoids that
+    // unsafe mapping while preserving two full settling clocks.
+    always @(posedge clk) begin
+        if (!rst_n)
+            rx_sync_pipe <= 2'b11;
+        else
+            rx_sync_pipe <= {rx_sync_pipe[0], rx_i};
+    end
+
     always @(posedge clk or negedge rst_n) begin
     always @(posedge clk or negedge rst_n) begin
         if (!rst_n) begin
         if (!rst_n) begin
-            rx_sync_pipe <= 2'b11;
             state <= ST_IDLE;
             state <= ST_IDLE;
             bit_counter <= {COUNTER_BITS{1'b0}};
             bit_counter <= {COUNTER_BITS{1'b0}};
             bit_index <= 3'd0;
             bit_index <= 3'd0;
@@ -38,7 +48,6 @@ module uart_rx_byte #(
             byte_data <= 8'd0;
             byte_data <= 8'd0;
             framing_error <= 1'b0;
             framing_error <= 1'b0;
         end else begin
         end else begin
-            rx_sync_pipe <= {rx_sync_pipe[0], rx_i};
             byte_valid <= 1'b0;
             byte_valid <= 1'b0;
             framing_error <= 1'b0;
             framing_error <= 1'b0;
 
 

+ 6 - 3
src/rtl/prod2u_p4_i2c_stop_start_read.v

@@ -53,8 +53,8 @@ module prod2u_p4_i2c_stop_start_read #(
     localparam [4:0] ST_ABORT_SCL_HIGH = 5'd16;
     localparam [4:0] ST_ABORT_SCL_HIGH = 5'd16;
     localparam [4:0] ST_ABORT_RELEASE = 5'd17;
     localparam [4:0] ST_ABORT_RELEASE = 5'd17;
 
 
-    (* async_reg = "true" *) reg [1:0] scl_sync;
-    (* async_reg = "true" *) reg [1:0] sda_sync;
+    (* keep = "true" *) reg [1:0] scl_sync;
+    (* keep = "true" *) reg [1:0] sda_sync;
     (* keep = "true", syn_encoding = "sequential", fsm_encoding = "none" *)
     (* keep = "true", syn_encoding = "sequential", fsm_encoding = "none" *)
     reg [4:0] state;
     reg [4:0] state;
     reg [31:0] phase_count;
     reg [31:0] phase_count;
@@ -86,7 +86,10 @@ module prod2u_p4_i2c_stop_start_read #(
         end
         end
     endgenerate
     endgenerate
 
 
-    always @(posedge clk or negedge rst_n) begin
+    // Synchronous-reset input synchronizers keep both EF2 stages on the
+    // declared sys_clk. See uart_rx_byte for the corresponding TD mapping
+    // constraint.
+    always @(posedge clk) begin
         if (!rst_n) begin
         if (!rst_n) begin
             scl_sync <= 2'b11;
             scl_sync <= 2'b11;
             sda_sync <= 2'b11;
             sda_sync <= 2'b11;