<p dir="ltr">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.</p>

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