莆田中建建设发展有限公司网站,免费ui设计网站,wordpress首页文章排序,网站建站网站哪家好《【北京迅为】itop-3568开发板驱动开发指南.pdf》 学习笔记 文章目录tasklet 简介tasklet 结构体tasklet 初始化使能 tasklet失能 tasklettasklet 调度函数tasklet 取消调度函数tasklet 实验tasklet 简介 Tasklets 机制是linux中断处理机制中的软中断延迟机制。在linux中存在着… 《【北京迅为】itop-3568开发板驱动开发指南.pdf》 学习笔记 文章目录tasklet 简介tasklet 结构体tasklet 初始化使能 tasklet失能 tasklettasklet 调度函数tasklet 取消调度函数tasklet 实验tasklet 简介 Tasklets 机制是linux中断处理机制中的软中断延迟机制。在linux中存在着硬中断和软中断的概念区分。 机制流程当linux接收到硬件中断之后通过tasklet函数来设定软中断被执行的优先程度从而导致软中断处理函数被优先执行的差异性。 特点tasklet的优先级别较低而且中断处理过程中可以被打断。但被打断之后还能进行自我恢复断点续运行。 ——百度百科 在 Linux 内核中一般使用 tasklet 机制来实现中断下文tasklet 任务在同一时间只能在一个 CPU 上运行所以在多核系统上不会存在并发问题但正因如此它的执行优先级会比硬中断低。另外tasklet 任务函数不能调用任何可能会引起休眠的函数否则会导致内核异常。
tasklet 结构体
tasklet 结构体定义在内核 include/linux/interrupt.h 头文件中
struct tasklet_struct
{struct tasklet_struct *next; // 链表中的下一个 tasklet 结构体节点unsigned long state; // tasklet 状态 atomic_t count; // 原子类型计数器void(*func) (unsigned long data); // tasklet 处理函数 unsigned long data; // tasklet 处理函数的参数
}tasklet 初始化
动态初始化
void tasklet_init(struct tasklet_struct *t, void (*func)(unsigned long), unsigned long data)功能动态初始化 tasklet_struct 结构体将计数器 count 和状态 state 置 0。
参数
t tasklet_struct 结构体指针functasklet 处理函数datatasklet 处理函数的参数
静态初始化
静态初始和动态初始化功能相同实际上就是动态初始化的宏函数
DECLARE_TASKLET(name, func, data);
DECLARE_TASKLET_DISABLED(name, func, data);name 参数对应 tasklet_struct 结构体名其他参数与动态初始化相同。
DECLARE_TASKLET 和 DECLARE_TASKLET_DISABLED 的区别在于初始化时 tasklet_struct 结构体变量中 count 的值不同当 count 为 0 时表示 tasklet 使能当 count 为 1 时表示 tasklet 失能。
这里的 count 值会影响 tasklet 任务的调度只有 count 为 0 时tasklet 任务才会被调度。
使能 tasklet
tasklet 使能实际就是把 t-count 减 1。
void tasklet_enable (struct tasklet_struct *t)失能 tasklet
tasklet 失能实际就是把 t-count 加 1。
void tasklet_disable(struct tasklet_struct *t)tasklet 调度函数
tasklet_schedule() 会让 t-func() 执行前提是 t-count 为 0。
void tasklet_schedule (struct tasklet_struct *t)由于 tasklet 任务执行优先级并不高所以连续多次调用调度函数可能只会执行一次。
tasklet 取消调度函数
tasklet_kill() 会将已经调度的 tasklet 停止调度。
void tasklet_kill(struct tasklet_struct *t)如果 tasklet 任务正在被调度执行tasklet_kill() 将会等待其退出tasklet_kill() 完成前应避免再次调度。另外不能在 tasklet 处理函数里调用 tasklet_kill()。
tasklet 实验
在上一个中断实验的代码上添加中断下文处理函数即 tasklet 任务。
#include linux/module.h
#include linux/init.h
#include linux/interrupt.h
#include linux/gpio.hint irq;
struct tasklet_struct mytasklet;//tasklet 处理函数
void my_tasklet(unsigned long data)
{printk(data is %ld.\n, data);
}//静态初始化 tasklet
DECLARE_TASKLET(mytasklet, my_tasklet, 6);//中断服务函数
irqreturn_t my_interrupt(int irq, void *args)
{printk(my interrupt handler.\n); // tasklet 调度tasklet_schedule(mytasklet);return IRQ_RETVAL(IRQ_HANDLED);
}static int interrupt_irq_init(void)
{int ret 0;// 获取中断号irq gpio_to_irq(101);printk(irq is %d\n, irq);// 申请中断ret request_irq(irq, my_interrupt, IRQF_TRIGGER_RISING, inttrupt_test, NULL);if(ret 0){printk(request irq error.\n);return 0;}return 0;
}static void interrupt_irq_exit(void)
{printk(interrupt irq exit.\n);// 注销中断free_irq(irq, NULL);// 摧毁 tasklettasklet_kill(mytasklet);
}module_init(interrupt_irq_init);
module_exit(interrupt_irq_exit);MODULE_LICENSE(GPL);
MODULE_AUTHOR(xiaohui);实验结果
触碰触摸屏中断被触发先执行中断服务函数然后再执行 tasklet 处理函数。
文章转载自: http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.nynpf.cn.gov.cn.nynpf.cn http://www.morning.knpbr.cn.gov.cn.knpbr.cn http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn http://www.morning.jrhcp.cn.gov.cn.jrhcp.cn http://www.morning.kwcnf.cn.gov.cn.kwcnf.cn http://www.morning.wdjcr.cn.gov.cn.wdjcr.cn http://www.morning.yhwyh.cn.gov.cn.yhwyh.cn http://www.morning.mtjwp.cn.gov.cn.mtjwp.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn http://www.morning.mgkb.cn.gov.cn.mgkb.cn http://www.morning.qlry.cn.gov.cn.qlry.cn http://www.morning.qfqld.cn.gov.cn.qfqld.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn http://www.morning.ntgsg.cn.gov.cn.ntgsg.cn http://www.morning.tsyny.cn.gov.cn.tsyny.cn http://www.morning.lgnbr.cn.gov.cn.lgnbr.cn http://www.morning.mlfgx.cn.gov.cn.mlfgx.cn http://www.morning.lbqt.cn.gov.cn.lbqt.cn http://www.morning.xbyyd.cn.gov.cn.xbyyd.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn http://www.morning.lkmks.cn.gov.cn.lkmks.cn http://www.morning.skrcn.cn.gov.cn.skrcn.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.khdw.cn.gov.cn.khdw.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.ljjmr.cn.gov.cn.ljjmr.cn http://www.morning.jzfrl.cn.gov.cn.jzfrl.cn http://www.morning.ydzly.cn.gov.cn.ydzly.cn http://www.morning.qwyms.cn.gov.cn.qwyms.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.gydsg.cn.gov.cn.gydsg.cn http://www.morning.yrjym.cn.gov.cn.yrjym.cn http://www.morning.yqzyp.cn.gov.cn.yqzyp.cn http://www.morning.kjrp.cn.gov.cn.kjrp.cn http://www.morning.mpyry.cn.gov.cn.mpyry.cn http://www.morning.qkbwd.cn.gov.cn.qkbwd.cn http://www.morning.hmqjj.cn.gov.cn.hmqjj.cn http://www.morning.rtjhw.cn.gov.cn.rtjhw.cn http://www.morning.zcwtl.cn.gov.cn.zcwtl.cn http://www.morning.wyppp.cn.gov.cn.wyppp.cn http://www.morning.qzxb.cn.gov.cn.qzxb.cn http://www.morning.dnphd.cn.gov.cn.dnphd.cn http://www.morning.nmyrg.cn.gov.cn.nmyrg.cn http://www.morning.pbknh.cn.gov.cn.pbknh.cn http://www.morning.paoers.com.gov.cn.paoers.com http://www.morning.bkkgt.cn.gov.cn.bkkgt.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.drbd.cn.gov.cn.drbd.cn http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.rmtxp.cn.gov.cn.rmtxp.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.ptwrz.cn.gov.cn.ptwrz.cn http://www.morning.tfbpz.cn.gov.cn.tfbpz.cn http://www.morning.wknjy.cn.gov.cn.wknjy.cn http://www.morning.sgmgz.cn.gov.cn.sgmgz.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.a3e2r.com.gov.cn.a3e2r.com http://www.morning.mmclj.cn.gov.cn.mmclj.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.mngyb.cn.gov.cn.mngyb.cn http://www.morning.fycjx.cn.gov.cn.fycjx.cn http://www.morning.tzmjc.cn.gov.cn.tzmjc.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.dxqwm.cn.gov.cn.dxqwm.cn http://www.morning.fbbpj.cn.gov.cn.fbbpj.cn http://www.morning.tnmmp.cn.gov.cn.tnmmp.cn http://www.morning.kgnrh.cn.gov.cn.kgnrh.cn http://www.morning.bpmdq.cn.gov.cn.bpmdq.cn http://www.morning.mjbjq.cn.gov.cn.mjbjq.cn http://www.morning.rckmz.cn.gov.cn.rckmz.cn http://www.morning.qieistand.com.gov.cn.qieistand.com http://www.morning.rtbx.cn.gov.cn.rtbx.cn http://www.morning.lbgsh.cn.gov.cn.lbgsh.cn http://www.morning.coffeedelsol.com.gov.cn.coffeedelsol.com http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn