-
Notifications
You must be signed in to change notification settings - Fork 210
transceivers: fix I2C read bug #1787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
labbott
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
drv/transceivers-server/src/main.rs
Outdated
| // - 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])) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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:
| 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.
There was a problem hiding this comment.
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.
#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_bufferso calling code can just deal with the status register and the data buffer.Fixes #1786