All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Florian Feldbauer <florian@ep1.ruhr-uni-bochum.de>,
	linux-can@vger.kernel.org
Subject: Re: Writing socketCAN module for my own hardware
Date: Tue, 12 Aug 2014 12:01:56 +0200	[thread overview]
Message-ID: <53E9E614.7060303@pengutronix.de> (raw)
In-Reply-To: <53E9D6F3.4050206@ep1.ruhr-uni-bochum.de>

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

On 08/12/2014 10:57 AM, Florian Feldbauer wrote:
> On 08/12/2014 10:24 AM, Marc Kleine-Budde wrote:
>> On 08/12/2014 09:51 AM, Florian Feldbauer wrote:
>>> I have developed a CAN interface for the Raspberry Pi computer using the
>>> SJA1000 directly connected to the GPIOs of the CPU.
>> This sounds very slow :)
> Actually no. At least with the chardev driver it was faster than the
> PEAK USB-CAN-PRO
> connected to my laptop.
> But I'm using direct memory manipulation to set/clear the GPIOs.
> This is much faster than using the designated GPIO functions from the
> kernel...

Portability comes with a price.

>>> So far this interface is used as chardev and works fine.
>>> But I'm also developing a user-space program using this CAN interface.
>>> This program should also be compatible with other CAN interfaces like
>>> the ones from PEAK or Kvazer. So I thought using socketCAN would be a
>>> good idea.
>> Yes.
>>
>>> Is there any documentation on how to write a socketCAN compatible kernel
>>> module for my own hardware?
>>> I tried writing something similar to the sja1000_isa driver...
>> IMHO sja1000_platform.c is a better blueprint, as it uses the device
>> tree to describe the hardware and does not rely on module parameters.
> Ok. I will have a look at it.
>>
>>> So far my modified kernel compiles and I can change bitrate and bring
>>> the interface up.
>>> But as soon as I try to send a CAN frame I get the error:
>>> Error 105: No buffer space available
>> You are sending CAN frames faster than the driver is able to send them,
>> you have to wait a bit, before sending new CAN frames.
> I'm using
>   int nbytes = write( fd, pframe, sizeof(can_frame_t) );
> to send a message. I thought this function blocks until the write is
> finished?

No. It will return with a errno if the message cannot be queued.

> My old chardev module was based on the kernel module from PEAK systems and
> thus had a FIFO buffer for sending and receiving messages.
> From the above error, I assume, socketCAN has no internal buffer?

There are buffers for RX and TX.

> What happens if there are many messages received on a small timescale?

If the system can handle the RX load all messages will be queued. Then
there are per socket queues for your userspace applications. If a queue
if full, CAN frames will be dropped. You can get information about
dropped CAN frames with the recvmsg() system call. See candump.c from
the gitorious can-utils for an exmaple.

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: 181 bytes --]

  reply	other threads:[~2014-08-12 10:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-12  7:51 Writing socketCAN module for my own hardware Florian Feldbauer
2014-08-12  8:24 ` Marc Kleine-Budde
2014-08-12  8:57   ` Florian Feldbauer
2014-08-12 10:01     ` Marc Kleine-Budde [this message]
2014-10-01  7:26       ` Florian Feldbauer
2014-10-01  7:49         ` Marc Kleine-Budde
2014-10-01 12:32           ` Florian Feldbauer
2014-10-01 12:41             ` Marc Kleine-Budde
2014-10-01 12:56               ` Florian Feldbauer
2014-10-01 13:11                 ` Marc Kleine-Budde
2014-10-09 15:06               ` Florian Feldbauer
2014-10-09 16:13                 ` Marc Kleine-Budde
2014-10-10  7:43                   ` Florian Feldbauer
2014-10-10  8:06                     ` Marc Kleine-Budde
2014-10-10  8:09                       ` Florian Feldbauer

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=53E9E614.7060303@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=florian@ep1.ruhr-uni-bochum.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.