From: Wolfgang Grandegger <wg@grandegger.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 1/5] CAN interface library
Date: Sun, 01 Nov 2009 17:16:59 +0100 [thread overview]
Message-ID: <4AEDB47B.3010101@grandegger.com> (raw)
In-Reply-To: <200911010936.10570.vapier@gentoo.org>
Mike Frysinger wrote:
> On Sunday 01 November 2009 06:33:33 Wolfgang Grandegger wrote:
[snip]
>> --- /dev/null
>> +++ b/drivers/can/can.c
>>
>> +static char *baudrates[] = { "125K", "250K", "500K" };
>
> so we're restricting ourselves to these three speeds ? i have passing
> familiarity with CAN, but i didnt think the protocol was restricted to
> specific speeds.
Well, this is an RFC and as I wrote in the introduction some features
need to be added or extended, especially for CAN device configuration.
My idea is to have a more complete default bit-timing table, which board
specific code may overwrite using, for example:
sja1000_register(&my_sja1000, &my_config_opts);
This would also allow to set the CAN clock, cdr and ocr registers.
>> +int can_register (struct can_dev* can_dev)
>
> no space before the paren, and the * is cuddled on the wrong side of the
> space. seems like a lot of this code suffers from these two issues.
U-Boot coding style requires a space after the function name and before
"(". But the "*" is misplaced, of course.
>> +{
>> + struct can_dev* dev;
>> +
>> + can_dev->next = NULL;
>> + if (!can_devs)
>> + can_devs = can_dev;
>> + else {
>> + for (dev = can_devs; dev->next; dev = dev->next)
>> + ;
>> + dev->next = can_dev;
>> + }
>
> invert the if logic and i think the code would look "nicer" -- use braces on
> the first branch instead of the second.
OK.
>> +struct can_dev *can_init (int dev_num, int ibaud)
>> +{
>> + struct can_dev *dev;
>> + int i;
>> +
>> + if (!can_devs) {
>> + puts ("No CAN devices registered\n");
>> + return NULL;
>> + }
>> +
>> + /* Advance to selected device */
>> + for (i = 0, dev = can_devs; dev; i++, dev = dev->next) {
>> + if (i == dev_num)
>> + break;
>> + }
>> +
>> + if (!dev) {
>> + printf ("CAN device %d does not exist\n", dev_num);
>> + return NULL;
>> + }
>> +
>> + printf ("Initializing CAN%d at 0x%08x with baudrate %s\n",
>> + i, dev->base, baudrates[ibaud]);
>> +
>> + dev->init (dev, ibaud);
>> +
>> + return dev;
>> +}
>
> wonder if we should have a generic device list code base since this looks
> similar to a lot of other u-boot device lists ...
Do we already have a generic interface?
>> --- /dev/null
>> +++ b/include/can.h
>> @@ -0,0 +1,70 @@
>> +/*
>> + * (C) Copyright 2007-2009, Wolfgang Grandegger <wg@denx.de>
>
> have you really been working on this stuff since 2007 ?
The code was written in 2007. "2007, 2009" is more appropriate.
>> +struct can_dev {
>> + char *name;
>
> const ?
OK.
Wolfgang.
next prev parent reply other threads:[~2009-11-01 16:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-01 11:33 [U-Boot] [RFC 0/5] CAN framework for U-Boot Wolfgang Grandegger
2009-11-01 11:33 ` [U-Boot] [RFC 1/5] CAN interface library Wolfgang Grandegger
2009-11-01 11:33 ` [U-Boot] [RFC 2/5] CAN device test command Wolfgang Grandegger
2009-11-01 11:33 ` [U-Boot] [RFC 3/5] CAN device driver for the SJA1000 Wolfgang Grandegger
2009-11-01 11:33 ` [U-Boot] [RFC 4/5] CAN device driver for the Intel 82527 Wolfgang Grandegger
2009-11-01 11:33 ` [U-Boot] [RFC 5/5] CAN interface support for the TQM855L module Wolfgang Grandegger
2009-11-02 12:02 ` [U-Boot] [RFC 3/5] CAN device driver for the SJA1000 Matthias Fuchs
2009-11-02 12:50 ` Wolfgang Grandegger
2009-11-02 14:22 ` Matthias Fuchs
2009-11-02 20:20 ` Wolfgang Grandegger
2009-11-05 20:28 ` Wolfgang Denk
2009-11-01 14:45 ` [U-Boot] [RFC 2/5] CAN device test command Mike Frysinger
2009-11-01 16:24 ` Wolfgang Grandegger
2009-11-01 18:07 ` Mike Frysinger
2009-11-01 14:36 ` [U-Boot] [RFC 1/5] CAN interface library Mike Frysinger
2009-11-01 16:16 ` Wolfgang Grandegger [this message]
2009-11-01 18:05 ` Mike Frysinger
2009-11-01 22:00 ` 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=4AEDB47B.3010101@grandegger.com \
--to=wg@grandegger.com \
--cc=u-boot@lists.denx.de \
/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