diff --git a/library/spi_engine/spi_engine_execution/spi_engine_execution.v b/library/spi_engine/spi_engine_execution/spi_engine_execution.v index 4dd61f6732..91b9f3abe7 100644 --- a/library/spi_engine/spi_engine_execution/spi_engine_execution.v +++ b/library/spi_engine/spi_engine_execution/spi_engine_execution.v @@ -163,8 +163,6 @@ module spi_engine_execution #( wire io_ready1; wire io_ready2; - wire end_of_sdi_latch; - wire sample_sdo; (* direct_enable = "yes" *) wire cs_gen; @@ -200,8 +198,7 @@ module spi_engine_execution #( .trigger_tx(trigger_tx), .trigger_rx(trigger_rx), .first_bit(first_bit), - .cs_activate(cs_activate), - .end_of_sdi_latch(end_of_sdi_latch)); + .cs_activate(cs_activate)); assign sample_sdo = sdo_data_valid && ((trigger_tx && last_bit) || (wait_for_io || exec_transfer_cmd)); @@ -331,7 +328,7 @@ module spi_engine_execution #( end else begin case (inst_d1) CMD_TRANSFER: begin - if (transfer_active == 1'b0 && wait_for_io == 1'b0 && end_of_sdi_latch == 1'b1) + if (transfer_active == 1'b0 && wait_for_io == 1'b0) idle <= 1'b1; end CMD_CHIPSELECT: begin diff --git a/library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg.v b/library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg.v index 2298a20861..10a68b2fc2 100644 --- a/library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg.v +++ b/library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg.v @@ -76,8 +76,7 @@ module spi_engine_execution_shiftreg #( input trigger_tx, input trigger_rx, input first_bit, - input cs_activate, - output end_of_sdi_latch + input cs_activate ); reg [ 7:0] sdi_counter = 8'b0; @@ -156,9 +155,7 @@ module spi_engine_execution_shiftreg #( generate if (ECHO_SCLK == 1) begin : g_echo_sclk_miso_latch - reg [7:0] sdi_counter_d = 8'b0; - reg [7:0] sdi_transfer_counter = 8'b0; - reg [7:0] num_of_transfers = 8'b0; + reg last_sdi_bit_r; reg [(NUM_OF_SDI * DATA_WIDTH)-1:0] sdi_data_latch = {(NUM_OF_SDI * DATA_WIDTH){1'b0}}; if ((DEFAULT_SPI_CFG[1:0] == 2'b01) || (DEFAULT_SPI_CFG[1:0] == 2'b10)) begin : g_echo_miso_nshift_reg @@ -185,10 +182,10 @@ module spi_engine_execution_shiftreg #( always @(posedge echo_sclk or posedge cs_activate) begin if (cs_activate) begin sdi_counter <= 8'b0; - sdi_counter_d <= 8'b0; + last_sdi_bit_r <= 1'b0; end else begin - sdi_counter <= (sdi_counter == word_length-1) ? 8'b0 : sdi_counter + 1'b1; - sdi_counter_d <= sdi_counter; + last_sdi_bit_r <= (sdi_counter == word_length - 1); // FIXME: potentially unsafe path: what are the guarantees of settling time between changing word_length and first echo_sclk edge? + sdi_counter <= (sdi_counter == word_length - 1) ? 8'b0 : sdi_counter + 1'b1; end end @@ -214,17 +211,17 @@ module spi_engine_execution_shiftreg #( always @(posedge echo_sclk or posedge cs_activate) begin if (cs_activate) begin sdi_counter <= 8'b0; - sdi_counter_d <= 8'b0; + last_sdi_bit_r <= 1'b0; end else begin - sdi_counter <= (sdi_counter == word_length-1) ? 8'b0 : sdi_counter + 1'b1; - sdi_counter_d <= sdi_counter; + last_sdi_bit_r <= (sdi_counter == word_length - 1); // FIXME: potentially unsafe path: what are the guarantees of settling time between changing word_length and first echo_sclk edge? + sdi_counter <= (sdi_counter == word_length - 1) ? 8'b0 : sdi_counter + 1'b1; end end end assign sdi_data = sdi_data_latch; - assign last_sdi_bit = (sdi_counter == 0) && (sdi_counter_d == word_length-1); + assign last_sdi_bit = last_sdi_bit_r; // sdi_data_valid is synchronous to SPI clock, so synchronize the // last_sdi_bit to SPI clock @@ -250,34 +247,10 @@ module spi_engine_execution_shiftreg #( end end - always @(posedge clk) begin - if (cs_activate) begin - num_of_transfers <= 8'b0; - end else begin - if (current_instr == CMD_TRANSFER) begin - // current_cmd contains the NUM_OF_TRANSFERS - 1 - num_of_transfers <= current_cmd[7:0] + 1'b1; - end - end - end - - always @(posedge clk) begin - if (cs_activate) begin - sdi_transfer_counter <= 0; - end else if (last_sdi_bit_m[2] == 1'b0 && - last_sdi_bit_m[1] == 1'b1) begin - sdi_transfer_counter <= sdi_transfer_counter + 1'b1; - end - end - - assign end_of_sdi_latch = last_sdi_bit_m[2] & (sdi_transfer_counter == num_of_transfers); - end /* g_echo_sclk_miso_latch */ else begin : g_sclk_miso_latch - assign end_of_sdi_latch = 1'b1; - for (i=0; i