LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 11-23-2009, 09:41 AM   #1
LEICIF
LQ Newbie
 
Registered: Nov 2009
Posts: 11

Rep: Reputation: 0
Problem with interrupt handle.


Hello,

I am trying to test linux driver to understand how to handle interrupts.

Code:
// Linux Device Driver Template/Skeleton
// Kernel Module

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <asm/uaccess.h>
#include <asm/io.h>

#include <linux/module.h>
#include <linux/interrupt.h>
#include <asm/io.h>

#define SKELETON_MAJOR 32
#define SKELETON_NAME "skeleton"
#define BASEPORT 0x378
#define PARALLEL_PORT_INTERRUPT 7
#define CASE1 1
#define CASE2 2

static unsigned long devid;
int cntr;

// interrupt handler
static irqreturn_t handler(int irq, void *data)
{
	cntr++;
	printk("parint: >>> Interrupt PARALLEL PORT INT %d HANDLED\n", cntr);
	return IRQ_HANDLED;
}


// define which file operations are supported
struct file_operations skeleton_fops = {
	.owner	=	THIS_MODULE,
	.llseek	=	NULL,
	.readdir=	NULL,
	.poll	=	NULL,
	.mmap	=	NULL,
	.flush	=	NULL,
	.fsync	=	NULL,
	.fasync	=	NULL,
	.lock	=	NULL
};

int xinit_module(void)
{
	int ret;
	ret = request_irq(PARALLEL_PORT_INTERRUPT, handler, IRQF_DISABLED  , "parallelport", (void *)&devid);
	if (ret)	{ printk ("parint: error requesting irq 7: returned %d\n", ret); }
	enable_irq(PARALLEL_PORT_INTERRUPT);
	outb_p(0x10, BASEPORT + 2); 

	printk("parint: Generating Interrupt now on all output pins (intr/ACK = pin 10)\n");
	//generate interrupt
	outb_p(0, BASEPORT);
	outb_p(255, BASEPORT);
	outb_p(0, BASEPORT);
	printk("parint: Interrupt generated. You should see the handler-message\n");
	return 0;
}


void xcleanup_module(void)
{
	printk("Finlizando driver.\n");
	disable_irq(PARALLEL_PORT_INTERRUPT);
	free_irq(PARALLEL_PORT_INTERRUPT, (void *)&devid);
}


module_init(xinit_module);
module_exit(xcleanup_module);
MODULE_LICENSE("GPL");
Driver compile without problem, but , after request_irq in module_init, if I uncomment enable_irq, linux return me a problem:

Code:
Unbalanced enable for IRQ 7
------------[ cut here ]------------
WARNING: at kernel/irq/manage.c:174 enable_irq+0x6f/0xac()
Modules linked in: skeleton(+) usb_storage iptable_filter ip_tables ip6table_filter ip6_tables x_tables ext2 ipv6 i915 drm af_packet snd_pcm_oss snd_mixer_oss snd_seq snd_seq_device cpufreq_conservative cpufreq_userspace cpufreq_powersave acpi_cpufreq binfmt_misc microcode fuse nls_iso8859_1 nls_cp437 vfat fat loop dm_mod ide_disk pata_pcmcia ide_cs arc4 ecb crypto_blkcipher pcmcia snd_hda_intel snd_pcm snd_timer snd_page_alloc iwl3945 rtc_cmos snd_hwdep yenta_socket rtc_core ohci1394 video rsrc_nonstatic snd iTCO_wdt ieee1394 sr_mod wmi button intel_agp output pcmcia_core firmware_class battery tg3 rtc_lib dcdbas cdrom ac iTCO_vendor_support i2c_i801 joydev soundcore i2c_core mac80211 cfg80211 sg usbhid hid ff_memless sd_mod ehci_hcd uhci_hcd usbcore edd ext3 mbcache jbd fan ide_generic ide_core ata_piix libata scsi_mod dock thermal processor [last unloaded: skeleton]
Pid: 3713, comm: insmod Tainted: G      D N 2.6.25.20-0.5-default #1

Call Trace:
 [<ffffffff8020d696>] dump_trace+0xc4/0x57d
 [<ffffffff8020db8f>] show_trace+0x40/0x57
 [<ffffffff804477bd>] dump_stack+0x72/0x7b
 [<ffffffff80237567>] warn_on_slowpath+0x58/0x80
 [<ffffffff8026f5e9>] enable_irq+0x6f/0xac
 [<ffffffff8862409f>] :skeleton:init_module+0x49/0xa6
 [<ffffffff8025ab5d>] sys_init_module+0x1b10/0x1c4d
 [<ffffffff8020bffa>] system_call_after_swapgs+0x8a/0x8f
 [<00007f555c9cc6fa>]

---[ end trace 7e5c10f539e28698 ]---
parint: Generating Interrupt now on all output pins (intr/ACK = pin 10)
parint: Interrupt generated. You should see the handler-message
I dont understand what is the reason.
Could somebody tell me what is the problem???

Best regards.
 
Old 11-24-2009, 04:40 AM   #2
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
U can enable a disabled IRQ. On the very first time the IRQ is'nt disabled, so obviously it will be an unbalanced call to the function enable_irq().
 
  


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
control is not going to interrupt handler when interrupt remyasj LinuxQuestions.org Member Intro 1 11-12-2009 12:56 AM
how to handle the timer interrupt in real mode manas_sem Programming 2 12-15-2006 07:47 AM
how to handle the timer interrupt in real mode manas_sem Programming 1 12-12-2006 12:49 AM
control is not going to interrupt handler when interrupt comes in serial driver sateeshalla Linux - Kernel 1 05-04-2006 09:43 AM

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

All times are GMT -5. The time now is 10:16 AM.

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