RasPi GPIO driver

Simon Williams williamssimonp at gmail.com
Sun Oct 20 23:29:12 UTC 2013


This is a good question, for which I could not come up with a good answer.
I have written a driver to provide posix support,  but I decided that the
read and write functions didn't mean much and ended up using IOCTL instead.
I wrote a task that used GPIO directly initially, but decided that there
should be something in the kernel for it and automatically thought 'device
driver'. I then decided to implement one as an easy prelude to my next task
which is a block device driver for the SD card.

The main aim was to deliver something  small, but possibly useful and to
get some feedback on my code  before wading into anything too heavy weight.

Regards

Simon
On 20 Oct 2013 23:45, "Alan Cudmore" <alan.cudmore at gmail.com> wrote:

> We can certainly read and write GPIO pins without POSIX support. I think
> Pierre was trying to create a standard driver for GPIO that might be
> expanded into a generic GPIO interface for all BSPs.
>
> The code in Pierre's driver has the basic macros and defines to do the
> GPIO reads and writes. It could be used without the driver.
>
> But this is a good time to bring this up:
> What should the Raspberry Pi GPIO support look like in the BSP?
> 1. Simple direct reads and writes through macros or functions?
> 2. A driver such as Pierre's
> 3. Or a combination of both: Supply the driver and defines/macros and
> allow the user to decide what to use?
>
> Alan
>
>
>
> On 10/20/2013 6:19 PM, sarraciro wrote:
>
>> Hi Alan,
>> yes I've tested it too and work properly...
>> for compile using your rki-project makefile (as starting point) I had to
>> add the POSIX support in the makefile...(RTEMS_HAS_POSIX_**API = yes
>> after
>> paths for RTEMS tools and RTEMS BSP).
>> But ... it use posix support ... There is another way?? like ChibiOS ???
>>
>> I've read an article about minimum constrains to compile C code in bare
>> metal OS ...
>> I think the solution is something like this:
>>
>> /* mmio.h - access to MMIO registers */
>>   #ifndef MMIO_H
>> #define MMIO_H
>>   #include <stdint.h>
>>   // write to MMIO register
>> static inline void mmio_write(uint32_t reg, uint32_t data) {
>>      uint32_t *ptr = (uint32_t*)reg;
>>      asm volatile("str %[data], [%[reg]]"
>>              : : [reg]"r"(ptr), [data]"r"(data));
>> }
>>   // read from MMIO register
>> static inline uint32_t mmio_read(uint32_t reg) {
>>      uint32_t *ptr = (uint32_t*)reg;
>>      uint32_t data;
>>      asm volatile("ldr %[data], [%[reg]]"
>>                  : [data]"=r"(data) : [reg]"r"(ptr));
>>      return data;
>> }
>>   #endif // #ifndef MMIO_H
>>
>> anyone can confirm or disagree with this?
>> The ": :" or ":" are not C operators true?? sounds like C++?
>>
>> --
>> RC (popovich)
>>
>>
>> Il giorno dom, 20/10/2013 alle 18.05 -0400, Alan Cudmore ha scritto:
>>
>>> There is an RTEMS Rpi GPIO driver here:
>>> https://github.com/pficheux/**raspberry_pi/tree/master/**
>>> RTEMS/gpio_driver<https://github.com/pficheux/raspberry_pi/tree/master/RTEMS/gpio_driver>
>>> I have tested this, and it works.
>>>
>>> Simon, I will definitely check out your driver when you submit it.
>>>
>>> Alan
>>>
>>> On 10/20/2013 5:57 PM, sarraciro wrote:
>>>
>>>> Thank you Simon for your prompt reply... sure that I'm interested!
>>>> I'll wait for the patch! but also I'm trying to learn (understand!?!)
>>>> how to write  a simple driver for RTEMS... for other future use of a
>>>> custom drivers.
>>>> regards
>>>>
>>>> --
>>>> RC
>>>>    Il giorno dom, 20/10/2013 alle 21.32 +0000, williamssimonp at gmail.comha
>>>> scritto:
>>>>
>>>>> I am testing one as we speak, if you’re interested.  Should be ready
>>>>> to submit the patch about mid-week.
>>>>>    Regards
>>>>>    Simon
>>>>>    Sent from Windows Mail
>>>>>    From: sarraciro
>>>>> Sent: ‎Sunday‎, ‎20‎ ‎October‎ ‎2013 ‎22‎:‎28
>>>>> To: rtems-users at rtems.org
>>>>>    Hi all,
>>>>> I'm trying to write a simple driver to use raspberry pi gpio.
>>>>> I've found some examples for the POSIX approach (& I tried it with
>>>>> success) but I'm more interesting to pure C solution.
>>>>> I read the RTEMS's documentation but it's too general (for my
>>>>> know-how) ... and  I've read the BCM2835 datasheet for register
>>>>> addresses ...  I understood the relevance to use the pointers for
>>>>> access
>>>>> to the memory...but I'm stucking until now I don't understand how to
>>>>> move on...
>>>>> Any suggestions or lectures for understand how to complete the task?
>>>>> thank you
>>>>> rc
>>>>>
>>>>> ______________________________**_________________
>>>>> rtems-users mailing list
>>>>> rtems-users at rtems.org
>>>>> http://www.rtems.org/mailman/**listinfo/rtems-users<http://www.rtems.org/mailman/listinfo/rtems-users>
>>>>>
>>>>>
>>>> ______________________________**_________________
>>>> rtems-users mailing list
>>>> rtems-users at rtems.org
>>>> http://www.rtems.org/mailman/**listinfo/rtems-users<http://www.rtems.org/mailman/listinfo/rtems-users>
>>>>
>>>
>>
>> ______________________________**_________________
>> rtems-users mailing list
>> rtems-users at rtems.org
>> http://www.rtems.org/mailman/**listinfo/rtems-users<http://www.rtems.org/mailman/listinfo/rtems-users>
>>
>
> ______________________________**_________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/**listinfo/rtems-users<http://www.rtems.org/mailman/listinfo/rtems-users>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20131021/f6ec94a6/attachment-0001.html>


More information about the users mailing list