]> rtime.felk.cvut.cz Git - can-utils.git/commit
can-calc-bit-timing: better sample point calculation
authorMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 13 Apr 2016 09:29:37 +0000 (11:29 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Wed, 13 Apr 2016 11:13:01 +0000 (13:13 +0200)
commit44a2900bd82b2060ed3e2eb3330811af122141d9
treeba0af495f789545e0dc205287f3bb1323e68fbb2
parente36391c7d976a4204f6245f9511dc3d23b7c0af4
can-calc-bit-timing: better sample point calculation

This patch tries to optimize the calculation of the sample point. To
understand what it does have a look at the original implementation.

If there is a combination of timing parameters where both the bitrate
and sample point error are 0 the current implementation will find it.

However if the reference clock doesn't allow an optimal bitrate (this
means the bitrate error is always != 0) there might be several timing
parameter combinations having the same bitrate error. The original
implementation will allways choose the one with the highest brp. The
actual sample point error isn't taken into account.

This patch changes the algorithm to minimize the sample point error,
too. Now a brp/tseg combination is accepted as better if one of these
condition are fulfilled:
1) the bit rate error must be smaller, or
2) the bit rate error must be equal and
   the sample point error must be equal or smaller

If a smaller bit rate error is found the sample point error is reset.
This ensures that we first optimize for small bit rate error and then
for small sample point errors.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
can-calc-bit-timing.c