/* * mon_int.c: Monitor interrupts from FPGA * * AUTHOR: Mark McDermott * CREATED: June 12, 2008 * COPYRIGHT: 2008 The Learning Labs, Inc. * * DESCRIPTION: This program opens up a char device and monitors interrupts * coming from the FPGA through PF16 on the iMX21. * DEPENDENCIES: none * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include #include #include #include #include #include #define fpga_MAJOR 245 int det_int=0; int num_int =0; /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This routine would do the interrupt handling for the main loop. * */ void sighandler(int signo) { if (signo==SIGIO) det_int++; printf("\nmon_interrupt: Interrupt captured by SIGIO\n"); // DEBUG return; /* Return to main loop */ } char buffer[4096]; int main(int argc, char **argv) { int count; struct sigaction action; int fd; int rc; int fc; // memset(&action, 0, sizeof(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/fpga_int", O_RDWR); if (fd == -1) { perror("Unable to open /dev/fpa_int"); rc = fd; exit (-1); } printf("\nmon_interrupt: /dev/fpga_int opened successfully\n"); fc = fcntl(fd, F_SETOWN, getpid()); if (fc == -1) { perror("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); } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This while loop emulates a program running the main * loop i.e. sleep(). The main loop is interrupted when * the SIGIO signal is received. */ while(1) { /* this only returns if a signal arrives */ sleep(86400); /* one day */ if (!det_int) continue; num_int++; printf("mon_interrupt: Number of interrupts detected: %d\n", num_int); det_int=0; } }