Re: [PATCH] socket-can: bit-timing calculation
From: realmz paranoid
Date: Tue Jan 17 2012 - 23:45:27 EST
Hi Marc,
On Tue, Jan 17, 2012 at 10:34 PM, Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx> wrote:
> Hello,
>
> Realmz Paranoid, a hint from David Miller:
>> Nobody is seeing any of your postings because of "open list: NETWORKING
>> DRIVERS" stuff in the email headers.
>
> On 01/17/2012 11:25 AM, Marc Kleine-Budde wrote:
>> On 01/17/2012 11:18 AM, realmz paranoid wrote:
>> [...]
>>
>>>>>> This is worse because it does not find the best match. The first
>>>>>> match might not be the best.
>>>>>>
>>>>>> I got it, because the tseg1_max and tseg2_max limit, the first found
>>>> best
>>>>> error will not get the best sample point on some hardware.
>>>>> So I'd tweak the blackfin can code.
>>>>
>>>> The algorithm does *not* work well for all configs, especially when the
>>>> clock frequency is not a multiple of 8 MHz. Instead of tweaking the
>>>> algorithm just for your hardware it does make more sense to provide the
>>>> parameters manually using "tq= ...". Also setting "sjw > 1" helps if the
>>>> bit-timing is not optimal.
>>
>> I've an improved version (somewhere) that minimizes sample point error,
>> too. Give me some minutes to find it.
>
> Here it is. Wolfgang wrote the can-calc-bit-timing tool, which he used to generate
> the table in the other mail. It's part of can-utils. I've pushed my improvement
> to my repo (better-bitrate-calculation branch):
>
> https://gitorious.org/~bet-frogger/linux-can/mkl-can-utils
>
> Here's the patch:
>
> From 4df04420f128ec326e536fe55fc819b893a5c9ef Mon Sep 17 00:00:00 2001
> From: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> Date: Sat, 15 May 2010 18:26:03 +0200
> Subject: [PATCH] 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 has a pretty
> good change of finding it (maybe it will always do, but I'm to lazy
> to proof this).
>
> 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.
>
> The following diff shows the sample point error improvements.
>
> --- orig.txt  Â2010-05-17 00:10:21.000000000 +0200
> +++ new.txt   2010-05-17 00:10:05.000000000 +0200
> @@ -27,9 +27,9 @@
> ÂBit timing parameters for mscan with 33.000000 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error BTR0 BTR1
> Â1000000 Â Â 90 Â 3 Â Â4 Â Â3 Â 1 Â 3 1000000 Â0.0% 75.0% 72.7% Â3.1% 0x02 0x26
> - 800000 Â Â181 Â 2 Â Â2 Â Â2 Â 1 Â 6 Â785714 Â1.8% 80.0% 71.4% 10.8% 0x05 0x13
> + 800000 Â Â 90 Â 5 Â Â5 Â Â3 Â 1 Â 3 Â785714 Â1.8% 80.0% 78.5% Â1.9% 0x02 0x29
> Â500000 Â Â181 Â 4 Â Â4 Â Â2 Â 1 Â 6 Â500000 Â0.0% 87.5% 81.8% Â6.5% 0x05 0x17
> Â250000 Â Â333 Â 4 Â Â5 Â Â2 Â 1 Â11 Â250000 Â0.0% 87.5% 83.3% Â4.8% 0x0a 0x18
> Â125000 Â Â666 Â 4 Â Â5 Â Â2 Â 1 Â22 Â125000 Â0.0% 87.5% 83.3% Â4.8% 0x15 0x18
> Â100000 Â Â666 Â 6 Â Â6 Â Â2 Â 1 Â22 Â100000 Â0.0% 87.5% 86.6% Â1.0% 0x15 0x1b
> @@ -40,12 +40,12 @@
> ÂBit timing parameters for mscan with 33.300000 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error BTR0 BTR1
> Â1000000 Â Â 90 Â 3 Â Â4 Â Â3 Â 1 Â 3 1009090 Â0.9% 75.0% 72.7% Â3.1% 0x02 0x26
> - 800000 Â Â180 Â 2 Â Â2 Â Â2 Â 1 Â 6 Â792857 Â0.9% 80.0% 71.4% 10.8% 0x05 0x13
> + 800000 Â Â 90 Â 5 Â Â5 Â Â3 Â 1 Â 3 Â792857 Â0.9% 80.0% 78.5% Â1.9% 0x02 0x29
> Â500000 Â Â180 Â 4 Â Â4 Â Â2 Â 1 Â 6 Â504545 Â0.9% 87.5% 81.8% Â6.5% 0x05 0x17
> - 250000 Â Â570 Â 2 Â Â2 Â Â2 Â 1 Â19 Â250375 Â0.1% 87.5% 71.4% 18.4% 0x12 0x13
> - 125000 Â 1141 Â 2 Â Â2 Â Â2 Â 1 Â38 Â125187 Â0.1% 87.5% 71.4% 18.4% 0x25 0x13
> + 250000 Â Â210 Â 7 Â Â8 Â Â3 Â 1 Â 7 Â250375 Â0.1% 87.5% 84.2% Â3.8% 0x06 0x2e
> + 125000 Â Â570 Â 5 Â Â6 Â Â2 Â 1 Â19 Â125187 Â0.1% 87.5% 85.7% Â2.1% 0x12 0x1a
> Â100000 Â 1111 Â 3 Â Â3 Â Â2 Â 1 Â37 Â100000 Â0.0% 87.5% 77.7% 11.2% 0x24 0x15
> Â 50000 Â 1111 Â 7 Â Â7 Â Â3 Â 1 Â37 Â 50000 Â0.0% 87.5% 83.3% Â4.8% 0x24 0x2d
> Â 20000 ***bitrate not possible***
> Â 10000 ***bitrate not possible***
> @@ -53,12 +53,12 @@
> ÂBit timing parameters for mscan with 33.333333 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error BTR0 BTR1
> Â1000000 Â Â 90 Â 3 Â Â4 Â Â3 Â 1 Â 3 1010101 Â1.0% 75.0% 72.7% Â3.1% 0x02 0x26
> - 800000 Â Â180 Â 2 Â Â2 Â Â2 Â 1 Â 6 Â793650 Â0.8% 80.0% 71.4% 10.8% 0x05 0x13
> + 800000 Â Â 90 Â 5 Â Â5 Â Â3 Â 1 Â 3 Â793650 Â0.8% 80.0% 78.5% Â1.9% 0x02 0x29
> Â500000 Â Â180 Â 4 Â Â4 Â Â2 Â 1 Â 6 Â505050 Â1.0% 87.5% 81.8% Â6.5% 0x05 0x17
> - 250000 Â Â570 Â 2 Â Â2 Â Â2 Â 1 Â19 Â250626 Â0.3% 87.5% 71.4% 18.4% 0x12 0x13
> - 125000 Â 1140 Â 2 Â Â2 Â Â2 Â 1 Â38 Â125313 Â0.3% 87.5% 71.4% 18.4% 0x25 0x13
> + 250000 Â Â210 Â 7 Â Â8 Â Â3 Â 1 Â 7 Â250626 Â0.3% 87.5% 84.2% Â3.8% 0x06 0x2e
> + 125000 Â Â570 Â 5 Â Â6 Â Â2 Â 1 Â19 Â125313 Â0.3% 87.5% 85.7% Â2.1% 0x12 0x1a
> Â100000 Â 1110 Â 3 Â Â3 Â Â2 Â 1 Â37 Â100100 Â0.1% 87.5% 77.7% 11.2% 0x24 0x15
> Â 50000 Â Â870 Â 8 Â Â8 Â Â6 Â 1 Â29 Â 49975 Â0.1% 87.5% 73.9% 15.5% 0x1c 0x5f
> Â 20000 ***bitrate not possible***
> Â 10000 ***bitrate not possible***
> @@ -78,12 +78,12 @@
>
> ÂBit timing parameters for at91 with 99.532800 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error   CAN_BR
> -1000000 Â Â100 Â 3 Â Â3 Â Â3 Â 1 Â10 Â995328 Â0.5% 75.0% 70.0% Â6.7% 0x00090222
> +1000000 Â Â 50 Â 7 Â Â7 Â Â5 Â 1 Â 5 Â995328 Â0.5% 75.0% 75.0% Â0.0% 0x00040664
> Â800000 Â Â 50 Â 8 Â Â8 Â Â8 Â 1 Â 5 Â796262 Â0.5% 80.0% 68.0% 15.0% 0x00040777
> - 500000 Â Â251 Â 2 Â Â3 Â Â2 Â 1 Â25 Â497664 Â0.5% 87.5% 75.0% 14.3% 0x00180121
> - 250000 Â Â572 Â 2 Â Â2 Â Â2 Â 1 Â57 Â249455 Â0.2% 87.5% 71.4% 18.4% 0x00380111
> + 500000 Â Â100 Â 8 Â Â8 Â Â3 Â 1 Â10 Â497664 Â0.5% 87.5% 85.0% Â2.9% 0x00090772
> + 250000 Â Â210 Â 7 Â Â8 Â Â3 Â 1 Â21 Â249455 Â0.2% 87.5% 84.2% Â3.8% 0x00140672
> Â125000 Â Â532 Â 6 Â Â6 Â Â2 Â 1 Â53 Â125198 Â0.2% 87.5% 86.6% Â1.0% 0x00340551
> Â100000 Â Â833 Â 4 Â Â5 Â Â2 Â 1 Â83 Â 99932 Â0.1% 87.5% 83.3% Â4.8% 0x00520341
> Â 50000 Â Â833 Â 8 Â Â8 Â Â7 Â 1 Â83 Â 49966 Â0.1% 87.5% 70.8% 19.1% 0x00520776
> Â 20000 ***bitrate not possible***
> @@ -92,22 +92,22 @@
> ÂBit timing parameters for flexcan with 49.875000 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error  CAN_CTRL
> Â1000000 Â Â100 Â 3 Â Â3 Â Â3 Â 1 Â 5 Â997500 Â0.2% 75.0% 70.0% Â6.7% 0x04120002
> - 800000 Â Â180 Â 2 Â Â2 Â Â2 Â 1 Â 9 Â791666 Â1.0% 80.0% 71.4% 10.8% 0x08090001
> - 500000 Â Â200 Â 3 Â Â4 Â Â2 Â 1 Â10 Â498750 Â0.2% 87.5% 80.0% Â8.6% 0x09190002
> - 250000 Â Â501 Â 2 Â Â3 Â Â2 Â 1 Â25 Â249375 Â0.2% 87.5% 75.0% 14.3% 0x18110001
> + 800000 Â Â140 Â 3 Â Â3 Â Â2 Â 1 Â 7 Â791666 Â1.0% 80.0% 77.7% Â2.9% 0x06110002
> + 500000 Â Â100 Â 8 Â Â8 Â Â3 Â 1 Â 5 Â498750 Â0.2% 87.5% 85.0% Â2.9% 0x043a0007
> + 250000 Â Â200 Â 8 Â Â8 Â Â3 Â 1 Â10 Â249375 Â0.2% 87.5% 85.0% Â2.9% 0x093a0007
> Â125000 Â Â421 Â 7 Â Â8 Â Â3 Â 1 Â21 Â125000 Â0.0% 87.5% 84.2% Â3.8% 0x143a0006
> - 100000 Â 1002 Â 3 Â Â4 Â Â2 Â 1 Â50 Â 99750 Â0.2% 87.5% 80.0% Â8.6% 0x31190002
> + 100000 Â Â501 Â 8 Â Â8 Â Â3 Â 1 Â25 Â 99750 Â0.2% 87.5% 85.0% Â2.9% 0x183a0007
> Â 50000 Â 1664 Â 4 Â Â5 Â Â2 Â 1 Â83 Â 50075 Â0.1% 87.5% 83.3% Â4.8% 0x52210003
> Â 20000 Â 3568 Â 5 Â Â6 Â Â2 Â 1 178 Â 20014 Â0.1% 87.5% 85.7% Â2.1% 0xb1290004
> Â 10000 Â 4350 Â 8 Â Â8 Â Â6 Â 1 217 Â Â9992 Â0.1% 87.5% 73.9% 15.5% 0xd83d0007
>
> ÂBit timing parameters for flexcan with 66.500000 MHz ref clock
> Ânominal                 real Bitrt  nom Âreal SampP
> ÂBitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error  CAN_CTRL
> Â1000000 Â Â 90 Â 3 Â Â4 Â Â3 Â 1 Â 6 1007575 Â0.8% 75.0% 72.7% Â3.1% 0x051a0002
> - 800000 Â Â180 Â 2 Â Â2 Â Â2 Â 1 Â12 Â791666 Â1.0% 80.0% 71.4% 10.8% 0x0b090001
> + 800000 Â Â 90 Â 5 Â Â5 Â Â3 Â 1 Â 6 Â791666 Â1.0% 80.0% 78.5% Â1.9% 0x05220004
> Â500000 Â Â105 Â 7 Â Â8 Â Â3 Â 1 Â 7 Â500000 Â0.0% 87.5% 84.2% Â3.8% 0x063a0006
> Â250000 Â Â285 Â 5 Â Â6 Â Â2 Â 1 Â19 Â250000 Â0.0% 87.5% 85.7% Â2.1% 0x12290004
> Â125000 Â Â571 Â 5 Â Â6 Â Â2 Â 1 Â38 Â125000 Â0.0% 87.5% 85.7% Â2.1% 0x25290004
> Â100000 Â Â526 Â 7 Â Â8 Â Â3 Â 1 Â35 Â100000 Â0.0% 87.5% 84.2% Â3.8% 0x223a0006
>
> Signed-off-by: Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> ---
> Âcan-calc-bit-timing.c | Â 71 +++++++++++++++++++++++++++----------------------
> Â1 files changed, 39 insertions(+), 32 deletions(-)
>
> diff --git a/can-calc-bit-timing.c b/can-calc-bit-timing.c
> index f8c04ba..27bf41d 100644
> --- a/can-calc-bit-timing.c
> +++ b/can-calc-bit-timing.c
> @@ -1,6 +1,7 @@
> Â/* can-calc-bit-timing.c: Calculate CAN bit timing parameters
> Â*
> Â* Copyright (C) 2008 Wolfgang Grandegger <wg@xxxxxxxxxxxxxx>
> + * Copyright (C) 2010 Marc Kleine-Budde <mkl@xxxxxxxxxxxxxx>
> Â*
> Â* Derived from:
> Â* Â can_baud.c - CAN baudrate calculation
> @@ -372,18 +373,17 @@ static long common_bitrates[] = {
> Â#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
> Âstatic int can_update_spt(const struct can_bittiming_const *btc,
> - Â Â Â Â Â Â Â Â Â Â Â Â int sampl_pt, int tseg, int *tseg1, int *tseg2)
> + Â Â Â Â Â Â Â unsigned int sampl_pt, unsigned int tseg,
> + Â Â Â Â Â Â Â unsigned int *tseg1, unsigned int *tseg2)
> Â{
> Â Â Â Â*tseg2 = tseg + 1 - (sampl_pt * (tseg + 1)) / 1000;
> - Â Â Â if (*tseg2 < btc->tseg2_min)
> - Â Â Â Â Â Â Â *tseg2 = btc->tseg2_min;
> - Â Â Â if (*tseg2 > btc->tseg2_max)
> - Â Â Â Â Â Â Â *tseg2 = btc->tseg2_max;
> + Â Â Â *tseg2 = clamp(*tseg2, btc->tseg2_min, btc->tseg2_max);
> Â Â Â Â*tseg1 = tseg - *tseg2;
> Â Â Â Âif (*tseg1 > btc->tseg1_max) {
> Â Â Â Â Â Â Â Â*tseg1 = btc->tseg1_max;
> Â Â Â Â Â Â Â Â*tseg2 = tseg - *tseg1;
> Â Â Â Â}
> +
> Â Â Â Âreturn 1000 * (tseg + 1 - *tseg2) / (tseg + 1);
> Â}
> Â@@ -391,11 +391,15 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
> Â{
> Â Â Â Âstruct can_priv *priv = netdev_priv(dev);
> Â Â Â Âconst struct can_bittiming_const *btc = priv->bittiming_const;
> - Â Â Â long rate, best_rate = 0;
> - Â Â Â long best_error = 1000000000, error = 0;
> - Â Â Â int best_tseg = 0, best_brp = 0, brp = 0;
> - Â Â Â int tsegall, tseg = 0, tseg1 = 0, tseg2 = 0;
> - Â Â Â int spt_error = 1000, spt = 0, sampl_pt;
> + Â Â Â long rate; Â Â Â Â Â Â Â/* current bitrate */
> + Â Â Â long rate_error; Â Â Â Â/* difference between current and target value */
> + Â Â Â long best_rate_error = 1000000000;
> + Â Â Â int spt; Â Â Â Â Â Â Â Â/* current sample point in thousandth */
> + Â Â Â int spt_error; Â Â Â Â Â/* difference between current and target value */
> + Â Â Â int best_spt_error = 1000;
> + Â Â Â int sampl_pt; Â Â Â Â Â /* target sample point */
> + Â Â Â int best_tseg = 0, best_brp = 0; Â Â Â Â/* current best values for tseg and brp */
> + Â Â Â unsigned int brp, tsegall, tseg, tseg1, tseg2;
> Â Â Â Âu64 v64;
> Â Â Â Âif (!priv->bittiming_const)
> @@ -417,48 +421,51 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
> Â Â Â Âfor (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
> Â Â Â Â Â Â tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) {
> Â Â Â Â Â Â Â Âtsegall = 1 + tseg / 2;
> +
> Â Â Â Â Â Â Â Â/* Compute all possible tseg choices (tseg=tseg1+tseg2) */
> Â Â Â Â Â Â Â Âbrp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2;
> +
> Â Â Â Â Â Â Â Â/* chose brp step which is possible in system */
> Â Â Â Â Â Â Â Âbrp = (brp / btc->brp_inc) * btc->brp_inc;
> Â Â Â Â Â Â Â Âif ((brp < btc->brp_min) || (brp > btc->brp_max))
> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
> +
> Â Â Â Â Â Â Â Ârate = priv->clock.freq / (brp * tsegall);
> - Â Â Â Â Â Â Â error = bt->bitrate - rate;
> + Â Â Â Â Â Â Â rate_error = abs((long)(bt->bitrate - rate));
> +
> Â Â Â Â Â Â Â Â/* tseg brp biterror */
> - Â Â Â Â Â Â Â if (error < 0)
> - Â Â Â Â Â Â Â Â Â Â Â error = -error;
> - Â Â Â Â Â Â Â if (error > best_error)
> + Â Â Â Â Â Â Â if (rate_error > best_rate_error)
> Â Â Â Â Â Â Â Â Â Â Â Âcontinue;
> - Â Â Â Â Â Â Â best_error = error;
> - Â Â Â Â Â Â Â if (error == 0) {
> - Â Â Â Â Â Â Â Â Â Â Â spt = can_update_spt(btc, sampl_pt, tseg / 2,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â&tseg1, &tseg2);
> - Â Â Â Â Â Â Â Â Â Â Â error = sampl_pt - spt;
> - Â Â Â Â Â Â Â Â Â Â Â if (error < 0)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â error = -error;
> - Â Â Â Â Â Â Â Â Â Â Â if (error > spt_error)
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
> - Â Â Â Â Â Â Â Â Â Â Â spt_error = error;
> - Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /* reset sample point error if we have a better bitrate */
> + Â Â Â Â Â Â Â if (rate_error < best_rate_error)
> + Â Â Â Â Â Â Â Â Â Â Â best_spt_error = 1000;
> +
> + Â Â Â Â Â Â Â spt = can_update_spt(btc, sampl_pt, tseg / 2, &tseg1, &tseg2);
> + Â Â Â Â Â Â Â spt_error = abs((long)(sampl_pt - spt));
> + Â Â Â Â Â Â Â if (spt_error > best_spt_error)
> + Â Â Â Â Â Â Â Â Â Â Â continue;
> +
> + Â Â Â Â Â Â Â best_spt_error = spt_error;
> + Â Â Â Â Â Â Â best_rate_error = rate_error;
> Â Â Â Â Â Â Â Âbest_tseg = tseg / 2;
> Â Â Â Â Â Â Â Âbest_brp = brp;
> - Â Â Â Â Â Â Â best_rate = rate;
> - Â Â Â Â Â Â Â if (error == 0)
> +
> + Â Â Â Â Â Â Â if (rate_error == 0 && spt_error == 0)
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
> Â Â Â Â}
> Â- Â Â Âif (best_error) {
> + Â Â Â if (best_rate_error) {
> Â Â Â Â Â Â Â Â/* Error in one-tenth of a percent */
> - Â Â Â Â Â Â Â error = (best_error * 1000) / bt->bitrate;
> - Â Â Â Â Â Â Â if (error > CAN_CALC_MAX_ERROR) {
> + Â Â Â Â Â Â Â rate_error = (best_rate_error * 1000) / bt->bitrate;
> + Â Â Â Â Â Â Â if (rate_error > CAN_CALC_MAX_ERROR) {
> Â Â Â Â Â Â Â Â Â Â Â Âdev_err(dev->dev.parent,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"bitrate error %ld.%ld%% too high\n",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â error / 10, error % 10);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rate_error / 10, rate_error % 10);
> Â Â Â Â Â Â Â Â Â Â Â Âreturn -EDOM;
> Â Â Â Â Â Â Â Â} else {
> Â Â Â Â Â Â Â Â Â Â Â Âdev_warn(dev->dev.parent, "bitrate error %ld.%ld%%\n",
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âerror / 10, error % 10);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Ârate_error / 10, rate_error % 10);
> Â Â Â Â Â Â Â Â}
> Â Â Â Â}
> Â-- 1.7.4.1
>
I added bfin-can to can-calc-bit-timing.c and tried with your
better-bitrate-calculation branch, it did improve the sample error.
Thank you.
Here's the result:
Bit timing parameters for bfin-can with 131.250000 MHz ref clock
nominal real Bitrt nom real SampP
Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error CAN_CTRL
1000000 251 1 1 1 1 33 994318 0.6% 75.0% 75.0% 0.0%
clock 0x00000020 timing 0x00000001
800000 312 1 1 1 1 41 800304 0.0% 80.0% 75.0% 6.2%
clock 0x00000028 timing 0x00000001
- 500000 502 1 1 1 1 66 497159 0.6% 87.5% 75.0% 14.3%
clock 0x00000041 timing 0x00000001
+ 500000 251 3 3 1 1 33 497159 0.6% 87.5% 87.5% 0.0%
clock 0x00000020 timing 0x00000005
250000 266 6 6 2 1 35 250000 0.0% 87.5% 86.6% 1.0%
clock 0x00000022 timing 0x0000001b
125000 533 6 6 2 1 70 125000 0.0% 87.5% 86.6% 1.0%
clock 0x00000045 timing 0x0000001b
- 100000 2499 1 1 1 1 328 100038 0.0% 87.5% 75.0% 14.3%
clock 0x00000147 timing 0x00000001
+ 100000 1249 3 3 1 1 164 100038 0.0% 87.5% 87.5% 0.0%
clock 0x000000a3 timing 0x00000005
50000 1333 6 6 2 1 175 50000 0.0% 87.5% 86.6% 1.0%
clock 0x000000ae timing 0x0000001b
20000 2940 6 7 3 1 386 20001 0.0% 87.5% 82.3% 5.9%
clock 0x00000181 timing 0x0000002c
10000 6666 6 6 2 1 875 10000 0.0% 87.5% 86.6% 1.0%
clock 0x0000036a timing 0x0000001b
@@ -15,7 +15,7 @@
Bit timing parameters for bfin-can with 125.000000 MHz ref clock
nominal real Bitrt nom real SampP
Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error CAN_CTRL
1000000 40 8 8 8 1 5 1000000 0.0% 75.0% 68.0% 9.3%
clock 0x00000004 timing 0x0000007f
- 800000 312 1 1 1 1 39 801282 0.2% 80.0% 75.0% 6.2%
clock 0x00000026 timing 0x00000001
+ 800000 96 4 5 3 1 12 801282 0.2% 80.0% 76.9% 3.9%
clock 0x0000000b timing 0x00000028
500000 400 1 2 1 1 50 500000 0.0% 87.5% 80.0% 8.6%
clock 0x00000031 timing 0x00000002
250000 200 8 8 3 1 25 250000 0.0% 87.5% 85.0% 2.9%
clock 0x00000018 timing 0x0000002f
125000 1000 3 3 1 1 125 125000 0.0% 87.5% 87.5% 0.0%
clock 0x0000007c timing 0x00000005
-steven
> --
> Pengutronix e.K.         Â| Marc Kleine-Budde      |
> Industrial Linux Solutions    Â| Phone: +49-231-2826-924   |
> Vertretung West/Dortmund     Â| Fax:  +49-5121-206917-5555 |
> Amtsgericht Hildesheim, HRA 2686 Â| http://www.pengutronix.de  |
>
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/