Find the answer to your Linux question:
Results 1 to 3 of 3
Hello, I have developed a kernel module to handle a irq. Code: #include <linux/slab.h> #include <linux/sched.h> #include <linux/module.h> #include <linux/interrupt.h> #include <asm/io.h> #include <linux/time.h> #include <linux/ioport.h> #define BASEPORT 0x378 #define ...
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    22

    how to send signal from kernel space to user space

    Hello,

    I have developed a kernel module to handle a irq.

    Code:
    #include <linux/slab.h>
    #include <linux/sched.h>
    #include <linux/module.h>
    #include <linux/interrupt.h>
    #include <asm/io.h>
    #include <linux/time.h>
    #include <linux/ioport.h>
    
    #define BASEPORT 0x378
    #define LPT_INTERRUPT 7
    
    unsigned int contador;
    
    irq_handler_t handler(void)
    {
            // do stuff
    	outb_p(15, BASEPORT);
            printk(">>> PARALLEL PORT INT HANDLED %d\n", contador++);
    
    	return 0;
    }
    
    int xinit_module(void)
    {
    int ret;
    struct resource *lpt_res;
    
    	contador = 0;
    	// Request IRQ 7
            ret = request_irq(LPT_INTERRUPT, (irq_handler_t) handler, IRQF_DISABLED , "LEICIF", NULL);
    	if (ret < 0)
    	{
    		printk("Error, can not request irq 7");	
    		return (-1);
    	}
    	// Request access io region LPT
    	lpt_res = request_region(BASEPORT, 3, "BASEPORT");
    	if (lpt_res == NULL)
    	{
    		printk("Error en request_region.\n");
    		return(-1);
    	}
    
    	// ENCIENDO UN LED
    	outb_p(0x01, BASEPORT);
    
            //set port to interrupt mode; pins are output
            outb_p(0x00, BASEPORT + 2);
            outb_p(0x10, BASEPORT + 2);
    
            printk("wait for interrupt\n");
    
            // Here generate interrupt D0 signal connect to ACK signal
            outb(0, BASEPORT);
            outb(1, BASEPORT);
    
            printk("return code %d \n", ret);
            return 0;
    }
    
    void xcleanup_module(void)
    {
            disable_irq(LPT_INTERRUPT);
            free_irq(LPT_INTERRUPT, NULL);
            printk("closed\n");
    }
    
    module_init(xinit_module);
    module_exit(xcleanup_module);
    MODULE_LICENSE("GPL");
    This code works fine.
    Code:
    #insmod mydriver.ko
    wait for interrupt
    >>> PARALLEL PORT INT HANDLED 1
    return code 0
    #
    And now, the big question, Could module driver send something (signal, etc) to user space program??
    My idea is to execute a function in my user space program when interrupt handled.

    Best regards.

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Debian GNU/Linux -- You know you want it.

  3. #3
    Just Joined!
    Join Date
    May 2007
    Posts
    22
    Thanks a lot,

    it is a very easy example to understand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...