LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2004, 11:41 AM   #1
opereira
LQ Newbie
 
Registered: Mar 2004
Posts: 2

Rep: Reputation: 0
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);

}
 
Old 03-04-2004, 01:37 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
i was under the impression that installing/freeing interrupt handlers could only be done in kernel space?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Interrupt Handler lucky6969b Linux - Software 1 12-01-2005 11:55 AM
printk in the interrupt handler lordofring Programming 3 08-23-2005 08:00 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
Timer Interrupt Handler opereira Programming 1 03-03-2004 04:57 PM
parallel port handler interrupt tincho Programming 1 10-01-2003 05:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration