]> git.baikalelectronics.ru Git - kernel.git/commit
can: dev: can-calc-bit-timing(): better sample point calculation
authorMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 9 May 2016 12:13:06 +0000 (14:13 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Fri, 17 Jun 2016 13:39:42 +0000 (15:39 +0200)
commitd0fe53f0b09d03c964c63d4c1500f7495f59e434
tree6022ba055fe32cfc046491cae990f85c0b49596d
parent90b3970dee39ef296e02986eb369ee8f794bf7bf
can: dev: can-calc-bit-timing(): better sample point calculation

This patch optimizes 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>
drivers/net/can/dev.c