Skip to content

Conversation

@Aaron-Hartwig
Copy link
Contributor

@Aaron-Hartwig Aaron-Hartwig commented May 20, 2024

#1768 did not properly account for the FIFO behavior of the FPGA's data buffers. The "check the status byte" portion of the loop happened outside the part where we read the buffer, and since the buffer was just memory-mapped registers it could be repeatedly without consequence. Since the data was now in a FIFO, I was inadvertently draining the FIFO before the transaction was done. This PR consolidates the "is I2C done yet" logic into the get_i2c_status_and_read_buffer so calling code can just deal with the status register and the data buffer.

Fixes #1786

@Aaron-Hartwig Aaron-Hartwig requested review from labbott and mkeeter May 20, 2024 17:52
Copy link
Collaborator

@labbott labbott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// - SFF-8636 rev 2.10a, Section 6.2.4
Ok(Celsius(out.temperature.get() as f32 / 256.0))
} else {
Err(FpgaError::ImplError(status.as_bytes()[0]))
Copy link
Collaborator

@mkeeter mkeeter May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing? I think it's going to return the value of rdata_fifo_empty, because it's casting an PortI2CStatus to a &[u8] and taking the first byte (which happens to be rdata_fifo_empty: bool)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I actually don't care about the whole status here, I really just want to log the error observed. I'm going to make this line:

Suggested change
Err(FpgaError::ImplError(status.as_bytes()[0]))
Err(FpgaError::ImplError(status.error.as_bytes()[0]))

And get rid of the AsBytes deriviation on the PortI2CStatus type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more note: it looks like you can do status.error as u8 instead of status.error.as_bytes()[0], since it's already a single-byte enum type.

@Aaron-Hartwig Aaron-Hartwig merged commit 1d3f3d5 into master May 20, 2024
@Aaron-Hartwig Aaron-Hartwig deleted the aaron/transceivers-i2c-read-fix branch May 20, 2024 21:31
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.

transceivers: get_i2c_status_and_read_buffer reading FIFO before I2C transaction finishes

5 participants