Google
  Web www.spinics.net

Re: Writing/Reading GPIO on AT91SAM9260ek

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Paul Kavan wrote:

Thanks for the info. So, if I cannot use those definitions, any idea
of how to access the gpio pins from userspace?


I know this was different for me as well coming from the old DOS standpoint. The trick to remember is that memory (and therefore hardware) is going through a transformation-layer to allow the kernel to better keep track of things.

For accessing I/O, this means we need a way to map back and forth. This usually involves opening the device /dev/mem and using the "mmap" function to get a pointer for use. Something like this:


if((mem = open ("/dev/mem", O_RDWR | O_SYNC))== -1){
  printf("Cannot open /dev/mem! \n");
  exit(-1);
}
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem, target & ~MAP_MASK);
if( map_base == (void *)-1){
printf("mmap error!");
exit(-1);
}

virt_addr=map_base + (target & MAP_MASK);
readval = *((unsigned long *) virt_addr);

printf("Value:");
printf("%x", readval);

Hope this is of some use,

-Adam


--
Adam Yergovich
Engineer
JK Microsystems

1403 Fifth St. Suite D
Davis, CA 95616

Tel:(530) 297-6073

-------------------------------------------------------------------
List admin: http://lists.arm.linux.org.uk/mailman/listinfo/linux-arm
FAQ:        http://www.arm.linux.org.uk/mailinglists/faq.php
Etiquette:  http://www.arm.linux.org.uk/mailinglists/etiquette.php

[Site Home]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux ARM Kernel]     [Linux MIPS]     [ECOS]     [Tools]     [DDR & Rambus]     [Monitors]

Powered by Linux