Skip to content
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

212 i2c fix broken timeout handler (Meson) #241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

omeh-a
Copy link
Member

@omeh-a omeh-a commented Sep 13, 2024

This commit adds a timeout handler to discard requests if a timeout is reported by the I2C hardware.

@omeh-a omeh-a added drivers Issues pertaining to driver code for a device class meson Devices on a Meson platform - e.g. ODROID C4 protocol Issues pertaining to protocols for interfacing with drivers labels Sep 13, 2024
@omeh-a omeh-a linked an issue Sep 13, 2024 that may be closed by this pull request
@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch 3 times, most recently from 773571e to 6dd5973 Compare September 13, 2024 02:32
@Ivan-Velickovic
Copy link
Collaborator

What happens with the example now? I imagine we get thousands of error responses in the client now? Is that not messing anything up in the clients?

@Ivan-Velickovic
Copy link
Collaborator

What happens with the example now? I imagine we get thousands of error responses in the client now? Is that not messing anything up in the clients?

(referring to just the PN532 part of the I2C example).

@omeh-a
Copy link
Member Author

omeh-a commented Sep 13, 2024

What happens with the example now? I imagine we get thousands of error responses in the client now? Is that not messing anything up in the clients?

Yeah pretty much. These timeouts occur because of how the PN532 abuses NACKs and it's not the driver's fault. It doesn't mess anything up, although I've noticed there is some kind of weird cross-talk issue when the ds3231 and pn532 are enabled at the same time that I am trying to fix now.

@omeh-a omeh-a marked this pull request as draft September 13, 2024 03:12
@omeh-a
Copy link
Member Author

omeh-a commented Sep 13, 2024

Converting to draft pending fixing the crosstalk issue mentioned above

@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch 4 times, most recently from cbefc96 to 65ef3fb Compare September 18, 2024 04:20
@omeh-a omeh-a marked this pull request as ready for review September 18, 2024 04:20
@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch from 65ef3fb to 8f5cb2c Compare September 18, 2024 04:21
@omeh-a
Copy link
Member Author

omeh-a commented Sep 18, 2024

Little block of code for token return got yeeted by the patch generated by the style checker somehow?? Adding back now.

@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch from 8f5cb2c to 225a98f Compare September 18, 2024 04:27
Comment on lines +54 to +57
// Max number of timeout IRQs before giving up. For some devices such as the pn532,
// these arrive constantly in normal operation. As a result we need a high threshold
// before acting.
#define TIMEOUT_MAX 100000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems weird to work-around broken hardware in the driver rather than the client.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I might be missing something but here it seems we're just hacking around the fact that the PN532 generates a lot of timeouts.

Copy link
Member Author

Choose a reason for hiding this comment

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

The real issue is that we don't know why the timeouts get generated. The main thing we need this driver to do is to avoid locking up in the case that an actual defective device ACKs and then stops. Since the I2C hardware doesn't stop when an IRQ arrives, it's really hard to reason about whether any particular timeout is authentic, so I figured that just counting them is an OK fix since we know that a large quantity continuously discounts the possibility of a weird device.

Since we have no way to know why the IRQs fire, we can't really figure out why the PN532 causes it. IMO it's not worth leaving this driver in a state where it can lock up because of that

Copy link
Member Author

Choose a reason for hiding this comment

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

(as in the timeout IRQs are undocumented - the actual condition that makes them fire is unclear to me even when looking at the logic analyser output)

@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch 3 times, most recently from 976a037 to ace86f5 Compare September 30, 2024 05:00
@omeh-a omeh-a force-pushed the 212-i2c-fix-broken-timeout-handler branch from ace86f5 to 328df63 Compare December 4, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
drivers Issues pertaining to driver code for a device class meson Devices on a Meson platform - e.g. ODROID C4 protocol Issues pertaining to protocols for interfacing with drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I2C: Fix broken timeout handler (!)
3 participants