Skip to content

Commit f1c8844

Browse files
committed
library/spi_engine: fix corner case in the execution
Inserts a ready signal for when the valid_indices has finished its inner logic. This avoid the possible issue where the latency of the command is smaller than this logic. This could only happen in the FIFO mode. Signed-off-by: Carlos Souza <[email protected]>
1 parent 1d4f513 commit f1c8844

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg.v

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ module spi_engine_execution_shiftreg #(
9393
wire sdo_toshiftreg; //it is using the valid data for shifting in this cycle
9494
wire last_sdi_bit;
9595
wire trigger_rx_s;
96+
wire index_ready;
9697
wire sdo_data_ready_int;
9798

9899
// sdo_data_ready_int is active when two conditions are true:
@@ -102,7 +103,7 @@ module spi_engine_execution_shiftreg #(
102103
// (s_offload_active || current_instr == CMD_TRANSFER)
103104
// when s_offload_active, it is possible to prefetch
104105
// when !s_offload_active, it is waiting for write instruction
105-
assign sdo_data_ready_int = ((!data_sdo_v) || (sdo_toshiftreg)) && (s_offload_active || exec_cmd);
106+
assign sdo_data_ready_int = ((!data_sdo_v) || (sdo_toshiftreg)) && (s_offload_active || (exec_cmd & index_ready));
106107
assign sdo_data_ready = sdo_data_ready_int;
107108
assign sdo_io_ready = data_sdo_v;
108109

@@ -126,7 +127,8 @@ module spi_engine_execution_shiftreg #(
126127
.transfer_active (transfer_active),
127128
.trigger_tx (trigger_tx),
128129
.first_bit (first_bit),
129-
.sdo_enabled(sdo_enabled),
130+
.sdo_enabled (sdo_enabled),
131+
.index_ready (index_ready),
130132
.data_assembled (aligned_sdo_data),
131133
.last_handshake (data_sdo_v));
132134

library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg_data_assemble.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module spi_engine_execution_shiftreg_data_assemble #(
5656
input trigger_tx,
5757
input first_bit,
5858
input sdo_enabled,
59+
output index_ready,
5960
output [(NUM_OF_SDIO * DATA_WIDTH)-1:0] data_assembled,
6061
output last_handshake
6162
);
@@ -79,6 +80,7 @@ module spi_engine_execution_shiftreg_data_assemble #(
7980

8081
assign data_assembled = aligned_data;
8182
assign last_handshake = last_handshake_int;
83+
assign index_ready = index_ready_reg;
8284

8385
// register data
8486
always @(posedge clk) begin
@@ -107,16 +109,19 @@ module spi_engine_execution_shiftreg_data_assemble #(
107109
reg [3:0] i;
108110
reg [3:0] j;
109111
reg [3:0] mask_index;
112+
reg index_ready_reg;
110113
always @(posedge clk) begin
111114
if (resetn == 1'b0) begin
112115
num_active_lanes <= NUM_OF_SDIO;
116+
index_ready_reg <= 1'b0;
113117
mask_index <= 0;
114118
j <= 0;
115119
end else begin
116120
if (exec_sdo_lane_cmd) begin
117121
count_active_lanes = 0;
118122
i = 0;
119123
j <= 0;
124+
index_ready_reg <= 1'b0;
120125
mask_index <= 0;
121126
for (i = 0; i < NUM_OF_SDIO; i = i + 1) begin
122127
count_active_lanes = count_active_lanes + current_cmd[i];
@@ -129,6 +134,7 @@ module spi_engine_execution_shiftreg_data_assemble #(
129134
mask_index <= mask_index + 1;
130135
end
131136
j <= j + 1;
137+
index_ready_reg <= (j == NUM_OF_SDIO-1) ? 1'b1 : 1'b0;
132138
end
133139
end
134140
end

0 commit comments

Comments
 (0)