中断底半部及工作队列的用法

来源:互联网 发布:java多线程 pdf 编辑:程序博客网 时间:2024/05/16 18:59

使用场景:

a)如果一个任务对时间非常敏感,将其放在中断处理程序中执行。
b)如果一个任务和硬件相关,将其放在中断处理程序中执行。
c)如果一个任务要保证不被其他中断(特别是相同的中断)打断,将其放在中断处理程序中执行。
d)其他所有任务,考虑放在下半部去执行。

e)不能睡眠

 

#include <linux/of.h>

#include <linux/of_address.h>

#include <linux/of_device.h>

#include <linux/of_gpio.h>

#include <linux/of_irq.h>

#include <linux/rtpm_prio.h>

static unsigned int ft_touch_irq=0

static unsigned int hf_flag=0

staic DECLARE_WAIT_QUEUE_HEAD(waiter);

void led_tasklet_action(void);

DECLARE_TASKLET(test_tasklet,led_tasklet_action,0);

 

staic irqreturn_t eint_interrupt_handler(int irq,void *dev_id)

{

tasklet_schedule(&test_tasklet);

return IRQ_HANDLED;

}

 

static int irq_registration(void)//最好写在probe

{

struct device_node *node=NULL;

int ret=0;

u32 ints[2]={0,0};

node = of_find_matching_node(node,touch_of_match);

if(node){

of_property_read_u32_array(node,”debounce”,ints,ARRAY_SIZE(ints));

gpio_set_debounce(ints[0],ints[1]);

ft_touch_irq=irq_of_parse_and_map(node,0);

ret=request_irq(ft_touch_irq,eint_interrupt_handler,IRQF_TRIGGER_RISING,”TOUCH_PANEL-eint”,NULL);

}

else{

printk(“can not find eint device node!”);

}

return 0;

}

 

void led_tasklet_action(void)

{

......

......

......//执行代码

}

 个人原创,可直接复制在代码中使用,请勿转载