Skip to content

Commit

Permalink
SPI Engine: improve timing
Browse files Browse the repository at this point in the history
pre-compute the last bit counter value

Signed-off-by: Laez Barbosa <[email protected]>
  • Loading branch information
LBFFilho committed Dec 6, 2024
1 parent 6399547 commit 8d2c41a
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ module spi_engine_execution #(

reg last_transfer;
reg [7:0] word_length = DATA_WIDTH;
reg [7:0] last_bit_count = DATA_WIDTH-1;
reg [7:0] left_aligned = 8'b0;

assign first_bit = ((bit_counter == 'h0) || (bit_counter == word_length));
Expand Down Expand Up @@ -244,6 +245,7 @@ module spi_engine_execution #(
sdo_idle_state <= SDO_DEFAULT;
clk_div <= DEFAULT_CLK_DIV;
word_length <= DATA_WIDTH;
last_bit_count <= DATA_WIDTH-1;
left_aligned <= 8'b0;
end else if (exec_write_cmd == 1'b1) begin
if (cmd[9:8] == REG_CONFIG) begin
Expand All @@ -256,6 +258,7 @@ module spi_engine_execution #(
end else if (cmd[9:8] == REG_WORD_LENGTH) begin
// the max value of this reg must be DATA_WIDTH
word_length <= cmd[7:0];
last_bit_count <= cmd[7:0] - 1;
left_aligned <= DATA_WIDTH - cmd[7:0];
end
end
Expand Down Expand Up @@ -458,7 +461,7 @@ module spi_engine_execution #(
// end_of_word will signal the end of a transaction, pushing the command
// stream execution to the next command. end_of_word in normal mode can be
// generated using the global bit_counter
assign last_bit = bit_counter == word_length - 1;
assign last_bit = (bit_counter == last_bit_count);
assign end_of_word = last_bit == 1'b1 && ntx_rx == 1'b1 && clk_div_last == 1'b1;

always @(posedge clk) begin
Expand Down

0 comments on commit 8d2c41a

Please sign in to comment.