Why this interrupt handler does not work?
The main idea is that each time that the Real time Clock (RTC) enables, my_handler print the message.
#include <stdio.h> #include <linux/rtc.h> #include <sys/ioctl.h> #include <sys/time.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <linux/sched.h> void my_handler(int irq, void *dev_id, struct pt_regs *regs) { printk("working"); } void main(void) { int i, fd, retval, irqcount = 0; unsigned long tmp, data; struct rtc_time; free_irq(8,NULL); request_irq(8,my_handler,SA_INTERRUPT,"test",NULL); fd = open ("/dev/rtc", O_RDONLY); if (fd == -1) { perror("/dev/rtc"); exit(errno); } fprintf(stderr, "\n\t\t\tRTC \n\n"); fprintf(stderr, "Counting 20 interrupts at:"); fflush(stderr); for (tmp=2; tmp<=8192; tmp*=2) { retval = ioctl(fd, RTC_IRQP_SET, tmp); if (retval == -1) { perror("ioctl"); exit(errno); } fprintf(stderr, "\n%ldHz:\t", tmp); fflush(stderr); /* Enable periodic interrupts */ retval = ioctl(fd, RTC_PIE_ON, 0); if (retval == -1) { perror("ioctl"); exit(errno); } for (i=1; i<21; i++) { /* This blocks */ retval = read(fd, &data, sizeof(unsigned long)); if (retval == -1) { perror("read"); exit(errno); } fprintf(stderr, " %d",i); fflush(stderr); irqcount++; } /* Disable periodic interrupts */ retval = ioctl(fd, RTC_PIE_OFF, 0); if (retval == -1) { perror("ioctl"); exit(errno); } } close(fd); free_irq(8,NULL); } |
i was under the impression that installing/freeing interrupt handlers could only be done in kernel space?
|
All times are GMT -5. The time now is 08:05 PM. |