From: Marc Kleine-Budde <mkl@pengutronix.de>
To: "Max S." <max@schneidersoft.net>
Cc: "Sebastian Haas" <dev@sebastianhaas.info>,
"Heinz-Jürgen Oertel" <hj.oertel@t-online.de>,
linux-can@vger.kernel.org
Subject: autobaud detection (was: Re: adding can4linux to drivers/char)
Date: Sun, 29 Sep 2013 21:43:27 +0200 [thread overview]
Message-ID: <524882DF.2050604@pengutronix.de> (raw)
In-Reply-To: <1380482622.14050.15.camel@blackbox>
[-- Attachment #1: Type: text/plain, Size: 3136 bytes --]
On 09/29/2013 09:23 PM, Max S. wrote:
> This isn't on topic to this thread...
I've changed the topic :P
> Just thought I'd note:
Thanks.
> On Sun, 2013-09-29 at 20:44 +0200, Marc Kleine-Budde wrote:
>> If there is a need for bitrate detection, feel free request it here. I
>> think there are some controllers that support this in hardware, while
>> others don't. Is there a known working algorithm for bitrate detection?
>
> Most controllers have listen only mode, in which the error counters are
> frozen. It is then possible to systematically try all common bit-rate
> configurations, and listen for good frames. works best when you start
> with high speeds and work your way down. Listen only mode baud sniffing
> will require at least two other nodes (one to send, one to ack..)
This sounds pretty straight forward. This can be implemented as a
userspace library. Pseudo code:
The function get the can interface name as a string, an optional 0
terminated array of bitrates (must be sorted or we sort internally) if
NULL a default array is used, a pointer to an int that will be written
if the bitrate is found and a timeout value in ms. The code waits for X
ms for a good frame to arrive.
int can_autobitrate(const char *interface, const int bitrate_array[],
int *autobitrate, int timeout_ms)
{
struct pollfd fds[1];
int s, ret = 0;
err = can_set_listenonly(interface);
if (err)
return err;
s = socket(interface);
fds[1].fd = s;
fds[1].events = POLLIN;
if (!bitrate_array)
bitrate_array = default_bitrate_array;
for (i = 0; bitrate_array[i]; i++) {
can_ifdown(interface);
can_set_bitrate(interface, bitrate_array[i]);
can_ifup(interface);
/* wait for good frame comming in */
ret = poll(fds, 1, timeout_ms);
if (ret == 1 && fds[1].revents & POLLIN) {
*bitrate = bitrate_array[i];
goto out:
}
proper_error_handling();
}
ret = -1;
out:
close(s);
set_normal_mode(interface);
}
> Some controllers also have a mode similar to listen only, but that also
> internally connect the TX signal to the RX signal. this way you only
> need 1 other node to send non acked frames. the autobauding node will
> then ack those frames for itself only. Atmel calls this mode LOOPBACK...
> even though its not a typical "LOOPBACK".
This new mode can be easily added to the other control mode, we just
have to define a proper name.
> Additionally when using micros with on-board CAN controllers the RX pin
> can be temporarily reprogrammed to an input. With a pin change interrupt
> and a timer it is then possible to measure the TQ used by other nodes.
Nice, with modern Device Tree based Kernels that is also possible. You
can describe alternative pinmux settings for a device in a hardware
independent way.
Marc
--
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 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]
next prev parent reply other threads:[~2013-09-29 20:00 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-20 23:03 adding can4linux to drivers/char Heinz-Jürgen Oertel
2013-09-21 9:17 ` Oliver Hartkopp
2013-09-21 19:57 ` Wolfgang Grandegger
2013-09-21 13:38 ` Marc Kleine-Budde
2013-09-21 16:37 ` Sebastian Haas
2013-09-21 17:09 ` Marc Kleine-Budde
2013-09-21 18:17 ` Oliver Hartkopp
[not found] ` <CADGMhsXaJOpbdCgEAoOguZWX2rS_P0a-H5UDZwUWiHD4Nj=upw@mail.gmail.com>
2013-09-22 10:40 ` Marc Kleine-Budde
2013-09-22 11:01 ` Oliver Hartkopp
2013-09-23 13:46 ` Marc Kleine-Budde
2013-09-21 19:55 ` Wolfgang Grandegger
2013-09-29 16:28 ` Heinz-Jürgen Oertel
2013-09-29 17:44 ` Marc Kleine-Budde
2013-09-29 17:45 ` Sebastian Haas
2013-09-29 18:44 ` Marc Kleine-Budde
2013-09-29 19:23 ` Max S.
2013-09-29 19:17 ` Heinz-Jürgen Oertel
2013-09-29 19:43 ` Marc Kleine-Budde [this message]
2013-09-30 7:30 ` Sebastian Haas
2013-09-30 10:20 ` Kurt Van Dijck
2013-09-29 19:23 ` Heinz-Jürgen Oertel
2013-09-30 9:35 ` Oliver Hartkopp
2013-10-01 20:20 ` AW: " May, Stefan
2013-10-02 7:49 ` Oliver Hartkopp
2013-10-02 8:43 ` Linux CAN CUSE hacks, SocketCAN and RT Was: " Pavel Pisa
2013-10-02 9:47 ` Wolfgang Grandegger
2013-09-29 19:41 ` Wolfgang Grandegger
2013-09-30 7:40 ` Sebastian Haas
2013-09-30 8:21 ` Wolfgang Grandegger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=524882DF.2050604@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=dev@sebastianhaas.info \
--cc=hj.oertel@t-online.de \
--cc=linux-can@vger.kernel.org \
--cc=max@schneidersoft.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).