[spi_device] Connect watermark to interrupt source
This commit connects the watermark event to the interrupt source.
watermark event occurs in SCK domain. The logic registers the comb
signal at SCK then pulse sync the signal into the bus clock domain
(sck_).
Signed-off-by: Eunchan Kim <eunchan@opentitan.org>
diff --git a/hw/ip/spi_device/rtl/spi_device.sv b/hw/ip/spi_device/rtl/spi_device.sv
index 6a38e6f..291305f 100644
--- a/hw/ip/spi_device/rtl/spi_device.sv
+++ b/hw/ip/spi_device/rtl/spi_device.sv
@@ -281,11 +281,14 @@
// Interrupts in Flash mode
logic intr_upload_cmdfifo_not_empty, intr_upload_payload_not_empty;
logic intr_readbuf_watermark, intr_readbuf_flip;
+ logic flash_sck_readbuf_watermark, flash_sck_readbuf_flip;
// TODO: Implement
- assign intr_readbuf_watermark = 1'b 0;
assign intr_readbuf_flip = 1'b 0;
+ logic unused_flip_event;
+ assign unused_flip_event = flash_sck_readbuf_flip;
+
// TPM ===============================================================
localparam int unsigned TpmFifoDepth = 4; // 4B
localparam int unsigned TpmFifoPtrW = $clog2(TpmFifoDepth+1);
@@ -587,6 +590,14 @@
.intr_o (intr_upload_payload_not_empty_o )
);
+ prim_pulse_sync u_flash_readbuf_watermark_pulse_sync (
+ .clk_src_i (clk_spi_in_buf ),
+ .rst_src_ni (rst_ni ),
+ .src_pulse_i (flash_sck_readbuf_watermark),
+ .clk_dst_i (clk_i ),
+ .rst_dst_ni (rst_ni ),
+ .dst_pulse_o (intr_readbuf_watermark )
+ );
prim_intr_hw #(.Width(1)) u_intr_readbuf_watermark (
.clk_i,
.rst_ni,
@@ -1229,7 +1240,8 @@
.io_mode_o (sub_iomode [IoModeReadCmd]),
- .read_watermark_o ()
+ .sck_read_watermark_o (flash_sck_readbuf_watermark),
+ .sck_read_flip_o (flash_sck_readbuf_flip)
);
// Begin: Read Status ==============================================
diff --git a/hw/ip/spi_device/rtl/spi_readcmd.sv b/hw/ip/spi_device/rtl/spi_readcmd.sv
index a2cb57a..9628b57 100644
--- a/hw/ip/spi_device/rtl/spi_readcmd.sv
+++ b/hw/ip/spi_device/rtl/spi_readcmd.sv
@@ -169,8 +169,12 @@
output io_mode_e io_mode_o,
// Read watermark event occurs when current address exceeds the threshold cfg
- // value for the first time after hit the current read buffer (1kB granularity).
- output read_watermark_o
+ // value for the first time after hit the current read buffer (1kB
+ // granularity).
+ //
+ // These signals are pulse signals.
+ output logic sck_read_watermark_o,
+ output logic sck_read_flip_o
);
@@ -332,6 +336,9 @@
// Indication of data output phase
logic output_start;
+ // Events: watermark, flip
+ logic read_watermark, read_flip;
+
//////////////
// Datapath //
//////////////
@@ -669,6 +676,21 @@
end
//- END: Main state machine -----------------------------------------------
+ // Events: register
+ // watermark, flip are pulse signals. watermark pulse width is 1 SCK. flip
+ // pulse width varies (2 to 32).
+ // They are not registered (output of comb logic). Register the signal then
+ // pulse sync at TOP
+ always_ff @(posedge clk_i or negedge sys_rst_ni) begin
+ if (!sys_rst_ni) begin
+ sck_read_watermark_o <= 1'b 0;
+ sck_read_flip_o <= 1'b 0;
+ end else begin
+ sck_read_watermark_o <= read_watermark;
+ sck_read_flip_o <= read_flip;
+ end
+ end
+
///////////////
// Instances //
///////////////
@@ -719,8 +741,8 @@
.start_i (output_start),
- .event_watermark_o (read_watermark_o),
- .event_flip_o ()
+ .event_watermark_o (read_watermark),
+ .event_flip_o (read_flip)
);
////////////////
diff --git a/hw/ip/spi_device/rtl/spid_readbuffer.sv b/hw/ip/spi_device/rtl/spid_readbuffer.sv
index 51e62f0..3f9e886 100644
--- a/hw/ip/spi_device/rtl/spid_readbuffer.sv
+++ b/hw/ip/spi_device/rtl/spid_readbuffer.sv
@@ -114,6 +114,7 @@
assign current_buffer_idx = current_address_i[31:OneBufferAw];
assign flip = current_buffer_idx == next_buffer_addr;
+ // TODO: Make event_flip_o pulse signal
assign event_flip_o = active && flip;
// TODO: Consider the case if host jumps the address? (report error?)