Repository navigation
BitTiming: align validation with ISO 11898-1 and improve from_sample_point - #2147
Merged
Merged
Conversation
…le point rule only in strict mode
…oints of 100% or more
…and sample point rules
…alid config timings
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.
Summary of Changes
Review of
can/bit_timing.pyagainst ISO 11898-1:2015, with fixes, docs and test cleanup.BitTimingvalidated nothing unlessstrict=True. Both classes now always check the basic structure (brp, tseg1, tseg2 ≥ 1; 1 ≤ sjw ≤ min(tseg1, tseg2);f_clock/bitrate > 0). Invalid input raisesValueErrorinstead ofZeroDivisionErrorlater.btr0/btr1raise instead of silently overflowing (pcan, kvaser, vector, slcan, canalystii send these to hardware).str()showsBTR: n/a.from_registersaccepts only 8-bit values.sjw < tseg1in the nominal phase. The ≥ 50 % sample point rule now applies only in strict mode and the solvers; ISO does not restrict the sample point.from_sample_point()prefers the most accurate bitrate, then the closest sample point. For CAN FD a shared prescaler comes right after bitrate accuracy, because equal time quanta give the best clock tolerance. The solvers useround()instead ofint()and reject sample points ≥ 100 %.oscillator_tolerance()uses the exact time quantum (12.5 ns was rounded to 12 ns).--timingCLI error now says "incomplete or invalid".Related Issues / Pull Requests
Type of Change
Checklist
tox).Additional Notes
Intended behaviour changes:
strict=False.from_sample_point()returns different timings for about 20 % of common classic inputs: no tseg2 = 1, SJW limited by the ISO rules, and equal or better bitrate. No common input loses its solution. This also affectsgs_usb(10 of 63 tested bitrate/clock combinations at its default 87.5 %). Odd bitrates find solutions more often.BitTimingFdnow accepts sample points below 50 %.bitrate, as before), but a warning is logged.🤖 Generated with AI