Re: keyboard driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





/* Bottom Half */
static void got_char(void *scancode)
{
printk("Scan Code %x %s.\n",
(int) *((char *) scancode) & 0x7F,
*((char *) scancode) & 0x80 ? "Released" : "Pressed");
}


try printk("<1> Scan Code ......");

/* The keyboard interrupt handler function */
void irq_handler(int irq, void *dev_id, struct pt_regs *regs)
{
       /* This variables are static because they need to be
        * * accessible (through pointers) to the bottom half routine.
        * */
       static unsigned char scancode;
       static struct tq_struct task =
       {
               routine:got_char,
               data:&scancode
       };

       unsigned char status;
       /* Read keyboard status */
       status = inb(0x64);
       scancode = inb(0x60);
       printk( "<1> in the irq_handler function\n");

       /* Scheduale bottom half to run */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,2,0)
       queue_task(&task, &tq_immediate);
#else
       queue_task_irq(&task, &tq_immediate);
#endif
       mark_bh(IMMEDIATE_BH);
}
/* Initialize the module . register the IRQ handler */
int init_module()
{
       int result = 0;

       /* Since the keyboard handler won't co.exist with another handler,
        * * such as us, we have to disable it (free its IRQ) before we do
        * * anything. Since we don't know where it is, there's no way to
        * * reinstate it later . so the computer will have to be rebooted
        * * when we're done.
        * */
       free_irq(1, NULL);

       /* Request IRQ 1, the keyboard IRQ, to go to our irq_handler. */
       /* return value 0 => success */
       result = request_irq(1,irq_handler,0,"test_keyboard_irq_handler",NULL);
       if ( result != 0 )
       {
               printk ( "<1>request_irq failed, with result=%d\n",result );
               return -1;
       }
       else
       {
               printk ( "<1>request_irq successful!\n" );
               return 0;
       }

}
/* Cleanup */
void cleanup_module()
{
       free_irq(1, NULL);
}
===============================================================






-- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/






--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux