Skip to content

Commit b8723c4

Browse files
committed
sys/can: improve SJW calculation
1 parent 90d7b0b commit b8723c4

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

sys/can/device.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,16 +581,23 @@ int can_device_calc_bittiming(uint32_t clock, const struct can_bittiming_const *
581581
timing->phase_seg1 = tseg1 - timing->prop_seg;
582582
timing->phase_seg2 = tseg2;
583583

584-
if (!timing->sjw || !timing_const->sjw_max) {
584+
if (!timing->sjw && !timing_const->sjw_max) {
585+
/* fallback if sjw is unset and no device max value is known */
585586
timing->sjw = SJW;
586587
}
587588
else {
589+
if (!timing->sjw) {
590+
/* SJW shall not be bigger than phase segmet 2*/
591+
timing->sjw = timing->phase_seg2;
592+
}
593+
if (timing->sjw > timing->phase_seg1) {
594+
/* SJW shall not be bigger than phase segmet 1*/
595+
timing->sjw = timing->phase_seg1;
596+
}
588597
if (timing->sjw > timing_const->sjw_max) {
598+
/* SJW shall not be bigger than its max value*/
589599
timing->sjw = timing_const->sjw_max;
590600
}
591-
if (timing->sjw > tseg2) {
592-
timing->sjw = tseg2;
593-
}
594601
}
595602

596603
timing->brp = best_brp;

0 commit comments

Comments
 (0)