user2510115
user2510115

Reputation: 702

keyboard interrupt handler giving null value

I am learning Linux Kernel Module programming(Interrupt Handler) and using the tutorial (http://tldp.org/LDP/lkmpg/2.6/html/) exact module link(http://tldp.org/LDP/lkmpg/2.6/html/x1256.html).

In the tutorial I am getting error when I used

INIT_WORK(&task, got_char, &scancode);

The error was "error: macro "INIT_WORK" passed 3 arguments, but takes just 2"

So I found one solution and use the below line

INIT_WORK(&task, got_char);

It's working fine but the output I am getting is null. I am expecting the key number from the keyboard.

Any body have any idea ?

If it is not clear please let me know I will try to interpret more.

Thanks

Upvotes: 1

Views: 1260

Answers (1)

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22395

Add a structure like follows,

struct getchar_info {
    /* Other info ... */
    struct work_struct work;
    unsigned int scancode;
    /* Other info ... */
};
static struct getchar_info gci; /* Statically declare or use kmalloc() */

Change got_char() to,

static void got_char(struct work_struct *work)
{
    struct getchar_info *info = container_of(work, struct getchar_info, work);
    info->scancode = my_val;
    /* ... */

Initialize it like INIT_WORK(&gci.work, got_char);

This is a common Linux kernel paradigm or design pattern. The work queue code needs to manage this structure pointer so it is easy to provide to your got_char routine. Your driver must allocate it as part of a larger structure (it is inheritence in OO terms; it looks like composition as 'C' only supports that). The container_of is like a C++ dynamic_cast<> (with single inheritance in case any C++ gurus are looking). It lets you get the composed structure from the sub-structure.

Upvotes: 4

Related Questions