From d45be68ac45d7a74126f44b2ac15e22aa4c04534 Mon Sep 17 00:00:00 2001 From: Laez Barbosa Date: Fri, 12 Jan 2024 11:10:18 -0300 Subject: [PATCH] SPI Engine: edge-based trigger Previous level-based trigger could cause issues in some low sampling rate setups. This commit changes it to edge-based. Signed-off-by: Laez Barbosa --- .../spi_engine_offload/spi_engine_offload.v | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/spi_engine/spi_engine_offload/spi_engine_offload.v b/library/spi_engine/spi_engine_offload/spi_engine_offload.v index 1c7529c2a..b5c5516ba 100644 --- a/library/spi_engine/spi_engine_offload/spi_engine_offload.v +++ b/library/spi_engine/spi_engine_offload/spi_engine_offload.v @@ -1,6 +1,6 @@ // *************************************************************************** // *************************************************************************** -// Copyright (C) 2015-2023 Analog Devices, Inc. All rights reserved. +// Copyright (C) 2015-2024 Analog Devices, Inc. All rights reserved. // // In this HDL repository, there are many different and unique modules, consisting // of various HDL (Verilog or VHDL) components. The individual modules are @@ -96,9 +96,12 @@ module spi_engine_offload #( reg [15:0] cmd_mem[0:2**CMD_MEM_ADDRESS_WIDTH-1]; reg [(DATA_WIDTH-1):0] sdo_mem[0:2**SDO_MEM_ADDRESS_WIDTH-1]; + reg trigger_last_reg; + wire [15:0] cmd_int_s; wire [CMD_MEM_ADDRESS_WIDTH-1:0] spi_cmd_rd_addr_next; wire spi_enable; + wire trigger_posedge; assign cmd_valid = spi_active; assign sdo_data_valid = spi_active; @@ -246,6 +249,16 @@ module spi_engine_offload #( .out_resetn(1'b1), .out_bits(trigger_s)); + always @(posedge spi_clk) begin + if (!spi_resetn) begin + trigger_last_reg <= 1'b0; + end else begin + trigger_last_reg <= trigger_s; + end + end + + assign trigger_posedge = trigger_s && !trigger_last_reg; + always @(posedge spi_clk) begin if (spi_resetn == 1'b0) begin spi_active <= 1'b0; @@ -253,7 +266,7 @@ module spi_engine_offload #( if (spi_active == 1'b0) begin // start offload when we have a valid trigger, offload is enabled and // the DMA is enabled - if (trigger_s == 1'b1 && spi_enable == 1'b1 && offload_sdi_ready == 1'b1) + if (trigger_posedge == 1'b1 && spi_enable == 1'b1 && offload_sdi_ready == 1'b1) spi_active <= 1'b1; end else if (cmd_ready == 1'b1 && spi_cmd_rd_addr_next == ctrl_cmd_wr_addr) begin spi_active <= 1'b0;