Selaa lähdekoodia

spirom: fix data corruption on reader stall

On reader stall, would drop and then duplicate a two-bit word because
the latching into the FIFO was not consistent with the latching into
spi_io_q. Fix this. Now all data is downloaded correctly!
H. Peter Anvin 3 vuotta sitten
vanhempi
commit
0b0eec607b

BIN
fpga/output_files/max80.jbc


BIN
fpga/output_files/max80.jic


BIN
fpga/output_files/max80.pof


BIN
fpga/output_files/max80.sof


+ 14 - 12
fpga/spirom.sv

@@ -33,24 +33,23 @@ module spirom (
    parameter [23:0] romstart = 24'h10_0000; // 1 MB
    parameter [23:0] datalen  = 24'h08_0000; // 512K
 
+   //
+   // FIFO and input latches
+   //
    reg [1:0] 		  spi_in_q;
    reg 			  spi_in_req;
+   reg 			  spi_in_req_q;
    wire [11:0] 		  wrusedw;
-   (* syn_preserve = 1 *) wire [8:0] 		  rdusedw;
-
-   //
-   // FIFO
-   //
+   wire [8:0] 		  rdusedw;
    wire [15:0] 		  fifo_out;
-
-   (* syn_preserve = 1 *) wire rdempty;
+   wire 		  rdempty;
    
    ddufifo spirom_fifo (
 			.aclr ( ~rst_n ),
 
 			.wrclk ( rom_clk ),
 			.data ( spi_in_q ),
-			.wrreq ( spi_in_req ),
+			.wrreq ( spi_in_req_q ),
 			.wrfull ( ),
 			.wrusedw ( wrusedw ),
 
@@ -128,12 +127,15 @@ module spirom (
 	  spi_clk_en   <= 1'b0;
 	  spi_data_ctr <= datalen << 2;
 	  spi_cs_n     <= 1'b1;
+	  spi_in_req   <= 1'b0;
+	  spi_in_req_q <= 1'b0;
        end
      else
        begin
-	  spi_in_q   <= spi_io;
-	  spi_in_req <= 1'b0;
-	  spi_clk_en <= 1'b0;
+	  spi_in_q     <= spi_io;
+	  spi_in_req   <= 1'b0;
+	  spi_in_req_q <= spi_in_req;
+	  spi_clk_en   <= 1'b0;
 
 	  if ( ~|spi_data_ctr )
 	    begin
@@ -149,7 +151,7 @@ module spirom (
 		    spi_clk_en <= (~wrusedw) >= 12'd128;
 		    if ( spi_clk_en )
 		      begin
-			 if ( spi_cmd_ctr[5] & spi_cmd_ctr[3] & spi_cmd_ctr[0] )
+			 if ( spi_cmd_ctr[5] & spi_cmd_ctr[3] )
 			   begin
 			      spi_in_req <= 1'b1;
 			      spi_data_ctr <= spi_data_ctr - 1'b1;