]> 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)
commit33025b74e6880e58c16bdd5a07f692807ea3190f
tree6022ba055fe32cfc046491cae990f85c0b49596d
parent8a3f6beeacec4f9e695adbbea662efd386993b57
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