fix(i2c): saturate I2cMaster timeout counter - #1471
Open
ruck314 wants to merge 1 commit into
Open
Conversation
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
marked this pull request as ready for review
August 18, 2026 23:09
This was referenced Aug 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
I2cMaster.vhddeclares the FSM timeout counter asinteger 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 comparesr.timeragainstTIMEOUT_C, so on the cycle the register reaches its maximum the case statement first evaluatesTIMEOUT_C + 1, which is outside the declared range. This aborts VCS simulations of any design that lets an I2C transaction reach its timeout:Each increment is now guarded so the counter saturates at
TIMEOUT_C.