From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <4DFDFD2F.1080506@domain.hid> Date: Sun, 19 Jun 2011 15:44:15 +0200 From: Gilles Chanteperdrix MIME-Version: 1.0 References: <4DFDF79F.1090502@domain.hid> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Xenomai-help] Problem accesing I2C without using Linux kernel List-Id: Help regarding installation and common use of Xenomai List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andrey Nechypurenko Cc: Xenomai help 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. -- Gilles.