Hello all,
I'm trying to find a way to access (that is, read / write) GPIO
registers on the DaVinci, preferably from userspace. As I understand it,
the proper way to go about it is to mmap the GPIO space, and then simply
access the registers. Attached is a small program that tries to do just
that, but fails (the value read from the DIR23 register does not
change). Any ideas / suggestions on why my approach fails or how to
control the GPIO's properly?
Thanx,
Avishai.
#include <stdint.h>
#include <stdio.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#define GPIO_PAGE_ADDR 0x01C67000
#define GPIO_DIR23_OFF 0x38
#define reg_addr(p, o) ((uint32_t *)((void *)p + o))
int main(int argc, char *argv[])
{
int i;
uint32_t *p;
char *filename = "/dev/mem";
void *addr = 0;
size_t length = 2048; // 2Kb
int prot = PROT_READ | PROT_WRITE;
int flags = MAP_SHARED;
int fd = open(filename, O_RDWR);
off_t offset = (off_t)GPIO_PAGE_ADDR;
if (fd < 0) {
perror("open");
return 1;
}
p = mmap(addr, length, prot, flags, fd, offset);
if (p == MAP_FAILED) {
perror("mmap");
return 4;
}
// read DIR23 value
printf("original reg value: 0x%x\n", *reg_addr(p, GPIO_DIR23_OFF));
*(volatile uint32_t*)reg_addr(p, 0xGPIO_DIR23_OFF) = 0xAA;
printf("modified reg value: 0x%x\n", *reg_addr(p, GPIO_DIR23_OFF));
return 0;
}
_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source