Hi everyone
I am working on a ultrasound imaging project which involves using the Beagle Board SPI interface to communicate with another board.
I am planning to use the GPIO pin(24) at the expansion connector as input to monitor the interrupt signal from another board. I read the DM37x TRM and followed those steps closely, but it did not work out as expected.
This is my program which is based on the example program i found herehttp://41j.com/blog/2011/09/beagleboard-gpio-input-driverless/
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <sys/mman.h> int main(void) { printf ("open file descriptor for PADCONFIG\n"); int fd = open("/dev/mem", O_RDWR | O_SYNC); //O_SYNC makes the memory uncacheable if (fd < 0) { printf("Could not open PADCONFIG memory fd\n"); return 0; } // Pad configuration printf ("map PINCONFIG\n"); volatile ulong *pinconf; pinconf = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x48000000); if (pinconf == MAP_FAILED) { printf("Pinconf Mapping failed\n"); close(fd); return 0; } printf ("set pinconfig GPIO\n"); pinconf[0x21BC/4] = 0x011C011C;//mux gpio168 as input close(fd); /* -------------------------------------- */ printf ("open file descriptor for GPIO\n"); int gpio_fd = open("/dev/mem", O_RDWR | O_SYNC); if (gpio_fd < 0) { printf("Could not open GPIO memory fd\n"); return 0; } // GPIO configuratio printf ("map GPIO\n"); volatile ulong *gpio; gpio = (ulong*) mmap(NULL, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, g gpio_fd, 0x49050000); if (gpio == MAP_FAILED) { printf ("GPIO Mapping failed\n"); close(gpio_fd); return 0; } printf ("set GPIO config\n"); // Configure GPIO pin on bank 6 as output. gpio[0x8034/4] |=0x00000100; //set gpio168 in bank 6 as input gpio[0x8080/4] = 0x00000100; //clear the wake-up enable in GPIO_WAKEUPENABLE page 3520 gpio[0x8060/4] = 0x00000100; // clear the the corresponding bit in the gpio[0x8070/4] = 0x00000100;//0x1: Clear the corresponding bit in the GPIO_IRQENABLE2 register page 351 if(gpio[0x8038/4]&&0x00000100) printf("The out put is 1\n");//not sure about this part else printf("The out put is 0\n"); close(gpio_fd); }
`
`
I am having the problem when the program runs here.(set the corresponding bit in the GPIO_OE reg)
gpio[0x8034/4] |=0x00000100; //set gpio168(pin24) in bank 6 as input
`
`
I am very new to bit wise operation and not sure if i am doing it right.
Also, I want to check the level of my input by check the data in GPIO_DATAIN registor(0x8038) It is legal to do something like this to check that bit?
for(;;){
if(gpio[0x8038/4]&&0x00000100)
printf("The input is 1\n");//not sure about this part
else
printf("The input is 0\n");
}
`
`
The way they do it in the example program is like:
for(;;) {
if(gpio[0x6038/4] == 201390076) printf("1\n");
// printf("gpio5: %d \n",gpio[0x6038/4]);
}
I have no idea how they got this 201390076 number.
Please advise, thanks.