File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -581,18 +581,25 @@ 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 ) {
585- timing -> sjw = SJW ;
586- }
587- else {
588- if (timing -> sjw > timing_const -> sjw_max ) {
589- timing -> sjw = timing_const -> sjw_max ;
584+ /* this paper http://www.oertel-halle.de/files/cia99paper.pdf might help to understand SJW */
585+ if (!timing -> sjw ) {
586+ if (!timing_const -> sjw_max ) {
587+ /* fallback if no device max value is known */
588+ timing -> sjw = SJW ;
590589 }
591- if (timing -> sjw > tseg2 ) {
592- timing -> sjw = tseg2 ;
590+ else {
591+ /* try to find the max_value start at max */
592+ timing -> sjw = timing_const -> sjw_max ;
593593 }
594594 }
595-
595+ if (timing -> sjw > timing -> phase_seg2 ) {
596+ /* SJW shall not be bigger than phase segment 1 */
597+ timing -> sjw = timing -> phase_seg2 ;
598+ }
599+ if (timing -> sjw > timing -> phase_seg1 ) {
600+ /* SJW shall not be bigger than phase segment 1 */
601+ timing -> sjw = timing -> phase_seg1 ;
602+ }
596603 timing -> brp = best_brp ;
597604
598605 timing -> bitrate = clock / (timing -> brp * (CAN_SYNC_SEG + tseg1 + tseg2 ));
You can’t perform that action at this time.
0 commit comments