-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Wire: Enable a timeout by default #363
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
base: master
Are you sure you want to change the base?
Wire: Enable a timeout by default #363
Conversation
In commit deea929 (Introduce non compulsory Wire timeout), some timeout-related functions were added. To allow writing portable sketches, it is important for those sketch to know whether they are using a Wire library version that is new enough to offer these functions without having to rely on version number checking (since other Arduino cores have their own versioning schemes). This adds a WIRE_HAS_TIMEOUT macro, similar to the existing WIRE_HAS_END macro, to facilitate that. This relates to arduino#42.
Previously, these were implicit in the default values of some global variables. Now, the default timeout is defined in Wire.h, which: - Makes it easier to change later - Allows sketches to detect the default timeout value
When no timeout is explicitly configured, Wire now uses a timeout of 25ms, resetting the Wire hardware if a timeout occurs. The timeout length matches the timeout you get when you call `Wire.setWireTimeout()` without arguments, and is loosely based on the SMBus timeout and maximum clock stretching time (though it works quite differently) and is rather long. In practice, this means that even if another master is on the bus, or slaves are using significant clock stretching, the timeout will probably not trigger unless there really is a lockup. This also enables a reset of the Wire hardware on a timeout (unlike `Wire.setWireTimeout()` without arguments), under the assumption that if a sketch has not set up timeout settings explicitly, it probably just wants things to keep running as well as possible and resetting allows recovering from most transient lockups. See arduino#42 for earlier discussion of this.
I'm in favor of making 25ms the default timeout. |
Though on second thought we should probably make sure we understand the throughput implications for turning this on by default. I'll try to put some measurements together. |
It has been nearly two years since the timeout feature was merged. I think it could be time to enable it by default? |
When no timeout is explicitly configured, Wire now uses a timeout of
25ms, resetting the Wire hardware if a timeout occurs.
The timeout length matches the timeout you get when you call
Wire.setWireTimeout()
without arguments, and is loosely based on theSMBus timeout and maximum clock stretching time (though it works quite
differently) and is rather long. In practice, this means that even if
another master is on the bus, or slaves are using significant clock
stretching, the timeout will probably not trigger unless there really is
a lockup.
This also enables a reset of the Wire hardware on a timeout (unlike
Wire.setWireTimeout()
without arguments), under the assumption that ifa sketch has not set up timeout settings explicitly, it probably just
wants things to keep running as well as possible and resetting allows
recovering from most transient lockups.
See #42 for earlier discussion of this.
As discussed before, this is not intended to be merged directly, but
only after the timeout feature has been available for a while. However,
having this PR might help not forgetting this later, and serves as a
place for discussing the exact values of the timeout already.
Note this PR also includes the commits from #362, but those should be ignored here. Only the last commit is relevant here.