All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Andrey Nechypurenko <andreynech@domain.hid>
Cc: Xenomai help <xenomai@xenomai.org>
Subject: Re: [Xenomai-help] Problem accesing I2C without using Linux kernel
Date: Sun, 19 Jun 2011 15:54:04 +0200	[thread overview]
Message-ID: <4DFDFF7C.7000805@domain.hid> (raw)
In-Reply-To: <4DFDFD2F.1080506@domain.hid>

On 06/19/2011 03:44 PM, Gilles Chanteperdrix wrote:
> On 06/19/2011 03:34 PM, Andrey Nechypurenko wrote:
>> Hi Gilles,
>>
>>>> fd = open("/dev/mem", O_RDWR | O_SYNC);
>>>> i2c_base = mmap(NULL, sizeof(i2c_base),
>>>>                PROT_READ | PROT_WRITE,
>>>>                MAP_SHARED, fd, I2C_DEFAULT_BASE);
>>>
>>> What is the value of i2c_base here? If it is MAP_FAILED, then mmap
>>> failed. And one reason for failing would be that sizeof(i2c_base) is not
>>> a multiple of the page size.
>>
>> In actual code I do check for the errors like below and it seams like
>> memory is mapped without errors:
>>
>>   if(i2c_base == NULL)
>>   {
>>     fd = open("/dev/mem", O_RDWR | O_SYNC);
>>     if(fd < 0)
>>     {
>>       fprintf(stderr, "Could not open memory\n");
>>       return;
>>     }
>>
>>     i2c_base =
>>       (volatile struct i2c *)mmap(NULL, sizeof(i2c_base),
>>                                   PROT_READ | PROT_WRITE,
>>                                   MAP_SHARED, fd, I2C_DEFAULT_BASE);
>>     if(i2c_base == MAP_FAILED)
>>     {
>>       fprintf(stderr, "Memory Mapping failed\n");
>>       close(fd);
>>       return;
>>     }
>>   }
>>
>> Regarding the size of the memory mapped block - i2c_base is a pointer
>> and that is why, the mmap invocation above is incorrect. It should be
>> mmap(NULL, sizeof(struct i2c). This is a typo resulted by multiple
>> experiments I was doing. sizeof(struct i2c) is 64 and event with this
>> value, the same "Bus error" message is printed and the application
>> quits.
> 
> Ok. I would pass the size of an entire page anyway, I do not think
> mapping anything not aligned on a page boundary makes sense.
> 
> If it still fails, enable CONFIG_DEBUG_USER in kernel configuration,
> pass user_debug=29 on kernel command line, and post the user debug log
> upon failure, then the disassembly of the function where the SIGBUS happens.
> 
> Note that this mailing list is probably not the best place to ask your
> question, since we mostly talk about Xenomai here, and your issue does
> not seem to have anything to do with Xenomai.
> 
> Please keep the discussion public.

Second stupid questions: are you sure all the clocks needed to get that
I2C module running are enabled?

-- 
                                                                Gilles.


  reply	other threads:[~2011-06-19 13:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-19 13:16 [Xenomai-help] Problem accesing I2C without using Linux kernel Andrey Nechypurenko
2011-06-19 13:20 ` Gilles Chanteperdrix
     [not found]   ` <BANLkTinVUd-R1cpD+40MGZZckzGhwrqRvw@domain.hid>
2011-06-19 13:44     ` Gilles Chanteperdrix
2011-06-19 13:54       ` Gilles Chanteperdrix [this message]
2011-06-19 14:06       ` Andrey Nechypurenko
2011-06-19 14:11         ` Gilles Chanteperdrix
2011-06-19 14:21           ` Andrey Nechypurenko
2011-06-19 16:57             ` Gilles Chanteperdrix
2011-06-19 20:24               ` Andrey Nechypurenko
2011-06-20  0:00                 ` [Xenomai-help] Beagleboard Xenomai David Wiebe
2011-06-20  5:02                   ` [Xenomai-help] Compiling program with xenomai support David Wiebe
2011-06-20  7:14                     ` Gilles Chanteperdrix
2011-06-20  8:06                       ` David Wiebe
2011-06-20 11:13                         ` Gilles Chanteperdrix
2011-06-20 19:04                           ` David Wiebe

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=4DFDFF7C.7000805@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=andreynech@domain.hid \
    --cc=xenomai@xenomai.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.