Skip to content

Commit 4458ec0

Browse files
committed
library/spi_engine: improve SDI FIFO mode
Every read returns a valid data for an active lane. It is not necessary to perform N reads everytime. Signed-off-by: Carlos Souza <carlos.souza@analog.com>
1 parent 0fc3835 commit 4458ec0

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

library/spi_engine/axi_spi_engine/axi_spi_engine.v

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ module axi_spi_engine #(
136136
localparam PCORE_VERSION = 'h010600;
137137
localparam S_AXI = 0;
138138
localparam UP_FIFO = 1;
139+
localparam max_num_of_reads = NUM_OF_SDI-1;
139140

140141
wire clk;
141142
wire rstn;
@@ -157,11 +158,14 @@ module axi_spi_engine #(
157158
wire sdo_fifo_in_valid;
158159

159160
wire [31:0] sdi_fifo_level;
161+
reg [NUM_OF_SDI*DATA_WIDTH/8-1:0] sdi_fifo_tkeep_int;
162+
wire [NUM_OF_SDI*DATA_WIDTH/8-1:0] sdi_fifo_tkeep;
160163
wire sdi_fifo_almost_full;
161164
wire up_sdi_fifo_almost_full;
162165

163166
wire [DATA_WIDTH-1:0] sdi_fifo_out_data;
164167
wire sdi_fifo_out_ready;
168+
reg find_next_valid_fifo_value;
165169
wire sdi_fifo_out_valid;
166170

167171
wire [7:0] sync_fifo_data;
@@ -316,14 +320,6 @@ module axi_spi_engine #(
316320
end
317321
end
318322

319-
always @(posedge clk) begin
320-
if (rstn == 1'b0) begin
321-
up_rack_ff <= 'd0;
322-
end else begin
323-
up_rack_ff <= up_rreq_s;
324-
end
325-
end
326-
327323
reg [7:0] offload_sdo_mem_address_width = OFFLOAD0_SDO_MEM_ADDRESS_WIDTH;
328324
reg [7:0] offload_cmd_mem_address_width = OFFLOAD0_CMD_MEM_ADDRESS_WIDTH;
329325
reg [7:0] sdi_fifo_address_width = SDI_FIFO_ADDRESS_WIDTH;
@@ -470,6 +466,20 @@ module axi_spi_engine #(
470466

471467
assign sdi_fifo_out_ready = up_rreq_s == 1'b1 && up_raddr_s == 8'h3a;
472468

469+
integer i;
470+
always @(posedge spi_clk) begin
471+
if (!spi_resetn) begin
472+
sdi_fifo_tkeep_int <= {(NUM_OF_SDI*DATA_WIDTH/8){1'b1}};
473+
end else begin
474+
if (cmd_valid && cmd_data[15:8] == 8'h23) begin
475+
for (i = 0; i < NUM_OF_SDI; i = i + 1) begin
476+
sdi_fifo_tkeep_int[i*DATA_WIDTH/8+:DATA_WIDTH/8] <= {DATA_WIDTH/8{cmd_data[i]}};
477+
end
478+
end
479+
end
480+
end
481+
assign sdi_fifo_tkeep = sdi_fifo_tkeep_int;
482+
473483
util_axis_fifo_asym #(
474484
.ASYNC_CLK(ASYNC_SPI_CLK),
475485
.S_DATA_WIDTH(NUM_OF_SDI * DATA_WIDTH),
@@ -479,7 +489,7 @@ module axi_spi_engine #(
479489
.ALMOST_EMPTY_THRESHOLD(1),
480490
.ALMOST_FULL_THRESHOLD(1),
481491
.TLAST_EN(0),
482-
.TKEEP_EN(0),
492+
.TKEEP_EN(1),
483493
.REDUCED_FIFO(0)
484494
) i_sdi_fifo(
485495
.s_axis_aclk(spi_clk),
@@ -489,13 +499,13 @@ module axi_spi_engine #(
489499
.s_axis_data(sdi_data),
490500
.s_axis_room(),
491501
.s_axis_tlast(),
492-
.s_axis_tkeep(),
502+
.s_axis_tkeep(sdi_fifo_tkeep),
493503
.s_axis_full(),
494504
.s_axis_almost_full(sdi_fifo_almost_full),
495505

496506
.m_axis_aclk(clk),
497507
.m_axis_aresetn(up_sw_resetn),
498-
.m_axis_ready(sdi_fifo_out_ready),
508+
.m_axis_ready(sdi_fifo_out_ready || find_next_valid_fifo_value),
499509
.m_axis_valid(sdi_fifo_out_valid),
500510
.m_axis_data(sdi_fifo_out_data),
501511
.m_axis_tlast(),
@@ -504,6 +514,41 @@ module axi_spi_engine #(
504514
.m_axis_empty(),
505515
.m_axis_almost_empty());
506516

517+
assign sdi_fifo_out_ready = up_rreq_s == 1'b1 && up_raddr_s == 8'h3a;
518+
519+
reg [3:0] sdi_out_counter;
520+
reg find_next_valid_fifo_value;
521+
always @(posedge clk) begin
522+
if (rstn == 1'b0) begin
523+
up_rack_ff <= 'd0;
524+
end else begin
525+
if (sdi_fifo_out_ready || find_next_valid_fifo_value) begin
526+
up_rack_ff <= sdi_fifo_out_valid;
527+
end else begin
528+
up_rack_ff <= up_rreq_s;
529+
end
530+
end
531+
end
532+
533+
//the current logic is considering that there is only one active lane in the set of lanes
534+
always @(posedge clk) begin
535+
if (!up_sw_resetn) begin
536+
find_next_valid_fifo_value <= 1'b0;
537+
sdi_out_counter <= 4'hf;
538+
end else if (sdi_fifo_out_ready) begin
539+
find_next_valid_fifo_value <= ~sdi_fifo_out_valid; //only in the next cycle it is possible to check if it is necessary a new read
540+
sdi_out_counter <= sdi_fifo_out_valid ? 4'hf : 0;
541+
end else begin
542+
if (!sdi_fifo_out_valid && sdi_out_counter < max_num_of_reads) begin
543+
find_next_valid_fifo_value <= 1'b1;
544+
sdi_out_counter <= sdi_out_counter + 1'b1;
545+
end else begin
546+
find_next_valid_fifo_value <= 1'b0;
547+
sdi_out_counter <= 4'hf;
548+
end
549+
end
550+
end
551+
507552
generate if (ASYNC_SPI_CLK) begin
508553

509554
// synchronization FIFO for the SYNC interface

library/spi_engine/spi_engine_execution/spi_engine_execution_shiftreg_data_assemble.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ always @(posedge clk) begin
8181
count_active_lanes = 0;
8282
i = 0;
8383
j <= 0;
84+
mask_index <= 0;
8485
for (i = 0; i < NUM_OF_SDI; i = i + 1) begin
8586
count_active_lanes = count_active_lanes + current_cmd[i];
8687
end

0 commit comments

Comments
 (0)