Ok, so you used mmap. I have not  read your whole source listing there but
that seems evident.

I can say though that you already have more experience in this area than
me. As I've not written any C / mmap code to directly manipulate gpio
registers.

With that said, there are many blogposts on the subject of beaglebone using
mmap with GPIO, etc on the internet. There was even a hackaday post on
someone talking about sysfs versus mmap and mmap being close to 1000x
faster. Anyway this person also posted code on guthub . . .

Short of telling you to "search the web and find information". What is it
exactly that you need help understanding ? As I may not personally be able
to give you a 100% correct answer off the top of my head. But I *may* be
able to point you to a resource that could answer your question. Just keep
in mind when I say there is a "lot" of information out there on the
subject. There really is.

Keywords "beaglebone black mmap gpio" will give lots of information on the
subject. Otherwise.

On Sat, Jul 4, 2015 at 8:49 AM, Salman Feroze <salmanferoz...@gmail.com>
wrote:

> Hey guys,
>
> Thanks in getting back to me I have posted the code that I used to enable
> a GPIO to act as input or an output below;
>
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <hw/inout.h>
> #include <sys/mman.h>
> #include <sys/neutrino.h>
> #include <stdint.h>
> #include <BeagleBoneIO.h>
>
>
> uintptr_t MapIO(uintptr_t gpio_base, uint32_t BaseAddress)
>
> {
>     gpio_base = mmap_device_io(AM335X_GPIO_SIZE, BaseAddress);
>     if(gpio_base == MAP_DEVICE_FAILED)
>     {
>         perror("Can't map device I/O for GPIO");
>         printf("Main Terminated...!\n");
>         return 0;
>     }
>     return gpio_base;
> }
>
>
> int WriteIO(uintptr_t gpio_base, int value, uint32_t BitsToModify)
>
> {
>     uint32_t val = 0;
>     val  = in32(gpio_base + GPIO_DATAOUT);    // value that is currently
> on the GPIO port
>
>     if (value==0)
>     {
>         val &= ~BitsToModify; // clear the bits
>     }
>     else
>     {
>         val |= BitsToModify;  // set the bits
>     }
>
>     out32(gpio_base + GPIO_DATAOUT, val);
>
>     return 0;
> }
>
>
> int SetDDR(uintptr_t gpio_port, int Direction, uint32_t BitsToSet)
>
> {
>     uint32_t val = 0;
>
>     // Read GPIO output enable register
>     //  0 The corresponding GPIO port is configured as an output.
>     //  1 The corresponding GPIO port is configured as an input.
>     val  = in32(gpio_port + GPIO_OE);
>
>     printf("value of register output enable register= %#010x\n", val);
>
> if(Direction== 0)
>         val &= ~(BitsToSet); // make sure they are 0
>     else
>         val |= BitsToSet;     // make sure they are set to 1
>
>     out32(gpio_port + GPIO_OE, val); // write value to output enable
>
>     val  = in32(gpio_port + GPIO_OE);
>     printf("Modified value of register output enable register= %#010x\n",
> val);
>
>     return 0;
> }
>
> uint32_t ReadIO(uintptr_t gpio_base, uint32_t BitsToRead)
>
> {
>     uint32_t val = 0;
>     val  = in32(gpio_base + GPIO_DATAIN);    // value that is currently on
> the GPIO port
>
>     printf("\nvalue of data register = %#010x\n", val);
>
>     val &= BitsToRead; // mask bit
>
>     printf("value of data register after masking it = %#010x\n", val);
>
>     return val;
> }
>
>
> int main(int argc, char *argv[])
>
> {
>     printf("Welcome to the QNX Momentics BeagleBone GPIO Reader\n");
>
>     uintptr_t    gpio0_port = 0;
>     uintptr_t    gpio1_port = 0;
>     uintptr_t    gpio2_port = 0;
>     uintptr_t    gpio3_port = 0;
>     uint32_t    val = 0;
>
>     ThreadCtl(_NTO_TCTL_IO,NULL);    // Request I/O privileges; let the
> thread execute the I/O opcodes
>                                     // in, ins, out, outs, cli, sti on
> architectures where it has the
>                                     // appropriate privilege, and let it
> attach IRQ handlers. You need
>                                     // root permissions to use this
> command. If a thread attempts to use
>                                     // faults with a SIGSEGV when the
> opcode is attempted.
>
>
>     uintptr_t gpio_base;
>
>     gpio_base = mmap_device_io(0x08, 0x44e10844);
>
>  if(gpio_base == MAP_DEVICE_FAILED)
>
>  {
>         perror("Can't map Control Base Module");
>         printf("Main Terminated...!\n");
>         return 0;
>     }
>
> printf("Device gpio_base\t = %#010x\n", gpio_base);
>
>
>      gpio1_port = MapIO(gpio1_port, AM335X_GPIO1_BASE);
>
>
>     // set the data direction
>
>     SetDDR(gpio1_port,1, GPIO1_28); // Main function of setting up pin 28
> as an input
>
>     munmap_device_io(gpio1_port, AM335X_GPIO_SIZE);
>
>     printf("\nAll good - Main Terminated...!\n");
>     return EXIT_SUCCESS;
>
> }
>
>
> So what I've done above is, writing up a data direction register function
> and writing to GPIO 28 to be an input(1). If I were to set GPIO 28 as an
> output, I have to to just change   SetDDR(gpio1_port, 0, GPIO1_28).
>
> Hope it helps!
>
> On Sat, Jul 4, 2015 at 4:35 AM, William Hermans <yyrk...@gmail.com> wrote:
>
>> Salman, bear with me, as I know very little about QNX. If you could
>> explain how you identified, and set the pin to input. That might help us
>> better answer your question. WIth Debian, there are a few options, but no
>> idea which of these options, if any are available with QNX.
>>
>> On Fri, Jul 3, 2015 at 10:57 AM, Max <lisar...@gmail.com> wrote:
>>
>>> If the pin acts as the input then it should read an external state. I
>>> would configure this pin as the output and then write 0/1 to a necessary
>>> bit position
>>>
>>> Отправлено с iPad
>>>
>>> 3 июля 2015 г., в 19:02, Salman Feroze <salmanferoz...@gmail.com>
>>> написал(а):
>>>
>>> Hey guys,
>>>
>>> I am relatively new in this forum, so please bear with me if the
>>> questions I ask would sound unintelligent. I am currently working with the
>>> Beagle Bone Black that is running QNX RTOS. I am trying to get my head
>>> around this board by developing simple programs such as turning ON an
>>> external LED that is connected to the board. So far, I have manage to
>>> identify a GPIO pin and set it to be an input using the data direction
>>> register (DDR) function. However, I am unable to move on from here.
>>>
>>> Since I have enabled the pin to act as input, how would I be able to use
>>> it to turn ON an LED? What should be my next step be?
>>>
>>> Any input/suggestion would be much appreciated.
>>>
>>> --
>>> For more options, visit http://beagleboard.org/discuss
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "BeagleBoard" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to beagleboard+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>  --
>>> For more options, visit http://beagleboard.org/discuss
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "BeagleBoard" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to beagleboard+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>> For more options, visit http://beagleboard.org/discuss
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "BeagleBoard" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/beagleboard/sRd8cPOoKEU/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> beagleboard+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleboard+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to