Other Parts Discussed in Thread: AM4379
Dear Sir,
I use the mmap function to operate the GPIO5(AM4379), but I can only read the REVISION register, I can not write the output register. I paste the code. Thanks so much.
#define NSEC_PER_SEC (1000000000) /* The number of nsecs per sec. */
#define GPIO5_START_ADDR (0x48322000)
#define GPIO5_END_ADDR (0x48323000)
#define GPIO5_CLR_OFFSET (0x190)
#define GPIO5_SET_OFFSET (0x194)
#define GPIO5_SIZE (GPIO5_END_ADDR - GPIO5_START_ADDR)
void *thread_func(void *data)
{
struct timespec t;
int interval = 500000000; /* 50us*/
void *gpio5_address = (void *)0;
int fd = 0;
if ((fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
printf("can't open /dev/mem \n");
exit(-1);
}
gpio5_address = mmap(0, GPIO5_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO5_START_ADDR);
if(gpio5_address == MAP_FAILED)
{
printf("unable to map GPIO5 bank.\n");
}
volatile unsigned int *gpio = 0;
gpio = (volatile unsigned int *)gpio5_address;
*(gpio+0x134) = 0x3F00;
// printf("input enable:%x\n",*(gpio));
// printf("CTRL Value:%x\n",*(gpio));
clock_gettime(CLOCK_MONOTONIC ,&t);
/* start after one second */
t.tv_sec++;
*(gpio+0x190) = 0x3F00;
printf("mmap addr is:%x\n",(unsigned int)gpio);
printf("GPIO REVISION:%x\n",*(gpio));
*(gpio+0x190) = (3<<10);
while(1) {
/* wait until next shot */
clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &t, NULL);
/* do the stuff */
printf("HelloWorld\n");
*(gpio+0x190) = 0x3F00;
printf("DATAOUT:%x\n",*(gpio+0x13C));
printf("DATAIN:%x\n",*(gpio+0x138));
/* calculate next shot */
t.tv_nsec += interval;
while (t.tv_nsec >= NSEC_PER_SEC) {
t.tv_nsec -= NSEC_PER_SEC;
t.tv_sec++;
}
}