From 158f544daaeb7266028fb960c6629471909af81a Mon Sep 17 00:00:00 2001 From: Marno van der Maas Date: Tue, 19 Mar 2024 14:04:58 +0000 Subject: [PATCH] [i2c,rtl] Saturate NACK counter After reducing the counter from 32 bits to 8 bits, saturation is now more likely. This commit saturates the NACK counter at the maximum value of 0xFF. Signed-off-by: Marno van der Maas --- hw/ip/i2c/rtl/i2c_core.sv | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/ip/i2c/rtl/i2c_core.sv b/hw/ip/i2c/rtl/i2c_core.sv index 09bf19153c494..3efbe4f964e73 100644 --- a/hw/ip/i2c/rtl/i2c_core.sv +++ b/hw/ip/i2c/rtl/i2c_core.sv @@ -188,9 +188,11 @@ module i2c_core import i2c_pkg::*; assign hw2reg.target_fifo_status.acqlvl.d = MaxFifoDepthW'(acq_fifo_depth); assign hw2reg.acqdata.abyte.d = acq_fifo_rdata[7:0]; assign hw2reg.acqdata.signal.d = acq_fifo_rdata[AcqFifoWidth-1:8]; - // Add one to the target NACK count if this target has sent a NACK. - assign hw2reg.target_nack_count.de = event_target_nack; - assign hw2reg.target_nack_count.d = reg2hw.target_nack_count.q + 1; + + // Add one to the target NACK count if this target has sent a NACK and if + // counter has not saturated. + assign hw2reg.target_nack_count.de = event_target_nack && (reg2hw.target_nack_count.q < 8'hFF); + assign hw2reg.target_nack_count.d = reg2hw.target_nack_count.q + 1; assign override = reg2hw.ovrd.txovrden;