Skip to content

fix(i2c): saturate I2cMaster timeout counter - #1471

Open
ruck314 wants to merge 1 commit into
pre-releasefrom
I2cMaster-patch
Open

fix(i2c): saturate I2cMaster timeout counter#1471
ruck314 wants to merge 1 commit into
pre-releasefrom
I2cMaster-patch

Conversation

@ruck314

@ruck314 ruck314 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Description

I2cMaster.vhd declares the FSM timeout counter as integer range 0 to TIMEOUT_C, but the three waiting states (WAIT_ADDR_ACK_S, WAIT_READ_DATA_S, WAIT_WRITE_ACK_S) incremented it unconditionally. The timeout detection compares r.timer against TIMEOUT_C, so on the cycle the register reaches its maximum the case statement first evaluates TIMEOUT_C + 1, which is outside the declared range. This aborts VCS simulations of any design that lets an I2C transaction reach its timeout:

Error-[SIMERR_CONSTERR_INDEXEDRANGE] Range Violation Error
protocols/i2c/rtl/I2cMaster.vhd, 263
              v.timer := r.timer + 1;
  Value 782501 is out of range 0 to 782500

Each increment is now guarded so the counter saturates at TIMEOUT_C.

The timer field is declared as integer range 0 to TIMEOUT_C, but the
WAIT_ADDR_ACK_S, WAIT_READ_DATA_S, and WAIT_WRITE_ACK_S states
incremented it unconditionally. Because the timeout check compares
r.timer against TIMEOUT_C, the increment evaluates TIMEOUT_C+1 one
cycle before the timeout is detected, which trips a range violation in
VCS simulation (SIMERR_CONSTERR_INDEXEDRANGE).

Guard each increment so the counter saturates at TIMEOUT_C. The
registered value is unchanged: when the guard blocks the increment,
v.timer keeps its default of 0 and the timeout logic also forces 0, so
the timeout error still fires on the same clock cycle as before.
@ruck314
ruck314 marked this pull request as ready for review August 18, 2026 23:09
This was referenced Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant