I am struggling with the CAN bit-timing. I implemented an SJA1000 driver on top of the SJA1000 kernel module which comes with Linux 2.6.31. So far it seems to work except that the bitrate is off by factor two, i.e. a
# ip link set can0 type can bitrate 250000 makes my CAN run at 125kBit/s. While it is easy to work around this problem by simply providing half the real clock frequency to the struct sja1000_priv, I was trying to figure out where and why things go wrong. After reading through the kernel/driver sources, the CAN sources (Verilog), the SJA1000 spec as well as the Bosch CAN spec, I got stuck at following point: In linux/can/netlink.h I have: > /* > * CAN bit-timing parameters > * > * For futher information, please read chapter "8 BIT TIMING > * REQUIREMENTS" of the "Bosch CAN Specification version 2.0" > * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf. > */ > struct can_bittiming { > __u32 bitrate; /* Bit-rate in bits/second */ > __u32 sample_point; /* Sample point in one-tenth of a percent */ > __u32 tq; /* Time quanta (TQ) in nanoseconds */ > __u32 prop_seg; /* Propagation segment in TQs */ > __u32 phase_seg1; /* Phase buffer segment 1 in TQs */ > __u32 phase_seg2; /* Phase buffer segment 2 in TQs */ > __u32 sjw; /* Synchronisation jump width in TQs */ > __u32 brp; /* Bit-rate prescaler */ > }; What is the exact meaning of the brp field? Looking at drivers/net/can/dev.c, > static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt) > { > u64 v64; > [...] > v64 = (u64)best_brp * 1000000000UL; > do_div(v64, priv->clock.freq); > bt->tq = (u32)v64; > [...] > bt->brp = best_brp; > /* real bit-rate */ > bt->bitrate = priv->clock.freq / (bt->brp * (tseg1 + tseg2 + 1)); it seems the meaning of brp=n is "one time quanta is n clock cycles". However, looking at drivers/net/can/sja1000/sja1000.c: > static int sja1000_set_bittiming(struct net_device *dev) > { > struct sja1000_priv *priv = netdev_priv(dev); > struct can_bittiming *bt = &priv->can.bittiming; > u8 btr0, btr1; > > btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6); > > [...] > > priv->write_reg(priv, REG_BTR0, btr0); the brp value (minus one) is written into the SJA's Baud Rate Prescaler (BTR0[5:0]). According my SJA1000 spec t_scl = 2 * t_clk * (BRP + 1) Where t_scl is the time quanta and t_clk the clock period. So BRP=n means "one time quanta is 2*(n+1) clock cycles". So wouldn't btr0 = ((bt->brp/2 - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6); and static struct can_bittiming_const sja1000_bittiming_const = { [...] .brp_min = 2, .brp_inc = 2, [...] be more correct? Thorsten -- Es gelten unsere Allgemeinen Leistungsbedingungen die unter http://www.msc-ge.com/alb abrufbar sind. Our standard terms and conditions apply which are available under http://www.msc-ge.com/alb . MSC Vertriebs GmbH Sitz der Gesellschaft: Stutensee Handelsregister: Mannheim, HRB Nr. 10 3631 Geschaftsfuhrung: Manfred Schwarztrauber, Lothar Kummerlin, Rudiger Kuhn, Silvano Geissler Umsatzsteuer ID Nr.: DE 143 585 507 WEEE Reg. Nr. : DE 31011852 Gleichmann & Co. Electronics GmbH Sitz der Gesellschaft: Frankenthal Handelsregister: Ludwigshafen, HRB Nr. 21305 Geschaftsfuhrung: Manfred Schwarztrauber, Thomas Klein Umsatzsteuer ID Nr. : DE 148 421 329 WEEE Reg. Nr.: DE 72277043 Diese E-Mail enthalt vertrauliche und/ oder rechtlich geschutzte Informationen. Wenn Sie nicht der beabsichtigte Empfanger sind, informieren Sie bitte sofort den Absender und loschen Sie diese E-Mail. The information contained in this message is confidential and/ or protected by law. If you are not the intended recipient, please contact the sender and delete this message.
<<attachment: ew2010_Logo_4c_deutsch.jpg>>
_______________________________________________ Socketcan-core mailing list [email protected] https://lists.berlios.de/mailman/listinfo/socketcan-core
