Linux CAN drivers development
 help / color / mirror / Atom feed
From: "Heinz-Jürgen Oertel" <oe@emtas.de>
To: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Cc: Ratheendran <ba.rsrajeshwaran@tataelxsi.co.in>,
	John Whitmore <arigead@gmail.com>,
	linux-can@vger.kernel.org
Subject: Re: detect auto baud rate on can bus in linux driver.
Date: Tue, 29 Apr 2014 14:47:19 +0200	[thread overview]
Message-ID: <21197917.OgRarI4yV7@laura> (raw)
In-Reply-To: <20140427180135.GB21176@vandijck-laurijssen.be>

[-- Attachment #1: Type: text/plain, Size: 1703 bytes --]

Am Sonntag, 27. April 2014, 20:01:35 schrieb Kurt Van Dijck:
> 
> Autobaud is, IMO, a userspace thing.
> The principle has been explained, and with iproute2 & candump piping into
> grep or wc, you could even make a shell script for that.


In can4linux it can be done in user space, like

int do_autobaud(can_fd)
{
int bitrate[] = {10, 20,  50, 125, 250, 500, 800, 1000 , 0};
int i;
int ret;
can_statuspar_t status;

	printf("\tswitch into listen only mode\n"); 
	set_lomode(can_fd, 1);
	/* for all possible bit rates */
	for (i = 0; ; i++) {
		if (bitrate[i] == 0) {
			ret = 0;
			break;
		}
		printf("\tTry %d Kbit/s\n", bitrate[i]);
		set_bitrate(can_fd, bitrate[i]);
		/* wait one second */
		sleep(1);
		ioctl(can_fd, CAN_IOCTL_STATUS, &status);
		/* printf("Rx buffer: %d\n", status.rx_buffer_used); */
		if (status.rx_buffer_used > 1) {
			printf("\t\tCould receive frames. Switch back to 
active mode\n");
			ret = bitrate[i];
			break;
		}
	}
	if (ret > 0) {
		/* bit rate detected */
		set_lomode(can_fd, 0);
	}
	return ret;
}


Of course the CAN controller should have a 'listen only' mode.

On a running EnergyBus it looks like:

using CAN device /dev/can1
doing auto bit rate detection now
take care that traffic is on the bus
        switch into listen only mode
        Try 10 Kbit/s
        Try 20 Kbit/s
        Try 50 Kbit/s
        Try 125 Kbit/s
        Try 250 Kbit/s
                Could receive frames. Switch back to active mode




-- 

Mit freundlichen Grüßen

    Heinz-Jürgen Oertel

-------------------------------------------------------------------------

emtas - your embedded solution partner
 

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

  parent reply	other threads:[~2014-04-29 12:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-24 13:20 detect auto baud rate on can bus in linux driver Ratheendran
2014-04-27  9:44 ` John Whitmore
2014-04-27 18:01   ` Kurt Van Dijck
2014-04-29  8:33     ` Ratheendran S. Rajeshwaran
2014-04-29  8:35       ` Ratheendran S. Rajeshwaran
2014-04-29 19:58       ` Robert Schwebel
     [not found]         ` <5360E8A6.8040204@tataelxsi.co.in>
2014-04-30 14:41           ` Kurt Van Dijck
2014-04-30 16:35             ` Oliver Hartkopp
2014-05-01 18:49               ` Kurt Van Dijck
     [not found]                 ` <5363243E.7070406@tataelxsi.co.in>
2014-05-02 11:00                   ` Kurt Van Dijck
2014-04-29 12:47     ` Heinz-Jürgen Oertel [this message]
     [not found]       ` <535FA7BB.3070700@tataelxsi.co.in>
2014-04-29 14:12         ` Heinz-Jürgen Oertel
     [not found]     ` <535F5449.7000108@tataelxsi.co.in>
2014-04-29 13:33       ` Kurt Van Dijck
2014-04-29 14:12         ` 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=21197917.OgRarI4yV7@laura \
    --to=oe@emtas.de \
    --cc=arigead@gmail.com \
    --cc=ba.rsrajeshwaran@tataelxsi.co.in \
    --cc=dev.kurt@vandijck-laurijssen.be \
    --cc=linux-can@vger.kernel.org \
    /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