HI Salman,
Can you please upload your beagleboneio.h header file here?
I am unable to understand the parameters passed as arguments in below line.
gpio_base = mmap_device_io(AM335X_GPIO_SIZE, BaseAddress);
what should i give if Ineed to blink LED on GPIO1_17 pin?
Regards,
Dhaneshwari
On Saturday, July 4, 2015 at 8:49:10 AM UTC-7, Salman Feroze 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 <[email protected]
> <javascript:>> 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 <[email protected] <javascript:>>
>> 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 <[email protected]
>>> <javascript:>> написал(а):
>>>
>>> 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 [email protected] <javascript:>.
>>> 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 [email protected] <javascript:>.
>>> 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
>> [email protected] <javascript:>.
>> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/43d28084-2d67-4bda-9ea4-60b8971d66cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.