By liran bh | 5/16/2016 | Linux Kernel & Internals

Tasklet Example

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/interrupt.h>
#include <asm/io.h>
static void got_char(void *scancode)
{
    printk(KERN_ALERT"Scan Code %x %s.\n",
        (int) *((char *) scancode) & 0x7F,
        *((char *) scancode) & 0x80 ? "Released" : "Pressed");
}
static unsigned char scancode;
 
DECLARE_TASKLET(module_tasklet, got_char, &scancode);
 
irqreturn_t irq_handler(int irq, void *dev_id, struct pt_regs *regs)
{
    unsigned char status;
 
    /* Read keyboard status */
    status = inb(0x64);
    scancode = inb(0x60);
    tasklet_schedule(&module_tasklet);
 
    /* Scheduale bottom half to run */
    return IRQ_HANDLED;
}
int init_module()
{
    int result;
    result = request_irq(1,irq_handler,
                SA_SHIRQ,"test_keyboard_irq_handler",
                    (void *)(irq_handler));
 
    if ( result != 0 )
    {
        printk ( KERN_ALERT"error, result=%d\n",result );
        return -1;
    }
    else
    {
        printk ( KERN_ALERT"succes!\n" );
    return 0;
    }
 
}
void cleanup_module()
{
    free_irq(1, NULL);
}

{{CommentsModel.TotalCount}} Comments

Your Comment

{{CommentsModel.Message}}

Recent Stories

Top DiscoverSDK Experts

User photo
3355
Ashton Torrence
Web and Windows developer
GUI | Web and 11 more
View Profile
User photo
3220
Mendy Bennett
Experienced with Ad network & Ad servers.
Mobile | Ad Networks and 1 more
View Profile
User photo
3060
Karen Fitzgerald
7 years in Cross-Platform development.
Mobile | Cross Platform Frameworks
View Profile
Show All
X

Compare Products

Select up to three two products to compare by clicking on the compare icon () of each product.

{{compareToolModel.Error}}

Now comparing:

{{product.ProductName | createSubstring:25}} X
Compare Now