/* * main.c */ #include #include #include #include #include #include #include #include #include #include #include #define mx21gpio_MAJOR 240 #define MAP_SIZE 4UL #define MAP_MASK (MAP_SIZE - 1) #define READ_CMD (0x0 << 31) #define WRITE_CMD (0x1 << 31) #define GPIO_BASE 0x10015000 #define GPIO_MASK 0x00000fff #define GPIO_SIZE 0x600 #define COMMAND_MASK 0x80000000 int num_int = 0; int det_int = 0; double delta, tmp_delta; float time_buf; int fd; unsigned long target_addr; unsigned int value; void sighandler(int signo) { if (signo == SIGIO) { // Deassert PB10, Get final time value = 1000; ioctl(fd, WRITE_CMD, &value); det_int++; } printf("\nMAIN: Interrupt captured by SIGIO\n"); return; /* Return to main loop */ } char buffer[4096]; int main(int argc, char **argv) { int rc, fc; struct sigaction action; sigemptyset(&action.sa_mask); sigaddset(&action.sa_mask, SIGIO); action.sa_handler = sighandler; action.sa_flags = 0; sigaction(SIGIO, &action, NULL); fd = open("/dev/gpio", O_RDWR); if (fd == -1) { perror("MAIN: Unable to open /dev/gpio"); rc = fd; exit (-1); } printf("\nMAIN: /dev/gpio opened successfully\n"); fc = fcntl(fd, F_SETOWN, getpid()); if (fc == -1) { perror("MAIN: SETOWN failed\n"); rc = fd; exit (-1); } fc= fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_ASYNC); if (fc == -1) { perror("SETFL failed\n"); rc = fd; exit (-1); } // Assert PB10, Get initial time value = 1001; ioctl(fd, WRITE_CMD, &value); printf("MAIN: Wait for a day...\n"); sleep(86400); // num_int++; printf("MAIN: INTERRUPT LATENCY = %.2lf ms\n", delta); return 0; }