sys/can: improve SJW calculation#21756
Conversation
sys/can/device.c
Outdated
| timing->sjw = SJW; | ||
| } | ||
| else { | ||
| if (!timing->sjw) { |
There was a problem hiding this comment.
To facilitate validation for any reader, it would be valuable to have the CIA paper reference here as a comment.
sys/can/device.c
Outdated
| timing->sjw = SJW; | ||
| } | ||
| else { | ||
| if (!timing->sjw) { |
There was a problem hiding this comment.
SJW must not be bigger than phase segments 1 and 2. If a value is provided, not probing for phase segment 2 would leave the possibility that sjw is larger than segment 2.
if (!timing->sjw) {
timing->sjw = timing->phase_seg2;
}
else {
timing->sjw = MIN(timing->sjw, timing->phase_seg2);
}
timing->sjw = MIN(timing->sjw, timing->phase_seg1);
timing->sjw = MIN(timing->sjw, timing_const->sjw_max);There was a problem hiding this comment.
Thanks for the review.
I simplified it a bit further ( also including the no known max default) but avoid including some MIN definition and kept the comments
eef9a2a to
a40a442
Compare
sys/can/device.c
Outdated
| } | ||
|
|
||
| if (timing->sjw > timing->phase_seg2) { | ||
| /* SJW shall not be bigger than phase segment 1 */ |
There was a problem hiding this comment.
| /* SJW shall not be bigger than phase segment 1 */ | |
| /* SJW shall not be bigger than phase segment 2 */ |
b46113b to
9e91dab
Compare
Teufelchen1
left a comment
There was a problem hiding this comment.
I did not test it but you did, right @kfessel? If so, here is the ACK.
|
Prove of Test Debug enable in device tests/drivers/candev/ BOARD=same54-xpro without sjw improvment with sjw improvment added line break to term for readability |
Contribution description
SJW was defaulting to 2 -> good for 8MHz time quanta bad for higher clock
With this PR:
This should usually end up with SJW being the same as phase 2 for can configuration having the sample point at 87.5%) ->
it's starting at value of phase 2 making changes by the following comparisons unlikely.
Testing procedure
read
run can and see improved stability of connection for slightly drifting clocks on either end (less failed frames due to synchronization issues).
Issues/PRs references
http://www.oertel-halle.de/files/cia99paper.pdf might help under standing the sjw value