All of lore.kernel.org
 help / color / mirror / Atom feed
* Possible NULL sample_point in the new way of computing bit-timings
@ 2016-08-09 14:17 Stephane Grosjean
  2016-09-05 12:14 ` Marc Kleine-Budde
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Grosjean @ 2016-08-09 14:17 UTC (permalink / raw)
  To: linux-can

Hi all,

With the new way of computing bit-timings introduced in linux-can-next, 
when CONFIG_CAN_CALC_BITTIMING is defined, I think there's a chance to 
set 0 in "bt->sample_point" of a can device. This is a different 
behavior than with the previous versions.

IMHO, there are cases where "can_update_sample_point()" might return 0 
("best_sample_point" is initialized to 0). There is no real damage in 
the main loop of "can_calc_bittiming()": its returned value is ignored 
(and only *sample_point_error matters). But it is not, outside this 
loop, when setting the (real) value of the sample_point. So I think that 
the real value of the sample_point must be computed using the final 
values of tseg and tseg2, something like:

diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 7188137..de422b3 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -200,8 +200,8 @@ static int can_calc_bittiming(struct net_device 
*dev, struct can_bittiming *bt,
         }

         /* real sample point */
-       bt->sample_point = can_update_sample_point(btc, 
sample_point_nominal, best_tseg,
-                                         &tseg1, &tseg2, NULL);
+       bt->sample_point = 1000 * (best_tseg + CAN_CALC_SYNC_SEG - tseg2) /
+                                       (best_tseg + CAN_CALC_SYNC_SEG);

         v64 = (u64)best_brp * 1000 * 1000 * 1000;
         do_div(v64, priv->clock.freq);

The best would be to introduce a function that implements the formula...

Stéphane

--
PEAK-System Technik GmbH
Sitz der Gesellschaft Darmstadt - HRB 9183 
Geschaeftsfuehrung: A.Gach, U.Wilhelm
--

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-05 12:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-09 14:17 Possible NULL sample_point in the new way of computing bit-timings Stephane Grosjean
2016-09-05 12:14 ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.