Handling Interrupt from ONOFF Pin

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Handling Interrupt from ONOFF Pin

1,396 次查看
denizdayan
Contributor II

What I am trying to achieve is: If ONOFF button is pressed shorter than 5 secs, I will handle interrupt and put the system in sleep mode. For now, I am trying to see a kernel message that says I triggered the interrupt successfully when the button is pressed. I am proceeding from another vendor's basic kernel module example for handling gpio interrupts. I have edited it a little bit:

#include <linux/module.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/gpio.h>

static int irq_number = -1;

irqreturn_t gpio_isr(int this_irq, void *dev_id)
{
    printk("Interrupt happened at gpio:%d\n", irq_number);
    return IRQ_HANDLED;
}

static void __exit gpio_interrupt_exit (void)
{
    free_irq(irq_number,0);
    return;
}

static int __init gpio_interrupt_init (void)
{
    int r;
    
    if (irq_number < 0) {
        printk("Please specify a valid gpio_number\n");
        return -1;
    }   
    r = request_irq(irq_number, gpio_isr, 0, 0, 0);
    if (r) {
        printk("failure requesting irq %i\n", irq_number);
        return r;
    }
    return 0;
}

MODULE_LICENSE("GPL");

module_param(irq_number, int, 0);

module_init(gpio_interrupt_init);
module_exit(gpio_interrupt_exit);

From what I've read from the Reference Manual, ONOFF pin has IRQ 36, so I enter 36 as my irq_number parameter. After installing module, Linux hangs. I guess I am choosing wrong number that points to a busy pin, so that causes the hang.

Is it possible to handle ONOFF pin's interrupt? If so, how can I do it? Thanks in advance.

标签 (2)
标记 (3)
0 项奖励
回复
1 回复

1,119 次查看
igorpadykov
NXP Employee
NXP Employee

Hi denizdayan

one can look on patch on

ONOFF button doesn't interrupt 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复